]> git.lyx.org Git - features.git/commitdiff
Exclude more conditional commands from preamble parsing:
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 12 Jan 2011 22:03:15 +0000 (22:03 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 12 Jan 2011 22:03:15 +0000 (22:03 +0000)
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

src/tex2lyx/TODO.txt
src/tex2lyx/preamble.cpp

index cb33c7e7c547974d97e773c38b03382e167e9046..b38c1734429019521511dfcb9f3298a98083c3ce 100644 (file)
@@ -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
index 1b432a2bde74e83704e6c49f86cd9c5dd7a3c6fc..8003e54195d8bb84d63fb77db96ba7d88182372d 100644 (file)
@@ -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)