From: Georg Baum Date: Wed, 12 Jan 2011 22:03:15 +0000 (+0000) Subject: Exclude more conditional commands from preamble parsing: X-Git-Tag: 2.0.0~1120 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7c83f74f265fe750688054cca419a45ae3e3db53;p=features.git Exclude more conditional commands from preamble parsing: LyX would output the parsed stuff unconditionally, so we must not translate it in LyX document settings. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37191 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index cb33c7e7c5..b38c173442 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -22,11 +22,8 @@ Format LaTeX feature LyX feature 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 diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index 1b432a2bde..8003e54195 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -149,6 +149,15 @@ const char * const known_coded_paper_margins[] = { "leftmargin", "topmargin", "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"; @@ -604,6 +613,22 @@ void handle_package(Parser &p, string const & name, string const & opts, } +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*/) { @@ -1068,14 +1093,27 @@ void parse_preamble(Parser & p, ostream & os, } } - 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)