X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftex2lyx%2Fpreamble.cpp;h=4dd8d7f28addd729cf2f2bc08a0adbab126f4edd;hb=c9a726bd43ed568a6fb3e9e4ce1d759f16790d3a;hp=28f44ee84449c3fdc812be2413a1b7fa2ed34613;hpb=f1cba8ff64b369792fd49f5ddf90e8126ab476ac;p=lyx.git diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index 28f44ee844..4dd8d7f28a 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -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"; @@ -248,7 +249,7 @@ string const scale_as_percentage(string const & scale) } -void handle_package(string const & name, string const & opts, +void handle_package(Parser &p, string const & name, string const & opts, bool in_lyx_preamble) { vector options = split_options(opts); @@ -256,20 +257,28 @@ void handle_package(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(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(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 = "1"; + else if (name == "amsmath" || name == "amssymb") { + h_use_amsmath = "2"; + p.skip_spaces(); + } + + 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,14 +343,16 @@ void handle_package(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 option - // therefore check for the "," character - // also only set when there is not more then one babel language option + // only set when there is not more than one inputenc + // option therefore check for the "," character also + // only set when there is not more then one babel + // language option if (opts.find(",") == string::npos && one_language == true) { if (opts == "ascii") //change ascii to auto to be in the unicode range, see @@ -337,28 +361,42 @@ void handle_package(string const & name, string const & opts, else if (!opts.empty()) h_inputencoding = 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 == "url") + p.skip_spaces(); // ignore this - else if (name == "color") + 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)) { @@ -375,7 +413,9 @@ void handle_package(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::iterator it = @@ -389,15 +429,20 @@ void handle_package(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(); } } @@ -413,7 +458,7 @@ void handle_package(string const & name, string const & opts, void end_preamble(ostream & os, TextClass const & /*textclass*/) { os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n" - << "\\lyxformat 247\n" + << "\\lyxformat 256\n" << "\\begin_document\n" << "\\begin_header\n" << "\\textclass " << h_textclass << "\n"; @@ -437,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" @@ -466,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()) { @@ -524,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(); @@ -663,21 +710,19 @@ void parse_preamble(Parser & p, ostream & os, else if (t.cs() == "usepackage") { string const options = p.getArg('[', ']'); string const name = p.getArg('{', '}'); - if (options.empty() && name.find(',')) { - vector vecnames; - split(name, vecnames, ','); - vector::const_iterator it = vecnames.begin(); - vector::const_iterator end = vecnames.end(); - for (; it != end; ++it) - handle_package(trim(*it), string(), - in_lyx_preamble); - } else { - handle_package(name, options, in_lyx_preamble); - } + vector vecnames; + split(name, vecnames, ','); + vector::const_iterator it = vecnames.begin(); + vector::const_iterator end = vecnames.end(); + for (; it != end; ++it) + handle_package(p, trim(*it), options, + in_lyx_preamble); } else if (t.cs() == "inputencoding") { - h_inputencoding = p.getArg('{','}'); + string const encoding = p.getArg('{','}'); + h_inputencoding = encoding; + p.setEncoding(encoding); } else if (t.cs() == "newenvironment") {