]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/preamble.cpp
tex2lyx/preamble.cpp: support for fileformat 256
[lyx.git] / src / tex2lyx / preamble.cpp
index a9b879a3200ef7341d68b81352b07f152e951681..4dd8d7f28addd729cf2f2bc08a0adbab126f4edd 100644 (file)
@@ -120,7 +120,8 @@ string h_paperfontsize           = "default";
 string h_spacing                 = "single";
 string h_papersize               = "default";
 string h_use_geometry            = "false";
-string h_use_amsmath             = "0";
+string h_use_amsmath             = "1";
+string h_use_esint               = "1";
 string h_cite_engine             = "basic";
 string h_use_bibtopic            = "false";
 string h_paperorientation        = "portrait";
@@ -256,20 +257,28 @@ void handle_package(Parser &p, string const & name, string const & opts,
        string scale;
 
        // roman fonts
-       if (is_known(name, known_roman_fonts))
+       if (is_known(name, known_roman_fonts)) {
                h_font_roman = name;
+               p.skip_spaces();
+       }
 
        if (name == "fourier") {
                h_font_roman = "utopia";
                // when font uses real small capitals
                if (opts == "expert")
                        h_font_sc = "true";
+               p.skip_spaces();
        }
-       if (name == "mathpazo")
+
+       if (name == "mathpazo") {
                h_font_roman = "palatino";
+               p.skip_spaces();
+       }
 
-       if (name == "mathptmx")
+       if (name == "mathptmx") {
                h_font_roman = "times";
+               p.skip_spaces();
+       }
 
        // sansserif fonts
        if (is_known(name, known_sans_fonts)) {
@@ -278,7 +287,9 @@ void handle_package(Parser &p, string const & name, string const & opts,
                        scale = opts;
                        h_font_sf_scale = scale_as_percentage(scale);
                }
+               p.skip_spaces();
        }
+
        // typewriter fonts
        if (is_known(name, known_typewriter_fonts)) {
                h_font_typewriter = name;
@@ -286,13 +297,24 @@ void handle_package(Parser &p, string const & name, string const & opts,
                        scale = opts;
                        h_font_tt_scale = scale_as_percentage(scale);
                }
+               p.skip_spaces();
        }
+
        // font uses old-style figure
-       if (name == "eco")
+       if (name == "eco") {
                h_font_osf = "true";
+               p.skip_spaces();
+       }
+
+       else if (name == "amsmath" || name == "amssymb") {
+               h_use_amsmath = "2";
+               p.skip_spaces();
+       }
 
-       else if (name == "amsmath" || name == "amssymb")
-               h_use_amsmath = "1";
+       else if (name == "esint") {
+               h_use_esint = "2";
+               p.skip_spaces();
+       }
 
        else if (name == "babel" && !opts.empty()) {
                // check if more than one option was used - used later for inputenc
@@ -321,9 +343,10 @@ void handle_package(Parser &p, string const & name, string const & opts,
                                h_language = "ukrainian";
                        h_quotes_language = h_language;
                }
+               p.skip_spaces();
        }
        else if (name == "fontenc")
-               ; // ignore this
+               p.skip_spaces(); // ignore this
 
        else if (name == "inputenc") {
                // only set when there is not more than one inputenc
@@ -341,27 +364,39 @@ void handle_package(Parser &p, string const & name, string const & opts,
                if (!options.empty())
                        p.setEncoding(options.back());
                options.clear();
+               p.skip_spaces();
        }
 
        else if (name == "makeidx")
-               ; // ignore this
+               p.skip_spaces(); // ignore this
+
+       else if (name == "prettyref")
+               p.skip_spaces(); // ignore this
+
+       else if (name == "varioref")
+               p.skip_spaces(); // ignore this
 
        else if (name == "verbatim")
-               ; // ignore this
+               p.skip_spaces(); // ignore this
 
-       else if (name == "color")
+       else if (name == "url")
+               p.skip_spaces(); // ignore this
+
+       else if (name == "color") {
                // with the following command this package is only loaded when needed for
                // undefined colors, since we only support the predefined colors
                h_preamble << "\\@ifundefined{definecolor}\n {\\usepackage{color}}{}\n";
+               p.skip_spaces();
+       }
 
        else if (name == "graphicx")
-               ; // ignore this
+               p.skip_spaces(); // ignore this
 
        else if (name == "setspace")
-               ; // ignore this
+               p.skip_spaces(); // ignore this
 
        else if (name == "geometry")
-               ; // Ignore this, the geometry settings are made by the \geometry
+               p.skip_spaces(); // Ignore this, the geometry settings are made by the \geometry
                  // command. This command is handled below.
 
        else if (is_known(name, known_languages)) {
@@ -378,7 +413,9 @@ void handle_package(Parser &p, string const & name, string const & opts,
                else
                        h_language = name;
                h_quotes_language = h_language;
+               p.skip_spaces();
        }
+
        else if (name == "natbib") {
                h_cite_engine = "natbib_authoryear";
                vector<string>::iterator it =
@@ -392,15 +429,20 @@ void handle_package(Parser &p, string const & name, string const & opts,
                                options.erase(it);
                        }
                }
+               p.skip_spaces();
        }
-       else if (name == "jurabib")
+
+       else if (name == "jurabib") {
                h_cite_engine = "jurabib";
+               p.skip_spaces();
+       }
+
        else if (!in_lyx_preamble) {
                if (options.empty())
-                       h_preamble << "\\usepackage{" << name << "}\n";
+                       h_preamble << "\\usepackage{" << name << "}";
                else {
                        h_preamble << "\\usepackage[" << opts << "]{" 
-                                  << name << "}\n";
+                                  << name << "}";
                        options.clear();
                }
        }
@@ -416,7 +458,7 @@ void handle_package(Parser &p, string const & name, string const & opts,
 void end_preamble(ostream & os, TextClass const & /*textclass*/)
 {
        os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
-          << "\\lyxformat 249\n"
+          << "\\lyxformat 256\n"
           << "\\begin_document\n"
           << "\\begin_header\n"
           << "\\textclass " << h_textclass << "\n";
@@ -440,6 +482,7 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/)
           << "\\papersize " << h_papersize << "\n"
           << "\\use_geometry " << h_use_geometry << "\n"
           << "\\use_amsmath " << h_use_amsmath << "\n"
+          << "\\use_esint " << h_use_esint << "\n"
           << "\\cite_engine " << h_cite_engine << "\n"
           << "\\use_bibtopic " << h_use_bibtopic << "\n"
           << "\\paperorientation " << h_paperorientation << "\n"
@@ -469,7 +512,7 @@ void parse_preamble(Parser & p, ostream & os,
        special_columns['D'] = 3;
        bool is_full_document = false;
        bool is_lyx_file = false;
-       bool in_lyx_preamble = true;
+       bool in_lyx_preamble = false;
 
        // determine whether this is a full document or a fragment for inclusion
        while (p.good()) {
@@ -527,10 +570,11 @@ void parse_preamble(Parser & p, ostream & os,
                        }
 
                        smatch sub;
-                       if (regex_search(comment, sub, islyxfile))
+                       if (regex_search(comment, sub, islyxfile)) {
                                is_lyx_file = true;
-                       else if (is_lyx_file
-                                && regex_search(comment, sub, usercommands))
+                               in_lyx_preamble = true;
+                       } else if (is_lyx_file
+                                  && regex_search(comment, sub, usercommands))
                                in_lyx_preamble = false;
                        else if (!in_lyx_preamble)
                                h_preamble << t.asInput();