231 sidewaysfigure/sidewaystable InsetFloat
232 bibtopic InsetBibTeX
246 framed.sty InsetBox
-247 lmodern.sty, charter.sty, utopia.sty font settings (header)
- ccfonts.sty, chancery.sty,
- beraserif.sty, berasans.sty,
- courier.sty, luximono.sty,
- beramono.sty, mathptmx.sty
+247 utopia.sty, ccfonts.sty, font settings (header)
+ chancery.sty, beraserif.sty
248 booktabs.sty InsetTabular
254 esint.sty \use_esint
266 armenian \language, \lang
"rightmargin", "bottommargin", "headheight", "headsep", "footskip",
"columnsep", 0};
+/// commands that can start an \if...\else...\endif sequence
+const char * const known_if_commands[] = {"if", "ifarydshln", "ifbraket",
+"ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf",
+"ifsidecap", "ifupgreek", 0};
+
+/// conditional commands with three arguments like \@ifundefined{}{}{}
+const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
+0};
+
// default settings
ostringstream h_preamble;
string h_textclass = "article";
}
+void handle_if(Parser & p, bool in_lyx_preamble)
+{
+ while (p.good()) {
+ Token t = p.get_token();
+ if (t.cat() == catEscape &&
+ is_known(t.cs(), known_if_commands))
+ handle_if(p, in_lyx_preamble);
+ else {
+ if (!in_lyx_preamble)
+ h_preamble << t.asInput();
+ if (t.cat() == catEscape && t.cs() == "fi")
+ return;
+ }
+ }
+}
+
void end_preamble(ostream & os, TextClass const & /*textclass*/)
{
}
}
- else if (t.cs() == "@ifundefined") {
+ else if (is_known(t.cs(), known_if_3arg_commands)) {
// prevent misparsing of \usepackage if it is used
// as an argument (see e.g. our own output of
// \@ifundefined above)
- h_preamble << t.asInput();
- h_preamble << '{' << p.verbatim_item() << '}';
- h_preamble << '{' << p.verbatim_item() << '}';
- h_preamble << '{' << p.verbatim_item() << '}';
+ string const arg1 = p.verbatim_item();
+ string const arg2 = p.verbatim_item();
+ string const arg3 = p.verbatim_item();
+ if (!in_lyx_preamble) {
+ h_preamble << t.asInput()
+ << '{' << arg1 << '}'
+ << '{' << arg2 << '}'
+ << '{' << arg3 << '}';
+ }
+ }
+
+ else if (is_known(t.cs(), known_if_commands)) {
+ // must not parse anything in conditional code, since
+ // LyX would output the parsed contents unconditionally
+ if (!in_lyx_preamble)
+ h_preamble << t.asInput();
+ handle_if(p, in_lyx_preamble);
}
else if (!t.cs().empty() && !in_lyx_preamble)