3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
18 #include "LayoutFile.h"
21 #include "TextClass.h"
23 #include "support/convert.h"
24 #include "support/FileName.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
28 #include "support/regex.h"
38 using namespace lyx::support;
43 // special columntypes
44 extern map<char, int> special_columns;
46 map<string, vector<string> > used_packages;
48 // needed to handle encodings with babel
49 bool one_language = true;
53 //add this to known_languages when updating to lyxformat 266:
55 //add these to known_languages when updating to lyxformat 268:
56 //"chinese-simplified", "chinese-traditional", "japanese", "korean"
57 // Both changes require first that support for non-babel languages (CJK,
59 const char * const known_languages[] = { "afrikaans", "american", "arabic",
60 "arabtex", "austrian", "bahasa", "basque", "belarusian", "brazil", "brazilian",
61 "breton", "british", "bulgarian", "canadian", "canadien", "catalan",
62 "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian",
63 "finnish", "francais", "french", "frenchb", "frenchle", "frenchpro",
64 "galician", "german", "germanb", "greek", "hebrew", "icelandic", "irish",
65 "italian", "kazakh", "latvian", "lithuanian", "lsorbian", "magyar",
66 "naustrian", "ngerman", "ngermanb", "norsk", "nynorsk", "polish", "portuges",
67 "portuguese", "romanian", "russian", "russianb", "scottish", "serbian", "slovak",
68 "slovene", "spanish", "swedish", "thai", "turkish", "ukraineb", "ukrainian",
69 "usorbian", "welsh", 0};
71 //add this when updating to lyxformat 305:
72 //bahasai, indonesian, and indon = equal to bahasa
73 //malay and meyalu = equal to bahasam
74 const char * const known_brazilian_languages[] = {"brazil", "brazilian", 0};
75 const char * const known_french_languages[] = {"french", "frenchb", "francais",
76 "frenchle", "frenchpro", 0};
77 const char * const known_german_languages[] = {"german", "germanb", 0};
78 const char * const known_ngerman_languages[] = {"ngerman", "ngermanb", 0};
79 const char * const known_portuguese_languages[] = {"portuges", "portuguese", 0};
80 const char * const known_russian_languages[] = {"russian", "russianb", 0};
81 const char * const known_ukrainian_languages[] = {"ukrainian", "ukraineb", 0};
83 //add these to known_english_quotes_languages when updating to lyxformat 268:
84 //"chinese-simplified", "korean"
85 // This requires first that support for non-babel languages (CJK) is added.
86 const char * const known_english_quotes_languages[] = {"american", "canadian",
87 "english", "esperanto", "hebrew", "irish", "scottish", "thai", 0};
89 //add this to known_french_quotes_languages when updating to lyxformat 327:
91 const char * const known_french_quotes_languages[] = {"albanian", "arabic",
92 "basque", "canadien", "catalan", "galician", "greek", "italian", "norsk",
93 "nynorsk", "spanish", "turkish", 0};
95 const char * const known_german_quotes_languages[] = {"austrian", "bulgarian",
96 "czech", "icelandic", "lithuanian", "lsorbian", "naustrian", "serbian",
97 "serbian-latin", "slovak", "slovene", "usorbian", 0};
99 const char * const known_polish_quotes_languages[] = {"afrikaans", "croatian",
100 "dutch", "estonian", "magyar", "polish", "romanian", 0};
102 const char * const known_swedish_quotes_languages[] = {"bahasa", "finnish",
105 char const * const known_fontsizes[] = { "10pt", "11pt", "12pt", 0 };
107 const char * const known_roman_fonts[] = { "ae", "bookman", "charter",
108 "cmr", "fourier", "lmodern", "mathpazo", "mathptmx", "newcent", 0};
110 const char * const known_sans_fonts[] = { "avant", "berasans", "cmbr", "cmss",
111 "helvet", "lmss", 0};
113 const char * const known_typewriter_fonts[] = { "beramono", "cmtl", "cmtt",
114 "courier", "lmtt", "luximono", "fourier", "lmodern", "mathpazo", "mathptmx",
117 const char * const known_paper_sizes[] = { "a3paper", "b3paper", "a4paper",
118 "b4paper", "a5paper", "b5paper", "executivepaper", "legalpaper",
121 const char * const known_class_paper_sizes[] = { "a4paper", "a5paper",
122 "executivepaper", "legalpaper", "letterpaper", 0};
124 const char * const known_paper_margins[] = { "lmargin", "tmargin", "rmargin",
125 "bmargin", "headheight", "headsep", "footskip", "columnsep", 0};
127 const char * const known_coded_paper_margins[] = { "leftmargin", "topmargin",
128 "rightmargin", "bottommargin", "headheight", "headsep", "footskip",
132 ostringstream h_preamble;
133 string h_textclass = "article";
134 string h_options = string();
135 string h_language = "english";
136 string h_inputencoding = "auto";
137 string h_font_roman = "default";
138 string h_font_sans = "default";
139 string h_font_typewriter = "default";
140 string h_font_default_family = "default";
141 string h_font_sc = "false";
142 string h_font_osf = "false";
143 string h_font_sf_scale = "100";
144 string h_font_tt_scale = "100";
145 string h_graphics = "default";
146 string h_paperfontsize = "default";
147 string h_spacing = "single";
148 string h_papersize = "default";
149 string h_use_geometry = "false";
150 string h_use_amsmath = "1";
151 string h_use_esint = "1";
152 string h_cite_engine = "basic";
153 string h_use_bibtopic = "false";
154 string h_paperorientation = "portrait";
155 string h_secnumdepth = "3";
156 string h_tocdepth = "3";
157 string h_paragraph_separation = "indent";
158 string h_defskip = "medskip";
159 string h_quotes_language = "english";
160 string h_papercolumns = "1";
161 string h_papersides = string();
162 string h_paperpagestyle = "default";
163 string h_tracking_changes = "false";
164 string h_output_changes = "false";
165 string h_margins = "";
168 /// translates a babel language name to a LyX language name
169 string babel2lyx(string language)
171 if (language == "arabtex")
172 return "arabic_arabtex";
173 if (language == "arabic")
174 return "arabic_arabi";
179 // returns true if at least one of the options in what has been found
180 bool handle_opt(vector<string> & opts, char const * const * what, string & target)
186 // the last language option is the document language (for babel and LyX)
187 // the last size option is the document font size
188 vector<string>::iterator it;
189 vector<string>::iterator position = opts.begin();
190 for (; *what; ++what) {
191 it = find(opts.begin(), opts.end(), *what);
192 if (it != opts.end()) {
193 if (it >= position) {
204 void delete_opt(vector<string> & opts, char const * const * what)
209 // remove found options from the list
210 // do this after handle_opt to avoid potential memory leaks
211 vector<string>::iterator it;
212 for (; *what; ++what) {
213 it = find(opts.begin(), opts.end(), *what);
214 if (it != opts.end())
221 * Split a package options string (keyval format) into a vector.
223 * authorformat=smallcaps,
225 * titleformat=colonsep,
226 * bibformat={tabular,ibidem,numbered}
228 vector<string> split_options(string const & input)
230 vector<string> options;
234 Token const & t = p.get_token();
235 if (t.asInput() == ",") {
236 options.push_back(trim(option));
238 } else if (t.asInput() == "=") {
241 if (p.next_token().asInput() == "{")
242 option += '{' + p.getArg('{', '}') + '}';
243 } else if (t.cat() != catSpace)
244 option += t.asInput();
248 options.push_back(trim(option));
255 * Add package \p name with options \p options to used_packages.
256 * Remove options from \p options that we don't want to output.
258 void add_package(string const & name, vector<string> & options)
260 // every package inherits the global options
261 if (used_packages.find(name) == used_packages.end())
262 used_packages[name] = split_options(h_options);
264 vector<string> & v = used_packages[name];
265 v.insert(v.end(), options.begin(), options.end());
266 if (name == "jurabib") {
267 // Don't output the order argument (see the cite command
268 // handling code in text.cpp).
269 vector<string>::iterator end =
270 remove(options.begin(), options.end(), "natbiborder");
271 end = remove(options.begin(), end, "jurabiborder");
272 options.erase(end, options.end());
277 // Given is a string like "scaled=0.9", return 0.9 * 100
278 string const scale_as_percentage(string const & scale)
280 string::size_type pos = scale.find('=');
281 if (pos != string::npos) {
282 string value = scale.substr(pos + 1);
284 return convert<string>(100 * convert<double>(value));
286 // If the input string didn't match our expectations.
287 // return the default value "100"
292 void handle_package(Parser &p, string const & name, string const & opts,
293 bool in_lyx_preamble)
295 vector<string> options = split_options(opts);
296 add_package(name, options);
300 if (is_known(name, known_roman_fonts)) {
305 if (name == "fourier") {
306 h_font_roman = "utopia";
307 // when font uses real small capitals
308 if (opts == "expert")
312 if (name == "mathpazo")
313 h_font_roman = "palatino";
315 if (name == "mathptmx")
316 h_font_roman = "times";
319 if (is_known(name, known_sans_fonts)) {
323 h_font_sf_scale = scale_as_percentage(scale);
328 if (is_known(name, known_typewriter_fonts)) {
329 h_font_typewriter = name;
332 h_font_tt_scale = scale_as_percentage(scale);
336 // font uses old-style figure
340 else if (name == "amsmath" || name == "amssymb")
343 else if (name == "esint")
346 else if (name == "babel" && !opts.empty()) {
347 // check if more than one option was used - used later for inputenc
348 // in case inputenc is parsed before babel, set the encoding to auto
349 if (options.begin() != options.end() - 1) {
350 one_language = false;
351 h_inputencoding = "auto";
353 // babel takes the last language of the option of its \usepackage
354 // call as document language. If there is no such language option, the
355 // last language in the documentclass options is used.
356 handle_opt(options, known_languages, h_language);
357 delete_opt(options, known_languages);
360 else if (name == "fontenc")
363 else if (name == "inputenc") {
364 // h_inputencoding is only set when there is not more than one
365 // inputenc option because otherwise h_inputencoding must be
366 // set to "auto" (the default encoding of the document language)
367 // Therefore check for the "," character.
368 // It is also only set when there is not more then one babel
369 // language option but this is handled in the routine for babel.
370 if (opts.find(",") == string::npos && one_language == true)
371 h_inputencoding = opts;
372 if (!options.empty())
373 p.setEncoding(options.back());
377 else if (name == "makeidx")
380 else if (name == "prettyref")
383 else if (name == "varioref")
386 else if (name == "verbatim")
389 else if (name == "nomencl")
392 else if (name == "textcomp")
395 else if (name == "url")
398 else if (LYX_FORMAT >= 408 && name == "subscript")
401 else if (name == "color") {
402 // with the following command this package is only loaded when needed for
403 // undefined colors, since we only support the predefined colors
404 h_preamble << "\\@ifundefined{definecolor}\n {\\usepackage{color}}{}\n";
407 else if (name == "graphicx")
410 else if (name == "setspace")
413 else if (name == "geometry")
414 ; // Ignore this, the geometry settings are made by the \geometry
415 // command. This command is handled below.
417 else if (is_known(name, known_languages))
420 else if (name == "natbib") {
421 h_cite_engine = "natbib_authoryear";
422 vector<string>::iterator it =
423 find(options.begin(), options.end(), "authoryear");
424 if (it != options.end())
427 it = find(options.begin(), options.end(), "numbers");
428 if (it != options.end()) {
429 h_cite_engine = "natbib_numerical";
435 else if (name == "jurabib")
436 h_cite_engine = "jurabib";
438 else if (!in_lyx_preamble) {
440 h_preamble << "\\usepackage{" << name << "}";
442 h_preamble << "\\usepackage[" << opts << "]{"
448 // We need to do something with the options...
449 if (!options.empty())
450 cerr << "Ignoring options '" << join(options, ",")
451 << "' of package " << name << '.' << endl;
453 // remove the whitespace
459 void end_preamble(ostream & os, TextClass const & /*textclass*/)
461 // merge synonym languages
462 if (is_known(h_language, known_brazilian_languages))
463 h_language = "brazilian";
464 else if (is_known(h_language, known_french_languages))
465 h_language = "french";
466 else if (is_known(h_language, known_german_languages))
467 h_language = "german";
468 else if (is_known(h_language, known_ngerman_languages))
469 h_language = "ngerman";
470 else if (is_known(h_language, known_portuguese_languages))
471 h_language = "portuguese";
472 else if (is_known(h_language, known_russian_languages))
473 h_language = "russian";
474 else if (is_known(h_language, known_ukrainian_languages))
475 h_language = "ukrainian";
477 // set the quote language
478 // LyX only knows the following quotes languages:
479 // english, swedish, german, polish, french and danish
480 // (quotes for "japanese" and "chinese-traditional" are missing because
481 // they wouldn't be useful: http://www.lyx.org/trac/ticket/6383)
482 // conversion list taken from
483 // http://en.wikipedia.org/wiki/Quotation_mark,_non-English_usage
484 // (quotes for kazakh and interlingua are unknown)
486 if (h_language == "danish")
487 h_quotes_language = "danish";
489 else if (is_known(h_language, known_french_quotes_languages)
490 || is_known(h_language, known_french_languages)
491 || is_known(h_language, known_russian_languages)
492 || is_known(h_language, known_ukrainian_languages))
493 h_quotes_language = "french";
495 else if (is_known(h_language, known_german_quotes_languages)
496 || is_known(h_language, known_german_languages)
497 || is_known(h_language, known_ngerman_languages))
498 h_quotes_language = "german";
500 else if (is_known(h_language, known_polish_quotes_languages))
501 h_quotes_language = "polish";
503 else if (is_known(h_language, known_swedish_quotes_languages))
504 h_quotes_language = "swedish";
506 else if (is_known(h_language, known_english_quotes_languages)
507 || is_known(h_language, known_brazilian_languages)
508 || is_known(h_language, known_portuguese_languages))
509 h_quotes_language = "english";
511 h_language = babel2lyx(h_language);
513 // output the LyX file settings
514 os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
515 << "\\lyxformat " << LYX_FORMAT << '\n'
516 << "\\begin_document\n"
517 << "\\begin_header\n"
518 << "\\textclass " << h_textclass << "\n";
519 if (!h_preamble.str().empty())
520 os << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
521 if (!h_options.empty())
522 os << "\\options " << h_options << "\n";
523 os << "\\language " << h_language << "\n"
524 << "\\inputencoding " << h_inputencoding << "\n"
525 << "\\font_roman " << h_font_roman << "\n"
526 << "\\font_sans " << h_font_sans << "\n"
527 << "\\font_typewriter " << h_font_typewriter << "\n"
528 << "\\font_default_family " << h_font_default_family << "\n"
529 << "\\font_sc " << h_font_sc << "\n"
530 << "\\font_osf " << h_font_osf << "\n"
531 << "\\font_sf_scale " << h_font_sf_scale << "\n"
532 << "\\font_tt_scale " << h_font_tt_scale << "\n"
533 << "\\graphics " << h_graphics << "\n"
534 << "\\paperfontsize " << h_paperfontsize << "\n"
535 << "\\spacing " << h_spacing << "\n"
536 << "\\papersize " << h_papersize << "\n"
537 << "\\use_geometry " << h_use_geometry << "\n"
538 << "\\use_amsmath " << h_use_amsmath << "\n"
539 << "\\use_esint " << h_use_esint << "\n"
540 << "\\cite_engine " << h_cite_engine << "\n"
541 << "\\use_bibtopic " << h_use_bibtopic << "\n"
542 << "\\paperorientation " << h_paperorientation << "\n"
544 << "\\secnumdepth " << h_secnumdepth << "\n"
545 << "\\tocdepth " << h_tocdepth << "\n"
546 << "\\paragraph_separation " << h_paragraph_separation << "\n"
547 << "\\defskip " << h_defskip << "\n"
548 << "\\quotes_language " << h_quotes_language << "\n"
549 << "\\papercolumns " << h_papercolumns << "\n"
550 << "\\papersides " << h_papersides << "\n"
551 << "\\paperpagestyle " << h_paperpagestyle << "\n"
552 << "\\tracking_changes " << h_tracking_changes << "\n"
553 << "\\output_changes " << h_output_changes << "\n"
554 << "\\end_header\n\n"
556 // clear preamble for subdocuments
560 } // anonymous namespace
562 void parse_preamble(Parser & p, ostream & os,
563 string const & forceclass, TeX2LyXDocClass & tc)
565 // initialize fixed types
566 special_columns['D'] = 3;
567 bool is_full_document = false;
568 bool is_lyx_file = false;
569 bool in_lyx_preamble = false;
571 // determine whether this is a full document or a fragment for inclusion
573 Token const & t = p.get_token();
575 if (t.cat() == catEscape && t.cs() == "documentclass") {
576 is_full_document = true;
582 while (is_full_document && p.good()) {
583 Token const & t = p.get_token();
586 cerr << "t: " << t << "\n";
592 if (!in_lyx_preamble &&
593 (t.cat() == catLetter ||
594 t.cat() == catSuper ||
596 t.cat() == catOther ||
597 t.cat() == catMath ||
598 t.cat() == catActive ||
599 t.cat() == catBegin ||
601 t.cat() == catAlign ||
602 t.cat() == catParameter))
603 h_preamble << t.cs();
605 else if (!in_lyx_preamble &&
606 (t.cat() == catSpace || t.cat() == catNewline))
607 h_preamble << t.asInput();
609 else if (t.cat() == catComment) {
610 // regex to parse comments (currently not used)
611 static regex const islyxfile("%% LyX .* created this file");
612 static regex const usercommands("User specified LaTeX commands");
614 string const comment = t.asInput();
616 // magically switch encoding default if it looks like XeLaTeX
617 static string const magicXeLaTeX =
618 "% This document must be compiled with XeLaTeX ";
619 if (comment.size() > magicXeLaTeX.size()
620 && comment.substr(0, magicXeLaTeX.size()) == magicXeLaTeX
621 && h_inputencoding == "auto") {
622 cerr << "XeLaTeX comment found, switching to UTF8\n";
623 h_inputencoding = "utf8";
626 if (regex_search(comment, sub, islyxfile)) {
628 in_lyx_preamble = true;
629 } else if (is_lyx_file
630 && regex_search(comment, sub, usercommands))
631 in_lyx_preamble = false;
632 else if (!in_lyx_preamble)
633 h_preamble << t.asInput();
636 else if (t.cs() == "pagestyle")
637 h_paperpagestyle = p.verbatim_item();
639 else if (t.cs() == "makeatletter") {
640 // LyX takes care of this
641 p.setCatCode('@', catLetter);
644 else if (t.cs() == "makeatother") {
645 // LyX takes care of this
646 p.setCatCode('@', catOther);
649 else if (t.cs() == "newcommand" || t.cs() == "renewcommand"
650 || t.cs() == "providecommand"
651 || t.cs() == "DeclareRobustCommand"
652 || t.cs() == "ProvideTextCommandDefault"
653 || t.cs() == "DeclareMathAccent") {
655 if (p.next_token().character() == '*') {
659 string const name = p.verbatim_item();
660 string const opt1 = p.getOpt();
661 string const opt2 = p.getFullOpt();
662 string const body = p.verbatim_item();
664 if (name == "\\rmdefault")
665 if (is_known(body, known_roman_fonts))
667 if (name == "\\sfdefault")
668 if (is_known(body, known_sans_fonts))
670 if (name == "\\ttdefault")
671 if (is_known(body, known_typewriter_fonts))
672 h_font_typewriter = body;
673 if (name == "\\familydefault") {
674 string family = body;
675 // remove leading "\"
676 h_font_default_family = family.erase(0,1);
678 // only non-lyxspecific stuff
679 if (!in_lyx_preamble) {
681 ss << '\\' << t.cs();
684 ss << '{' << name << '}' << opt1 << opt2
685 << '{' << body << "}";
686 h_preamble << ss.str();
688 // Add the command to the known commands
689 add_known_command(name, opt1, !opt2.empty());
691 ostream & out = in_preamble ? h_preamble : os;
692 out << "\\" << t.cs() << "{" << name << "}"
693 << opts << "{" << body << "}";
698 else if (t.cs() == "documentclass") {
699 vector<string>::iterator it;
700 vector<string> opts = split_options(p.getArg('[', ']'));
701 handle_opt(opts, known_fontsizes, h_paperfontsize);
702 delete_opt(opts, known_fontsizes);
703 // delete "pt" at the end
704 string::size_type i = h_paperfontsize.find("pt");
705 if (i != string::npos)
706 h_paperfontsize.erase(i);
707 // The documentclass options are always parsed before the options
708 // of the babel call so that a language cannot overwrite the babel
710 handle_opt(opts, known_languages, h_language);
711 delete_opt(opts, known_languages);
714 if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
715 h_paperorientation = "landscape";
719 if ((it = find(opts.begin(), opts.end(), "oneside"))
724 if ((it = find(opts.begin(), opts.end(), "twoside"))
730 if ((it = find(opts.begin(), opts.end(), "onecolumn"))
732 h_papercolumns = "1";
735 if ((it = find(opts.begin(), opts.end(), "twocolumn"))
737 h_papercolumns = "2";
741 // some size options are know to any document classes, other sizes
742 // are handled by the \geometry command of the geometry package
743 handle_opt(opts, known_class_paper_sizes, h_papersize);
744 delete_opt(opts, known_class_paper_sizes);
745 // the remaining options
746 h_options = join(opts, ",");
747 h_textclass = p.getArg('{', '}');
750 else if (t.cs() == "usepackage") {
751 string const options = p.getArg('[', ']');
752 string const name = p.getArg('{', '}');
753 vector<string> vecnames;
754 split(name, vecnames, ',');
755 vector<string>::const_iterator it = vecnames.begin();
756 vector<string>::const_iterator end = vecnames.end();
757 for (; it != end; ++it)
758 handle_package(p, trim(*it), options,
762 else if (t.cs() == "inputencoding") {
763 string const encoding = p.getArg('{','}');
764 h_inputencoding = encoding;
765 p.setEncoding(encoding);
768 else if (t.cs() == "newenvironment") {
769 string const name = p.getArg('{', '}');
771 ss << "\\newenvironment{" << name << "}";
774 ss << '{' << p.verbatim_item() << '}';
775 ss << '{' << p.verbatim_item() << '}';
776 if (!in_lyx_preamble)
777 h_preamble << ss.str();
780 else if (t.cs() == "def") {
781 string name = p.get_token().cs();
782 while (p.next_token().cat() != catBegin)
783 name += p.get_token().cs();
784 if (!in_lyx_preamble)
785 h_preamble << "\\def\\" << name << '{'
786 << p.verbatim_item() << "}";
789 else if (t.cs() == "newcolumntype") {
790 string const name = p.getArg('{', '}');
793 string opts = p.getOpt();
795 istringstream is(string(opts, 1));
798 special_columns[name[0]] = nargs;
799 h_preamble << "\\newcolumntype{" << name << "}";
801 h_preamble << "[" << nargs << "]";
802 h_preamble << "{" << p.verbatim_item() << "}";
805 else if (t.cs() == "setcounter") {
806 string const name = p.getArg('{', '}');
807 string const content = p.getArg('{', '}');
808 if (name == "secnumdepth")
809 h_secnumdepth = content;
810 else if (name == "tocdepth")
811 h_tocdepth = content;
813 h_preamble << "\\setcounter{" << name << "}{" << content << "}";
816 else if (t.cs() == "setlength") {
817 string const name = p.verbatim_item();
818 string const content = p.verbatim_item();
819 // the paragraphs are only not indented when \parindent is set to zero
820 if (name == "\\parindent" && content != "") {
821 if (content[0] == '0')
822 h_paragraph_separation = "skip";
823 } else if (name == "\\parskip") {
824 if (content == "\\smallskipamount")
825 h_defskip = "smallskip";
826 else if (content == "\\medskipamount")
827 h_defskip = "medskip";
828 else if (content == "\\bigskipamount")
829 h_defskip = "bigskip";
833 h_preamble << "\\setlength{" << name << "}{" << content << "}";
836 else if (t.cs() == "onehalfspacing")
837 h_spacing = "onehalf";
839 else if (t.cs() == "doublespacing")
840 h_spacing = "double";
842 else if (t.cs() == "setstretch")
843 h_spacing = "other " + p.verbatim_item();
845 else if (t.cs() == "begin") {
846 string const name = p.getArg('{', '}');
847 if (name == "document")
849 h_preamble << "\\begin{" << name << "}";
852 else if (t.cs() == "geometry") {
853 h_use_geometry = "true";
854 vector<string> opts = split_options(p.getArg('{', '}'));
855 vector<string>::iterator it;
857 if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
858 h_paperorientation = "landscape";
862 handle_opt(opts, known_paper_sizes, h_papersize);
863 delete_opt(opts, known_paper_sizes);
865 char const * const * margin = known_paper_margins;
867 for (; *margin; ++margin) {
869 // search for the "=" in e.g. "lmargin=2cm" to get the value
870 for(size_t i = 0; i != opts.size(); i++) {
871 if (opts.at(i).find(*margin) != string::npos) {
872 string::size_type pos = opts.at(i).find("=");
873 string value = opts.at(i).substr(pos + 1);
874 string name = known_coded_paper_margins[k];
875 h_margins += "\\" + name + " " + value + "\n";
881 else if (t.cs() == "jurabibsetup") {
882 vector<string> jurabibsetup =
883 split_options(p.getArg('{', '}'));
884 // add jurabibsetup to the jurabib package options
885 add_package("jurabib", jurabibsetup);
886 if (!jurabibsetup.empty()) {
887 h_preamble << "\\jurabibsetup{"
888 << join(jurabibsetup, ",") << '}';
892 else if (!t.cs().empty() && !in_lyx_preamble)
893 h_preamble << '\\' << t.cs();
896 // remove the whitespace
899 // Force textclass if the user wanted it
900 if (!forceclass.empty())
901 h_textclass = forceclass;
902 if (noweb_mode && !prefixIs(h_textclass, "literate-"))
903 h_textclass.insert(0, "literate-");
904 FileName layoutfilename = libFileSearch("layouts", h_textclass, "layout");
905 if (layoutfilename.empty()) {
906 cerr << "Error: Could not find layout file for textclass \"" << h_textclass << "\"." << endl;
909 tc.read(layoutfilename);
910 if (h_papersides.empty()) {
913 h_papersides = ss.str();
915 end_preamble(os, tc);