X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftex2lyx%2FPreamble.cpp;h=8b327b100d0a04622e872e0578b5df52ead4b5bd;hb=62af7ee772f16f154225d2d0b65d77f4376b6001;hp=21d081c5c6df0000a10e9750de2e2fb9e944ed7d;hpb=36399e88d3c437f8dfade8bcbb24d37c4ccff958;p=lyx.git diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 21d081c5c6..8b327b100d 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -158,15 +158,12 @@ const char * const known_typewriter_font_packages[] = { "beramono", "cmtl", "cmt const char * const known_math_font_packages[] = { "eulervm", "newtxmath", 0}; -const char * const known_paper_sizes[] = { "a0paper", "b0paper", "c0paper", +const char * const known_latex_paper_sizes[] = { "a0paper", "b0paper", "c0paper", "a1paper", "b1paper", "c1paper", "a2paper", "b2paper", "c2paper", "a3paper", "b3paper", "c3paper", "a4paper", "b4paper", "c4paper", "a5paper", "b5paper", "c5paper", "a6paper", "b6paper", "c6paper", "executivepaper", "legalpaper", "letterpaper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j", "b6j", 0}; -const char * const known_class_paper_sizes[] = { "a4paper", "a5paper", -"executivepaper", "legalpaper", "letterpaper", 0}; - const char * const known_paper_margins[] = { "lmargin", "tmargin", "rmargin", "bmargin", "headheight", "headsep", "footskip", "columnsep", 0}; @@ -414,9 +411,9 @@ void Preamble::suppressDate(bool suppress) } -void Preamble::registerAuthor(std::string const & name) +void Preamble::registerAuthor(std::string const & name, string const & initials) { - Author author(from_utf8(name), empty_docstring()); + Author author(from_utf8(name), empty_docstring(), from_utf8(initials)); author.setUsed(true); authors_.record(author); h_tracking_changes = "true"; @@ -426,7 +423,7 @@ void Preamble::registerAuthor(std::string const & name) Author const & Preamble::getAuthor(std::string const & name) const { - Author author(from_utf8(name), empty_docstring()); + Author author(from_utf8(name), empty_docstring(), empty_docstring()); for (AuthorList::Authors::const_iterator it = authors_.begin(); it != authors_.end(); ++it) if (*it == author) @@ -558,6 +555,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false), //h_notefontcolor; //h_options; h_output_changes = "false"; + h_change_bars = "false"; h_output_sync = "0"; //h_output_sync_macro h_papercolumns = "1"; @@ -709,13 +707,18 @@ void Preamble::handle_geometry(vector & options) options.erase(it); } // paper size - // keyval version: "paper=letter" + // keyval version: "paper=letter" or "paper=letterpaper" string paper = process_keyval_opt(options, "paper"); if (!paper.empty()) - h_papersize = paper + "paper"; + if (suffixIs(paper, "paper")) + paper = subst(paper, "paper", ""); // alternative version: "letterpaper" - handle_opt(options, known_paper_sizes, h_papersize); - delete_opt(options, known_paper_sizes); + handle_opt(options, known_latex_paper_sizes, paper); + if (suffixIs(paper, "paper")) + paper = subst(paper, "paper", ""); + delete_opt(options, known_latex_paper_sizes); + if (!paper.empty()) + h_papersize = paper; // page margins char const * const * margin = known_paper_margins; for (; *margin; ++margin) { @@ -1173,7 +1176,7 @@ void Preamble::handle_package(Parser &p, string const & name, if (is_known(name, known_sans_font_packages)) { h_font_sans[0] = name; if (contains(opts, "scale")) { - vector::const_iterator it = allopts.begin(); + vector::iterator it = allopts.begin(); for (; it != allopts.end() ; ++it) { string const opt = *it; if (prefixIs(opt, "scaled=") || prefixIs(opt, "scale=")) { @@ -1381,7 +1384,7 @@ void Preamble::handle_package(Parser &p, string const & name, if (is_known(name, known_typewriter_font_packages)) { h_font_typewriter[0] = name; if (contains(opts, "scale")) { - vector::const_iterator it = allopts.begin(); + vector::iterator it = allopts.begin(); for (; it != allopts.end() ; ++it) { string const opt = *it; if (prefixIs(opt, "scaled=") || prefixIs(opt, "scale=")) { @@ -1780,6 +1783,9 @@ void Preamble::handle_package(Parser &p, string const & name, } } + else if (name == "changebar") + h_output_changes = "true"; + else if (!in_lyx_preamble) { if (options.empty()) h_preamble << "\\usepackage{" << name << '}'; @@ -2020,6 +2026,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled os << "\\listings_params " << h_listings_params << "\n"; os << "\\tracking_changes " << h_tracking_changes << "\n" << "\\output_changes " << h_output_changes << "\n" + << "\\change_bars " << h_change_bars << "\n" << "\\html_math_output " << h_html_math_output << "\n" << "\\html_css_as_file " << h_html_css_as_file << "\n" << "\\html_be_strict " << h_html_be_strict << "\n" @@ -2543,12 +2550,41 @@ void Preamble::parse(Parser & p, string const & forceclass, if (t.cs() == "documentclass") { vector::iterator it; vector opts = split_options(p.getArg('[', ']')); + // FIXME This does not work for classes that have a + // different name in LyX than in LaTeX + h_textclass = p.getArg('{', '}'); + p.skip_spaces(); + // Force textclass if the user wanted it + if (!forceclass.empty()) + h_textclass = forceclass; + tc.setName(h_textclass); + if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) { + cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl; + exit(EXIT_FAILURE); + } + + // Font sizes. + // Try those who are (most likely) known to all packages first handle_opt(opts, known_fontsizes, h_paperfontsize); delete_opt(opts, known_fontsizes); // delete "pt" at the end string::size_type i = h_paperfontsize.find("pt"); if (i != string::npos) h_paperfontsize.erase(i); + // Now those known specifically to the class + string fsize; + vector class_fsizes = getVectorFromString(tc.opt_fontsize(), "|"); + string const fsize_format = tc.fontsizeformat(); + for (auto const fsize : class_fsizes) { + string latexsize = subst(fsize_format, "$$s", fsize); + vector::iterator it = find(opts.begin(), opts.end(), latexsize); + if (it != opts.end()) { + h_paperfontsize = fsize; + opts.erase(it); + break; + } + } + // The documentclass options are always parsed before the options // of the babel call so that a language cannot overwrite the babel // options. @@ -2601,16 +2637,33 @@ void Preamble::parse(Parser & p, string const & forceclass, opts.erase(it); } // paper sizes - // some size options are known to any document classes, other sizes + // some size options are known by the document class, other sizes // are handled by the \geometry command of the geometry package - handle_opt(opts, known_class_paper_sizes, h_papersize); - delete_opt(opts, known_class_paper_sizes); + string paper; + vector class_psizes = getVectorFromString(tc.opt_pagesize(), "|"); + string const psize_format = tc.pagesizeformat(); + for (auto const psize : class_psizes) { + string latexsize = subst(psize_format, "$$s", psize); + vector::iterator it = find(opts.begin(), opts.end(), latexsize); + if (it != opts.end()) { + h_papersize = psize; + opts.erase(it); + break; + } + if (psize_format == "$$spaper") + continue; + // Also try with the default format since this is understood by + // most classes + latexsize = psize + "paper"; + it = find(opts.begin(), opts.end(), latexsize); + if (it != opts.end()) { + h_papersize = psize; + opts.erase(it); + break; + } + } // the remaining options h_options = join(opts, ","); - // FIXME This does not work for classes that have a - // different name in LyX than in LaTeX - h_textclass = p.getArg('{', '}'); - p.skip_spaces(); continue; } @@ -2935,14 +2988,6 @@ void Preamble::parse(Parser & p, string const & forceclass, // remove the whitespace p.skip_spaces(); - // Force textclass if the user wanted it - if (!forceclass.empty()) - h_textclass = forceclass; - tc.setName(h_textclass); - if (!LayoutFileList::get().haveClass(h_textclass) || !tc.load()) { - cerr << "Error: Could not read layout file for textclass \"" << h_textclass << "\"." << endl; - exit(EXIT_FAILURE); - } if (h_papersides.empty()) { ostringstream ss; ss << tc.sides();