namespace {
-void begin_layout(ostream & os, Layout const * const & layout, TeXFont const & font,
- TeXFont const & normalfont)
-{
- os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
- // FIXME: This is not enough for things like
- // \\Huge par1 \\par par2
- output_font_change(os, normalfont, font);
-}
-
-
void end_layout(ostream & os)
{
os << "\n\\end_layout\n";
Context::~Context()
{
- if (!extra_stuff.empty())
- cerr << "Bug: Ignoring extra stuff '" << extra_stuff
- << '\'' << endl;
+ if (!par_extra_stuff.empty())
+ cerr << "Bug: Ignoring par-level extra stuff '"
+ << par_extra_stuff << '\'' << endl;
+}
+
+
+void Context::begin_layout(ostream & os, Layout const * const & l)
+{
+ os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
+ if (!extra_stuff.empty()) {
+ os << extra_stuff;
+ }
+ if (!par_extra_stuff.empty()) {
+ os << par_extra_stuff;
+ par_extra_stuff.erase();
+ }
+ // FIXME: This is not enough for things like
+ // \\Huge par1 \\par par2
+ output_font_change(os, normalfont, font);
}
end_deeper(os);
deeper_paragraph = false;
}
- begin_layout(os, layout, font, normalfont);
+ begin_layout(os, layout);
has_item = false;
} else {
// a standard paragraph in an
// that this may require a begin_deeper.
if (!deeper_paragraph)
begin_deeper(os);
- begin_layout(os, &textclass.defaultLayout(),
- font, normalfont);
+ begin_layout(os, &textclass.defaultLayout());
deeper_paragraph = true;
}
} else {
// No list-like environment
- begin_layout(os, layout, font, normalfont);
+ begin_layout(os, layout);
}
need_layout = false;
need_end_layout = true;
- if (!extra_stuff.empty()) {
- os << extra_stuff;
- extra_stuff.erase();
- }
os << "\n";
empty = false;
}
}
+void Context::add_par_extra_stuff(string const & stuff)
+{
+ if (!contains(par_extra_stuff, stuff))
+ par_extra_stuff += stuff;
+}
+
+
void Context::dump(ostream & os, string const & desc) const
{
os << "\n" << desc <<" [";
os << "new_layout_allowed ";
if (!extra_stuff.empty())
os << "extrastuff=[" << extra_stuff << "] ";
+ if (!par_extra_stuff.empty())
+ os << "parextrastuff=[" << par_extra_stuff << "] ";
os << "textclass=" << textclass.name()
<< " layout=" << to_utf8(layout->name())
<< " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
/// Add extra stuff if not already there
void add_extra_stuff(std::string const &);
+ /*!
+ * Add paragraph-level extra stuff if not already there. This
+ * will be reset at the next check_layout()
+ */
+ void add_par_extra_stuff(std::string const &);
+
/// Do we need to output some \\begin_layout command before the
/// next characters?
bool need_layout;
/// Do we need to output some \\end_layout command
bool need_end_layout;
- /// We may need to add something after this \\begin_layout command
+ /// We may need to add something after each \\begin_layout command
std::string extra_stuff;
+ /// We may need to add something after this \\begin_layout command
+ std::string par_extra_stuff;
/// If there has been an \\begin_deeper, we'll need a matching
/// \\end_deeper
bool need_end_deeper;
TeXFont font;
/// font attributes of normal text
static TeXFont normalfont;
+
+private:
+ void begin_layout(std::ostream & os, Layout const * const & l);
};
Context & context)
{
Context newcontext(context);
- // Don't inherit the extra stuff
- newcontext.extra_stuff.clear();
+ // Don't inherit the paragraph-level extra stuff
+ newcontext.par_extra_stuff.clear();
parse_text(p, os, flags, outer, newcontext);
// Make sure that we don't create invalid .lyx files
context.need_layout = newcontext.need_layout;
newcontext.need_end_layout = false;
newcontext.new_layout_allowed = false;
// Avoid warning by Context::~Context()
- newcontext.extra_stuff.clear();
+ newcontext.par_extra_stuff.clear();
ostringstream os;
parse_text_snippet(p, os, flags, outer, newcontext);
return os.str();
parent_context.check_end_layout(os);
switch (context.layout->latextype) {
case LATEX_LIST_ENVIRONMENT:
- context.extra_stuff = "\\labelwidthstring "
- + p.verbatim_item() + '\n';
+ context.add_par_extra_stuff("\\labelwidthstring "
+ + p.verbatim_item() + '\n');
p.skip_spaces();
break;
case LATEX_BIB_ENVIRONMENT:
else if (t.cs() == "noindent") {
p.skip_spaces();
- context.add_extra_stuff("\\noindent\n");
+ context.add_par_extra_stuff("\\noindent\n");
}
else if (t.cs() == "appendix") {
- context.add_extra_stuff("\\start_of_appendix\n");
+ context.add_par_extra_stuff("\\start_of_appendix\n");
// We need to start a new paragraph. Otherwise the
// appendix in 'bla\appendix\chapter{' would start
// too late.