2 * \file BufferParams.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
11 * \author Martin Vermeer
13 * Full author contact details are available in file CREDITS.
18 #include "BufferParams.h"
21 #include "LayoutFile.h"
22 #include "BranchList.h"
23 #include "buffer_funcs.h"
29 #include "IndicesList.h"
31 #include "LaTeXFeatures.h"
32 #include "ModuleList.h"
36 #include "OutputParams.h"
40 #include "PDFOptions.h"
42 #include "frontends/alert.h"
44 #include "insets/InsetListingsParams.h"
46 #include "support/convert.h"
47 #include "support/debug.h"
48 #include "support/docstream.h"
49 #include "support/FileName.h"
50 #include "support/filetools.h"
51 #include "support/gettext.h"
52 #include "support/Messages.h"
53 #include "support/Translator.h"
54 #include "support/lstrings.h"
60 using namespace lyx::support;
63 static char const * const string_paragraph_separation[] = {
68 static char const * const string_quotes_language[] = {
69 "english", "swedish", "german", "polish", "french", "danish", ""
73 static char const * const string_papersize[] = {
74 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
75 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
76 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
77 "b5paper", "b6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
82 static char const * const string_orientation[] = {
83 "portrait", "landscape", ""
87 static char const * const string_footnotekinds[] = {
88 "footnote", "margin", "fig", "tab", "alg", "wide-fig", "wide-tab", ""
92 static char const * const tex_graphics[] = {
93 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
94 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
95 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
96 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
107 // Paragraph separation
108 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
111 ParSepTranslator const init_parseptranslator()
113 ParSepTranslator translator
114 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
115 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
120 ParSepTranslator const & parseptranslator()
122 static ParSepTranslator translator = init_parseptranslator();
128 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
131 QuotesLangTranslator const init_quoteslangtranslator()
133 QuotesLangTranslator translator
134 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
135 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
136 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
137 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
138 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
139 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
144 QuotesLangTranslator const & quoteslangtranslator()
146 static QuotesLangTranslator translator = init_quoteslangtranslator();
152 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
155 static PaperSizeTranslator initPaperSizeTranslator()
157 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
158 translator.addPair(string_papersize[1], PAPER_CUSTOM);
159 translator.addPair(string_papersize[2], PAPER_USLETTER);
160 translator.addPair(string_papersize[3], PAPER_USLEGAL);
161 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
162 translator.addPair(string_papersize[5], PAPER_A0);
163 translator.addPair(string_papersize[6], PAPER_A1);
164 translator.addPair(string_papersize[7], PAPER_A2);
165 translator.addPair(string_papersize[8], PAPER_A3);
166 translator.addPair(string_papersize[9], PAPER_A4);
167 translator.addPair(string_papersize[10], PAPER_A5);
168 translator.addPair(string_papersize[11], PAPER_A6);
169 translator.addPair(string_papersize[12], PAPER_B0);
170 translator.addPair(string_papersize[13], PAPER_B1);
171 translator.addPair(string_papersize[14], PAPER_B2);
172 translator.addPair(string_papersize[15], PAPER_B3);
173 translator.addPair(string_papersize[16], PAPER_B4);
174 translator.addPair(string_papersize[17], PAPER_B5);
175 translator.addPair(string_papersize[18], PAPER_B6);
176 translator.addPair(string_papersize[19], PAPER_JISB0);
177 translator.addPair(string_papersize[20], PAPER_JISB1);
178 translator.addPair(string_papersize[21], PAPER_JISB2);
179 translator.addPair(string_papersize[22], PAPER_JISB3);
180 translator.addPair(string_papersize[23], PAPER_JISB4);
181 translator.addPair(string_papersize[24], PAPER_JISB5);
182 translator.addPair(string_papersize[25], PAPER_JISB6);
187 PaperSizeTranslator const & papersizetranslator()
189 static PaperSizeTranslator translator = initPaperSizeTranslator();
195 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
198 PaperOrientationTranslator const init_paperorientationtranslator()
200 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
201 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
206 PaperOrientationTranslator const & paperorientationtranslator()
208 static PaperOrientationTranslator translator = init_paperorientationtranslator();
214 typedef Translator<int, PageSides> SidesTranslator;
217 SidesTranslator const init_sidestranslator()
219 SidesTranslator translator(1, OneSide);
220 translator.addPair(2, TwoSides);
225 SidesTranslator const & sidestranslator()
227 static SidesTranslator translator = init_sidestranslator();
233 typedef Translator<int, BufferParams::Package> PackageTranslator;
236 PackageTranslator const init_packagetranslator()
238 PackageTranslator translator(0, BufferParams::package_off);
239 translator.addPair(1, BufferParams::package_auto);
240 translator.addPair(2, BufferParams::package_on);
245 PackageTranslator const & packagetranslator()
247 static PackageTranslator translator = init_packagetranslator();
253 typedef Translator<string, CiteEngine> CiteEngineTranslator;
256 CiteEngineTranslator const init_citeenginetranslator()
258 CiteEngineTranslator translator("basic", ENGINE_BASIC);
259 translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL);
260 translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
261 translator.addPair("jurabib", ENGINE_JURABIB);
266 CiteEngineTranslator const & citeenginetranslator()
268 static CiteEngineTranslator translator = init_citeenginetranslator();
274 typedef Translator<string, Spacing::Space> SpaceTranslator;
277 SpaceTranslator const init_spacetranslator()
279 SpaceTranslator translator("default", Spacing::Default);
280 translator.addPair("single", Spacing::Single);
281 translator.addPair("onehalf", Spacing::Onehalf);
282 translator.addPair("double", Spacing::Double);
283 translator.addPair("other", Spacing::Other);
288 SpaceTranslator const & spacetranslator()
290 static SpaceTranslator translator = init_spacetranslator();
297 class BufferParams::Impl
302 AuthorList authorlist;
303 BranchList branchlist;
304 Bullet temp_bullets[4];
305 Bullet user_defined_bullets[4];
306 IndicesList indiceslist;
308 /** This is the amount of space used for paragraph_separation "skip",
309 * and for detached paragraphs in "indented" documents.
313 PDFOptions pdfoptions;
314 LayoutFileIndex baseClass_;
318 BufferParams::Impl::Impl()
319 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
321 // set initial author
323 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
328 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
332 return new BufferParams::Impl(*ptr);
336 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
342 BufferParams::BufferParams()
345 setBaseClass(defaultBaseclass());
347 paragraph_separation = ParagraphIndentSeparation;
348 quotes_language = InsetQuotes::EnglishQuotes;
349 fontsize = "default";
352 papersize = PAPER_DEFAULT;
353 orientation = ORIENTATION_PORTRAIT;
354 use_geometry = false;
355 use_amsmath = package_auto;
356 use_esint = package_auto;
357 use_mhchem = package_auto;
358 cite_engine_ = ENGINE_BASIC;
359 use_bibtopic = false;
361 trackChanges = false;
362 outputChanges = false;
363 use_default_options = true;
364 maintain_unincluded_children = false;
367 language = default_language;
369 fontsRoman = "default";
370 fontsSans = "default";
371 fontsTypewriter = "default";
372 fontsDefaultFamily = "default";
376 fontsSansScale = 100;
377 fontsTypewriterScale = 100;
379 graphicsDriver = "default";
380 defaultOutputFormat = "default";
381 bibtex_command = "default";
382 index_command = "default";
385 listings_params = string();
386 pagestyle = "default";
387 suppress_date = false;
388 // no color is the default (white)
389 backgroundcolor = lyx::rgbFromHexName("#ffffff");
390 isbackgroundcolor = false;
391 // no color is the default (black)
392 fontcolor = lyx::rgbFromHexName("#000000");
394 // light gray is the default font color for greyed-out notes
395 notefontcolor = lyx::rgbFromHexName("#cccccc");
396 boxbgcolor = lyx::rgbFromHexName("#ff0000");
397 compressed = lyxrc.save_compressed;
398 for (int iter = 0; iter < 4; ++iter) {
399 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
400 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
403 indiceslist().addDefault(B_("Index"));
404 html_be_strict = false;
405 html_math_output = MathML;
406 html_math_img_scale = 1.0;
407 html_latex_start = "<span class='latex'>";
408 html_latex_end = "</span>";
412 docstring BufferParams::B_(string const & l10n) const
414 LASSERT(language, /**/);
415 return getMessages(language->code()).get(l10n);
419 AuthorList & BufferParams::authors()
421 return pimpl_->authorlist;
425 AuthorList const & BufferParams::authors() const
427 return pimpl_->authorlist;
431 BranchList & BufferParams::branchlist()
433 return pimpl_->branchlist;
437 BranchList const & BufferParams::branchlist() const
439 return pimpl_->branchlist;
443 IndicesList & BufferParams::indiceslist()
445 return pimpl_->indiceslist;
449 IndicesList const & BufferParams::indiceslist() const
451 return pimpl_->indiceslist;
455 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
457 LASSERT(index < 4, /**/);
458 return pimpl_->temp_bullets[index];
462 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
464 LASSERT(index < 4, /**/);
465 return pimpl_->temp_bullets[index];
469 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
471 LASSERT(index < 4, /**/);
472 return pimpl_->user_defined_bullets[index];
476 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
478 LASSERT(index < 4, /**/);
479 return pimpl_->user_defined_bullets[index];
483 Spacing & BufferParams::spacing()
485 return pimpl_->spacing;
489 Spacing const & BufferParams::spacing() const
491 return pimpl_->spacing;
495 PDFOptions & BufferParams::pdfoptions()
497 return pimpl_->pdfoptions;
501 PDFOptions const & BufferParams::pdfoptions() const
503 return pimpl_->pdfoptions;
507 HSpace const & BufferParams::getIndentation() const
509 return pimpl_->indentation;
513 void BufferParams::setIndentation(HSpace const & indent)
515 pimpl_->indentation = indent;
519 VSpace const & BufferParams::getDefSkip() const
521 return pimpl_->defskip;
525 void BufferParams::setDefSkip(VSpace const & vs)
527 pimpl_->defskip = vs;
531 string BufferParams::readToken(Lexer & lex, string const & token,
532 FileName const & filepath)
534 if (token == "\\textclass") {
536 string const classname = lex.getString();
537 // if there exists a local layout file, ignore the system one
538 // NOTE: in this case, the textclass (.cls file) is assumed to be available.
540 LayoutFileList & bcl = LayoutFileList::get();
541 if (tcp.empty() && !filepath.empty())
542 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
546 setBaseClass(classname);
547 // We assume that a tex class exists for local or unknown layouts so this warning
548 // will only be given for system layouts.
549 if (!baseClass()->isTeXClassAvailable()) {
551 translateIfPossible(from_utf8(baseClass()->description()));
552 docstring const msg =
553 bformat(_("The used document class\n"
555 "requires external files that are not available.\n"
556 "The document class can still be used, but LyX\n"
557 "will not be able to produce output until the\n"
558 "following prerequisites are installed:\n"
560 "See section 3.1.2.2 of the User's Guide for\n"
561 "more information."),
562 desc, from_utf8(baseClass()->prerequisites()));
563 frontend::Alert::warning(_("Document class not available"),
566 } else if (token == "\\begin_preamble") {
568 } else if (token == "\\begin_local_layout") {
569 readLocalLayout(lex);
570 } else if (token == "\\begin_modules") {
572 } else if (token == "\\begin_removed_modules") {
573 readRemovedModules(lex);
574 } else if (token == "\\begin_includeonly") {
575 readIncludeonly(lex);
576 } else if (token == "\\maintain_unincluded_children") {
577 lex >> maintain_unincluded_children;
578 } else if (token == "\\options") {
580 options = lex.getString();
581 } else if (token == "\\use_default_options") {
582 lex >> use_default_options;
583 } else if (token == "\\master") {
585 master = lex.getString();
586 } else if (token == "\\suppress_date") {
587 lex >> suppress_date;
588 } else if (token == "\\language") {
590 } else if (token == "\\inputencoding") {
592 } else if (token == "\\graphics") {
593 readGraphicsDriver(lex);
594 } else if (token == "\\default_output_format") {
595 lex >> defaultOutputFormat;
596 } else if (token == "\\bibtex_command") {
598 bibtex_command = lex.getString();
599 } else if (token == "\\index_command") {
601 index_command = lex.getString();
602 } else if (token == "\\fontencoding") {
604 fontenc = lex.getString();
605 } else if (token == "\\font_roman") {
607 fontsRoman = lex.getString();
608 } else if (token == "\\font_sans") {
610 fontsSans = lex.getString();
611 } else if (token == "\\font_typewriter") {
613 fontsTypewriter = lex.getString();
614 } else if (token == "\\font_default_family") {
615 lex >> fontsDefaultFamily;
616 } else if (token == "\\use_xetex") {
618 } else if (token == "\\font_sc") {
620 } else if (token == "\\font_osf") {
622 } else if (token == "\\font_sf_scale") {
623 lex >> fontsSansScale;
624 } else if (token == "\\font_tt_scale") {
625 lex >> fontsTypewriterScale;
626 } else if (token == "\\font_cjk") {
628 } else if (token == "\\paragraph_separation") {
631 paragraph_separation = parseptranslator().find(parsep);
632 } else if (token == "\\paragraph_indentation") {
634 string indentation = lex.getString();
635 pimpl_->indentation = HSpace(indentation);
636 } else if (token == "\\defskip") {
638 string defskip = lex.getString();
639 if (defskip == "defskip")
642 pimpl_->defskip = VSpace(defskip);
643 } else if (token == "\\quotes_language") {
646 quotes_language = quoteslangtranslator().find(quotes_lang);
647 } else if (token == "\\papersize") {
650 papersize = papersizetranslator().find(ppsize);
651 } else if (token == "\\use_geometry") {
653 } else if (token == "\\use_amsmath") {
656 use_amsmath = packagetranslator().find(use_ams);
657 } else if (token == "\\use_esint") {
660 use_esint = packagetranslator().find(useesint);
661 } else if (token == "\\use_mhchem") {
664 use_mhchem = packagetranslator().find(usemhchem);
665 } else if (token == "\\cite_engine") {
668 cite_engine_ = citeenginetranslator().find(engine);
669 } else if (token == "\\use_bibtopic") {
671 } else if (token == "\\use_indices") {
673 } else if (token == "\\tracking_changes") {
675 } else if (token == "\\output_changes") {
676 lex >> outputChanges;
677 } else if (token == "\\branch") {
679 docstring branch = lex.getDocString();
680 branchlist().add(branch);
683 string const tok = lex.getString();
684 if (tok == "\\end_branch")
686 Branch * branch_ptr = branchlist().find(branch);
687 if (tok == "\\selected") {
690 branch_ptr->setSelected(lex.getInteger());
692 if (tok == "\\filename_suffix") {
695 branch_ptr->setFileNameSuffix(lex.getInteger());
697 if (tok == "\\color") {
699 string color = lex.getString();
701 branch_ptr->setColor(color);
702 // Update also the Color table:
704 color = lcolor.getX11Name(Color_background);
706 lcolor.setColor(to_utf8(branch), color);
709 } else if (token == "\\index") {
711 docstring index = lex.getDocString();
713 indiceslist().add(index);
716 string const tok = lex.getString();
717 if (tok == "\\end_index")
719 Index * index_ptr = indiceslist().find(index);
720 if (tok == "\\shortcut") {
722 shortcut = lex.getDocString();
724 index_ptr->setShortcut(shortcut);
726 if (tok == "\\color") {
728 string color = lex.getString();
730 index_ptr->setColor(color);
731 // Update also the Color table:
733 color = lcolor.getX11Name(Color_background);
735 if (!shortcut.empty())
736 lcolor.setColor(to_utf8(shortcut), color);
739 } else if (token == "\\author") {
741 istringstream ss(lex.getString());
744 author_map[a.buffer_id()] = pimpl_->authorlist.record(a);
745 } else if (token == "\\paperorientation") {
748 orientation = paperorientationtranslator().find(orient);
749 } else if (token == "\\backgroundcolor") {
751 backgroundcolor = lyx::rgbFromHexName(lex.getString());
752 isbackgroundcolor = true;
753 } else if (token == "\\fontcolor") {
755 fontcolor = lyx::rgbFromHexName(lex.getString());
757 } else if (token == "\\notefontcolor") {
759 string color = lex.getString();
760 notefontcolor = lyx::rgbFromHexName(color);
761 } else if (token == "\\boxbgcolor") {
763 string color = lex.getString();
764 boxbgcolor = lyx::rgbFromHexName(color);
765 } else if (token == "\\paperwidth") {
767 } else if (token == "\\paperheight") {
769 } else if (token == "\\leftmargin") {
771 } else if (token == "\\topmargin") {
773 } else if (token == "\\rightmargin") {
775 } else if (token == "\\bottommargin") {
777 } else if (token == "\\headheight") {
779 } else if (token == "\\headsep") {
781 } else if (token == "\\footskip") {
783 } else if (token == "\\columnsep") {
785 } else if (token == "\\paperfontsize") {
787 } else if (token == "\\papercolumns") {
789 } else if (token == "\\listings_params") {
792 listings_params = InsetListingsParams(par).params();
793 } else if (token == "\\papersides") {
796 sides = sidestranslator().find(psides);
797 } else if (token == "\\paperpagestyle") {
799 } else if (token == "\\bullet") {
801 } else if (token == "\\bulletLaTeX") {
802 readBulletsLaTeX(lex);
803 } else if (token == "\\secnumdepth") {
805 } else if (token == "\\tocdepth") {
807 } else if (token == "\\spacing") {
811 if (nspacing == "other") {
814 spacing().set(spacetranslator().find(nspacing), tmp_val);
815 } else if (token == "\\float_placement") {
816 lex >> float_placement;
818 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
819 string toktmp = pdfoptions().readToken(lex, token);
820 if (!toktmp.empty()) {
821 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
825 } else if (token == "\\html_math_output") {
828 html_math_output = static_cast<MathOutput>(temp);
829 } else if (token == "\\html_be_strict") {
830 lex >> html_be_strict;
831 } else if (token == "\\html_math_img_scale") {
832 lex >> html_math_img_scale;
833 } else if (token == "\\html_latex_start") {
834 lex >> html_latex_start;
835 } else if (token == "\\html_latex_end") {
836 lex >> html_latex_end;
838 lyxerr << "BufferParams::readToken(): Unknown token: " <<
847 void BufferParams::writeFile(ostream & os) const
849 // The top of the file is written by the buffer.
850 // Prints out the buffer info into the .lyx file given by file
853 os << "\\textclass " << baseClass()->name() << '\n';
856 if (!preamble.empty()) {
857 // remove '\n' from the end of preamble
858 string const tmppreamble = rtrim(preamble, "\n");
859 os << "\\begin_preamble\n"
861 << "\n\\end_preamble\n";
865 if (!options.empty()) {
866 os << "\\options " << options << '\n';
869 // use the class options defined in the layout?
870 os << "\\use_default_options "
871 << convert<string>(use_default_options) << "\n";
873 // the master document
874 if (!master.empty()) {
875 os << "\\master " << master << '\n';
879 if (!removedModules_.empty()) {
880 os << "\\begin_removed_modules" << '\n';
881 list<string>::const_iterator it = removedModules_.begin();
882 list<string>::const_iterator en = removedModules_.end();
883 for (; it != en; it++)
885 os << "\\end_removed_modules" << '\n';
889 if (!layoutModules_.empty()) {
890 os << "\\begin_modules" << '\n';
891 LayoutModuleList::const_iterator it = layoutModules_.begin();
892 LayoutModuleList::const_iterator en = layoutModules_.end();
893 for (; it != en; it++)
895 os << "\\end_modules" << '\n';
899 if (!includedChildren_.empty()) {
900 os << "\\begin_includeonly" << '\n';
901 list<string>::const_iterator it = includedChildren_.begin();
902 list<string>::const_iterator en = includedChildren_.end();
903 for (; it != en; it++)
905 os << "\\end_includeonly" << '\n';
907 os << "\\maintain_unincluded_children "
908 << convert<string>(maintain_unincluded_children) << '\n';
910 // local layout information
911 if (!local_layout.empty()) {
912 // remove '\n' from the end
913 string const tmplocal = rtrim(local_layout, "\n");
914 os << "\\begin_local_layout\n"
916 << "\n\\end_local_layout\n";
919 // then the text parameters
920 if (language != ignore_language)
921 os << "\\language " << language->lang() << '\n';
922 os << "\\inputencoding " << inputenc
923 << "\n\\fontencoding " << fontenc
924 << "\n\\font_roman " << fontsRoman
925 << "\n\\font_sans " << fontsSans
926 << "\n\\font_typewriter " << fontsTypewriter
927 << "\n\\font_default_family " << fontsDefaultFamily
928 << "\n\\use_xetex " << convert<string>(useXetex)
929 << "\n\\font_sc " << convert<string>(fontsSC)
930 << "\n\\font_osf " << convert<string>(fontsOSF)
931 << "\n\\font_sf_scale " << fontsSansScale
932 << "\n\\font_tt_scale " << fontsTypewriterScale
934 if (!fontsCJK.empty()) {
935 os << "\\font_cjk " << fontsCJK << '\n';
937 os << "\n\\graphics " << graphicsDriver << '\n';
938 os << "\\default_output_format " << defaultOutputFormat << '\n';
939 os << "\\bibtex_command " << bibtex_command << '\n';
940 os << "\\index_command " << index_command << '\n';
942 if (!float_placement.empty()) {
943 os << "\\float_placement " << float_placement << '\n';
945 os << "\\paperfontsize " << fontsize << '\n';
947 spacing().writeFile(os);
948 pdfoptions().writeFile(os);
950 os << "\\papersize " << string_papersize[papersize]
951 << "\n\\use_geometry " << convert<string>(use_geometry)
952 << "\n\\use_amsmath " << use_amsmath
953 << "\n\\use_esint " << use_esint
954 << "\n\\use_mhchem " << use_mhchem
955 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
956 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
957 << "\n\\use_indices " << convert<string>(use_indices)
958 << "\n\\paperorientation " << string_orientation[orientation]
959 << "\n\\suppress_date " << convert<string>(suppress_date)
961 if (isbackgroundcolor == true)
962 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
963 if (isfontcolor == true)
964 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
965 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
966 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
967 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
968 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
970 BranchList::const_iterator it = branchlist().begin();
971 BranchList::const_iterator end = branchlist().end();
972 for (; it != end; ++it) {
973 os << "\\branch " << to_utf8(it->branch())
974 << "\n\\selected " << it->isSelected()
975 << "\n\\filename_suffix " << it->hasFileNameSuffix()
976 << "\n\\color " << lyx::X11hexname(it->color())
981 IndicesList::const_iterator iit = indiceslist().begin();
982 IndicesList::const_iterator iend = indiceslist().end();
983 for (; iit != iend; ++iit) {
984 os << "\\index " << to_utf8(iit->index())
985 << "\n\\shortcut " << to_utf8(iit->shortcut())
986 << "\n\\color " << lyx::X11hexname(iit->color())
991 if (!paperwidth.empty())
992 os << "\\paperwidth "
993 << VSpace(paperwidth).asLyXCommand() << '\n';
994 if (!paperheight.empty())
995 os << "\\paperheight "
996 << VSpace(paperheight).asLyXCommand() << '\n';
997 if (!leftmargin.empty())
998 os << "\\leftmargin "
999 << VSpace(leftmargin).asLyXCommand() << '\n';
1000 if (!topmargin.empty())
1001 os << "\\topmargin "
1002 << VSpace(topmargin).asLyXCommand() << '\n';
1003 if (!rightmargin.empty())
1004 os << "\\rightmargin "
1005 << VSpace(rightmargin).asLyXCommand() << '\n';
1006 if (!bottommargin.empty())
1007 os << "\\bottommargin "
1008 << VSpace(bottommargin).asLyXCommand() << '\n';
1009 if (!headheight.empty())
1010 os << "\\headheight "
1011 << VSpace(headheight).asLyXCommand() << '\n';
1012 if (!headsep.empty())
1014 << VSpace(headsep).asLyXCommand() << '\n';
1015 if (!footskip.empty())
1017 << VSpace(footskip).asLyXCommand() << '\n';
1018 if (!columnsep.empty())
1019 os << "\\columnsep "
1020 << VSpace(columnsep).asLyXCommand() << '\n';
1021 os << "\\secnumdepth " << secnumdepth
1022 << "\n\\tocdepth " << tocdepth
1023 << "\n\\paragraph_separation "
1024 << string_paragraph_separation[paragraph_separation];
1025 if (!paragraph_separation)
1026 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1028 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1029 os << "\n\\quotes_language "
1030 << string_quotes_language[quotes_language]
1031 << "\n\\papercolumns " << columns
1032 << "\n\\papersides " << sides
1033 << "\n\\paperpagestyle " << pagestyle << '\n';
1034 if (!listings_params.empty())
1035 os << "\\listings_params \"" <<
1036 InsetListingsParams(listings_params).encodedString() << "\"\n";
1037 for (int i = 0; i < 4; ++i) {
1038 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1039 if (user_defined_bullet(i).getFont() != -1) {
1040 os << "\\bullet " << i << " "
1041 << user_defined_bullet(i).getFont() << " "
1042 << user_defined_bullet(i).getCharacter() << " "
1043 << user_defined_bullet(i).getSize() << "\n";
1047 os << "\\bulletLaTeX " << i << " \""
1048 << lyx::to_ascii(user_defined_bullet(i).getText())
1054 os << "\\tracking_changes " << convert<string>(trackChanges) << '\n'
1055 << "\\output_changes " << convert<string>(outputChanges) << '\n'
1056 << "\\html_math_output " << html_math_output << '\n'
1057 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n'
1058 << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n'
1059 << "\\html_latex_start \"" << html_latex_start << "\"\n"
1060 << "\\html_latex_end \"" << html_latex_end << "\"\n";
1062 os << pimpl_->authorlist;
1066 void BufferParams::validate(LaTeXFeatures & features) const
1068 features.require(documentClass().requires());
1070 if (outputChanges) {
1071 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1072 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1073 LaTeXFeatures::isAvailable("xcolor");
1075 switch (features.runparams().flavor) {
1076 case OutputParams::LATEX:
1078 features.require("ct-dvipost");
1079 features.require("dvipost");
1080 } else if (xcolorulem) {
1081 features.require("ct-xcolor-ulem");
1082 features.require("ulem");
1083 features.require("xcolor");
1085 features.require("ct-none");
1088 case OutputParams::PDFLATEX:
1089 case OutputParams::XETEX:
1091 features.require("ct-xcolor-ulem");
1092 features.require("ulem");
1093 features.require("xcolor");
1094 // improves color handling in PDF output
1095 features.require("pdfcolmk");
1097 features.require("ct-none");
1105 // Floats with 'Here definitely' as default setting.
1106 if (float_placement.find('H') != string::npos)
1107 features.require("float");
1109 // AMS Style is at document level
1110 if (use_amsmath == package_on
1111 || documentClass().provides("amsmath"))
1112 features.require("amsmath");
1113 if (use_esint == package_on)
1114 features.require("esint");
1115 if (use_mhchem == package_on)
1116 features.require("mhchem");
1118 // Document-level line spacing
1119 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1120 features.require("setspace");
1122 // the bullet shapes are buffer level not paragraph level
1123 // so they are tested here
1124 for (int i = 0; i < 4; ++i) {
1125 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1127 int const font = user_defined_bullet(i).getFont();
1129 int const c = user_defined_bullet(i).getCharacter();
1135 features.require("latexsym");
1137 } else if (font == 1) {
1138 features.require("amssymb");
1139 } else if (font >= 2 && font <= 5) {
1140 features.require("pifont");
1144 if (pdfoptions().use_hyperref) {
1145 features.require("hyperref");
1146 // due to interferences with babel and hyperref, the color package has to
1147 // be loaded after hyperref when hyperref is used with the colorlinks
1148 // option, see http://www.lyx.org/trac/ticket/5291
1149 if (pdfoptions().colorlinks)
1150 features.require("color");
1154 features.require("xetex");
1156 if (language->lang() == "vietnamese")
1157 features.require("vietnamese");
1158 else if (language->lang() == "japanese")
1159 features.require("japanese");
1163 bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
1164 TexRow & texrow, FileName const & filepath) const
1166 os << "\\documentclass";
1168 DocumentClass const & tclass = documentClass();
1170 ostringstream clsoptions; // the document class options.
1172 if (tokenPos(tclass.opt_fontsize(),
1173 '|', fontsize) >= 0) {
1174 // only write if existing in list (and not default)
1175 clsoptions << fontsize << "pt,";
1178 // all paper sizes except of A4, A5, B5 and the US sizes need the
1180 bool nonstandard_papersize = papersize != PAPER_USLETTER
1181 && papersize != PAPER_USLEGAL
1182 && papersize != PAPER_USEXECUTIVE
1183 && papersize != PAPER_A4
1184 && papersize != PAPER_A5
1185 && papersize != PAPER_B5;
1187 if (!use_geometry) {
1188 switch (papersize) {
1190 clsoptions << "a4paper,";
1192 case PAPER_USLETTER:
1193 clsoptions << "letterpaper,";
1196 clsoptions << "a5paper,";
1199 clsoptions << "b5paper,";
1201 case PAPER_USEXECUTIVE:
1202 clsoptions << "executivepaper,";
1205 clsoptions << "legalpaper,";
1232 if (sides != tclass.sides()) {
1235 clsoptions << "oneside,";
1238 clsoptions << "twoside,";
1244 if (columns != tclass.columns()) {
1246 clsoptions << "twocolumn,";
1248 clsoptions << "onecolumn,";
1252 && orientation == ORIENTATION_LANDSCAPE)
1253 clsoptions << "landscape,";
1255 // language should be a parameter to \documentclass
1256 if (language->babel() == "hebrew"
1257 && default_language->babel() != "hebrew")
1258 // This seems necessary
1259 features.useLanguage(default_language);
1261 ostringstream language_options;
1262 bool const use_babel = features.useBabel();
1264 language_options << features.getLanguages();
1265 if (!language->babel().empty()) {
1266 if (!language_options.str().empty())
1267 language_options << ',';
1268 language_options << language->babel();
1270 // if Vietnamese is used, babel must directly be loaded
1271 // with language options, not in the class options, see
1272 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
1273 size_t viet = language_options.str().find("vietnam");
1274 // viet = string::npos when not found
1275 // the same is for all other languages that are not directly supported by
1276 // babel, but where LaTeX-packages add babel support.
1277 // this is currently the case for Latvian, Lithuanian, Mongolian
1279 size_t latvian = language_options.str().find("latvian");
1280 size_t lithu = language_options.str().find("lithuanian");
1281 size_t mongo = language_options.str().find("mongolian");
1282 size_t turkmen = language_options.str().find("turkmen");
1283 // if Japanese is used, babel must directly be loaded
1284 // with language options, not in the class options, see
1285 // http://www.lyx.org/trac/ticket/4597#c4
1286 size_t japan = language_options.str().find("japanese");
1287 if (lyxrc.language_global_options && !language_options.str().empty()
1288 && viet == string::npos && japan == string::npos
1289 && latvian == string::npos && lithu == string::npos
1290 && mongo == string::npos && turkmen == string::npos)
1291 clsoptions << language_options.str() << ',';
1294 // the predefined options from the layout
1295 if (use_default_options && !tclass.options().empty())
1296 clsoptions << tclass.options() << ',';
1298 // the user-defined options
1299 if (!options.empty()) {
1300 clsoptions << options << ',';
1303 string strOptions(clsoptions.str());
1304 if (!strOptions.empty()) {
1305 strOptions = rtrim(strOptions, ",");
1307 os << '[' << from_utf8(strOptions) << ']';
1310 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1312 // end of \documentclass defs
1315 os << "\\usepackage{fontspec}\n";
1319 // font selection must be done before loading fontenc.sty
1320 string const fonts =
1321 loadFonts(fontsRoman, fontsSans,
1322 fontsTypewriter, fontsSC, fontsOSF,
1323 fontsSansScale, fontsTypewriterScale, useXetex);
1324 if (!fonts.empty()) {
1325 os << from_ascii(fonts);
1328 if (fontsDefaultFamily != "default")
1329 os << "\\renewcommand{\\familydefault}{\\"
1330 << from_ascii(fontsDefaultFamily) << "}\n";
1332 // set font encoding
1333 // for arabic_arabi and farsi we also need to load the LAE and
1335 // XeTeX works without fontenc
1336 if (font_encoding() != "default" && language->lang() != "japanese"
1338 if (language->lang() == "arabic_arabi"
1339 || language->lang() == "farsi") {
1340 os << "\\usepackage[" << from_ascii(font_encoding())
1341 << ",LFE,LAE]{fontenc}\n";
1344 os << "\\usepackage[" << from_ascii(font_encoding())
1350 // handle inputenc etc.
1351 writeEncodingPreamble(os, features, texrow);
1354 if (!features.runparams().includeall && !includedChildren_.empty()) {
1355 os << "\\includeonly{";
1356 list<string>::const_iterator it = includedChildren_.begin();
1358 for (; it != includedChildren_.end() ; ++it) {
1359 string incfile = *it;
1360 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1361 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1363 if (!features.runparams().nice)
1365 // \includeonly doesn't want an extension
1366 incfile = changeExtension(incfile, string());
1367 incfile = support::latex_path(incfile);
1368 if (!incfile.empty()) {
1371 os << from_utf8(incfile);
1378 if (!listings_params.empty() || features.isRequired("listings")) {
1379 os << "\\usepackage{listings}\n";
1382 if (!listings_params.empty()) {
1384 // do not test validity because listings_params is
1385 // supposed to be valid
1387 InsetListingsParams(listings_params).separatedParams(true);
1388 // we can't support all packages, but we should load the color package
1389 if (par.find("\\color", 0) != string::npos)
1390 features.require("color");
1391 os << from_utf8(par);
1392 // count the number of newlines
1393 for (size_t i = 0; i < par.size(); ++i)
1399 if (!tclass.provides("geometry")
1400 && (use_geometry || nonstandard_papersize)) {
1401 odocstringstream ods;
1402 if (!getGraphicsDriver("geometry").empty())
1403 ods << getGraphicsDriver("geometry");
1404 if (orientation == ORIENTATION_LANDSCAPE)
1405 ods << ",landscape";
1406 switch (papersize) {
1408 if (!paperwidth.empty())
1409 ods << ",paperwidth="
1410 << from_ascii(paperwidth);
1411 if (!paperheight.empty())
1412 ods << ",paperheight="
1413 << from_ascii(paperheight);
1415 case PAPER_USLETTER:
1416 ods << ",letterpaper";
1419 ods << ",legalpaper";
1421 case PAPER_USEXECUTIVE:
1422 ods << ",executivepaper";
1488 // default papersize ie PAPER_DEFAULT
1489 switch (lyxrc.default_papersize) {
1490 case PAPER_DEFAULT: // keep compiler happy
1491 case PAPER_USLETTER:
1492 ods << ",letterpaper";
1495 ods << ",legalpaper";
1497 case PAPER_USEXECUTIVE:
1498 ods << ",executivepaper";
1567 docstring const g_options = trim(ods.str(), ",");
1568 os << "\\usepackage";
1569 if (!g_options.empty())
1570 os << '[' << g_options << ']';
1571 os << "{geometry}\n";
1573 os << "\\geometry{verbose";
1574 if (!topmargin.empty())
1575 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1576 if (!bottommargin.empty())
1577 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1578 if (!leftmargin.empty())
1579 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1580 if (!rightmargin.empty())
1581 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1582 if (!headheight.empty())
1583 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1584 if (!headsep.empty())
1585 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1586 if (!footskip.empty())
1587 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1588 if (!columnsep.empty())
1589 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1592 } else if (orientation == ORIENTATION_LANDSCAPE) {
1593 features.require("papersize");
1596 if (tokenPos(tclass.opt_pagestyle(),
1597 '|', pagestyle) >= 0) {
1598 if (pagestyle == "fancy") {
1599 os << "\\usepackage{fancyhdr}\n";
1602 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1606 // only output when the background color is not default
1607 if (isbackgroundcolor == true) {
1608 // only require color here, the background color will be defined
1609 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1611 features.require("color");
1612 features.require("pagecolor");
1615 // only output when the font color is not default
1616 if (isfontcolor == true) {
1617 // only require color here, the font color will be defined
1618 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1620 features.require("color");
1621 features.require("fontcolor");
1624 // Only if class has a ToC hierarchy
1625 if (tclass.hasTocLevels()) {
1626 if (secnumdepth != tclass.secnumdepth()) {
1627 os << "\\setcounter{secnumdepth}{"
1632 if (tocdepth != tclass.tocdepth()) {
1633 os << "\\setcounter{tocdepth}{"
1640 if (paragraph_separation) {
1641 // when skip separation
1642 switch (getDefSkip().kind()) {
1643 case VSpace::SMALLSKIP:
1644 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1646 case VSpace::MEDSKIP:
1647 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1649 case VSpace::BIGSKIP:
1650 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1652 case VSpace::LENGTH:
1653 os << "\\setlength{\\parskip}{"
1654 << from_utf8(getDefSkip().length().asLatexString())
1657 default: // should never happen // Then delete it.
1658 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1662 os << "\\setlength{\\parindent}{0pt}\n";
1665 // when separation by indentation
1666 // only output something when a width is given
1667 if (getIndentation().asLyXCommand() != "default") {
1668 os << "\\setlength{\\parindent}{"
1669 << from_utf8(getIndentation().asLatexCommand())
1675 // Now insert the LyX specific LaTeX commands...
1676 docstring lyxpreamble;
1678 // due to interferences with babel and hyperref, the color package has to
1679 // be loaded (when it is not already loaded) before babel when hyperref
1680 // is used with the colorlinks option, see
1681 // http://www.lyx.org/trac/ticket/5291
1682 // we decided therefore to load color always before babel, see
1683 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1684 lyxpreamble += from_ascii(features.getColorOptions());
1686 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1688 && (features.isRequired("jurabib")
1689 || features.isRequired("hyperref")
1690 || features.isRequired("vietnamese")
1691 || features.isRequired("japanese") ) ) {
1693 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1694 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1697 // The optional packages;
1698 lyxpreamble += from_ascii(features.getPackages());
1700 // Additional Indices
1701 if (features.isRequired("splitidx")) {
1702 IndicesList::const_iterator iit = indiceslist().begin();
1703 IndicesList::const_iterator iend = indiceslist().end();
1704 for (; iit != iend; ++iit) {
1705 lyxpreamble += "\\newindex[";
1706 lyxpreamble += iit->index();
1707 lyxpreamble += "]{";
1708 lyxpreamble += iit->shortcut();
1709 lyxpreamble += "}\n";
1714 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1717 // * Hyperref manual: "Make sure it comes last of your loaded
1718 // packages, to give it a fighting chance of not being over-written,
1719 // since its job is to redefine many LaTeX commands."
1720 // * Email from Heiko Oberdiek: "It is usually better to load babel
1721 // before hyperref. Then hyperref has a chance to detect babel.
1722 // * Has to be loaded before the "LyX specific LaTeX commands" to
1723 // avoid errors with algorithm floats.
1724 // use hyperref explicitly if it is required
1725 if (features.isRequired("hyperref")) {
1726 // pass what we have to stream here, since we need
1727 // to access the stream itself in PDFOptions.
1731 int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1733 OutputParams tmp_params = features.runparams();
1734 lines += pdfoptions().writeLaTeX(tmp_params, os,
1735 documentClass().provides("hyperref"));
1736 texrow.newlines(lines);
1737 // set back for the rest
1738 lyxpreamble.clear();
1741 // Will be surrounded by \makeatletter and \makeatother when not empty
1742 docstring atlyxpreamble;
1744 // Some macros LyX will need
1745 docstring tmppreamble(features.getMacros());
1747 if (!tmppreamble.empty())
1748 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1749 "LyX specific LaTeX commands.\n"
1750 + tmppreamble + '\n';
1752 // the text class specific preamble
1753 tmppreamble = features.getTClassPreamble();
1754 if (!tmppreamble.empty())
1755 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1756 "Textclass specific LaTeX commands.\n"
1757 + tmppreamble + '\n';
1759 // suppress date if selected
1760 // use \@ifundefined because we cannot be sure that every document class
1761 // has a \date command
1763 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1765 /* the user-defined preamble */
1766 if (!containsOnly(preamble, " \n\t"))
1768 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1769 "User specified LaTeX commands.\n"
1770 + from_utf8(preamble) + '\n';
1772 // subfig loads internally the LaTeX package "caption". As
1773 // caption is a very popular package, users will load it in
1774 // the preamble. Therefore we must load subfig behind the
1775 // user-defined preamble and check if the caption package was
1776 // loaded or not. For the case that caption is loaded before
1777 // subfig, there is the subfig option "caption=false". This
1778 // option also works when a koma-script class is used and
1779 // koma's own caption commands are used instead of caption. We
1780 // use \PassOptionsToPackage here because the user could have
1781 // already loaded subfig in the preamble.
1782 if (features.isRequired("subfig")) {
1783 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1784 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1785 "\\usepackage{subfig}\n";
1788 // Itemize bullet settings need to be last in case the user
1789 // defines their own bullets that use a package included
1790 // in the user-defined preamble -- ARRae
1791 // Actually it has to be done much later than that
1792 // since some packages like frenchb make modifications
1793 // at \begin{document} time -- JMarc
1794 docstring bullets_def;
1795 for (int i = 0; i < 4; ++i) {
1796 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1797 if (bullets_def.empty())
1798 bullets_def += "\\AtBeginDocument{\n";
1799 bullets_def += " \\def\\labelitemi";
1801 // `i' is one less than the item to modify
1808 bullets_def += "ii";
1814 bullets_def += '{' +
1815 user_defined_bullet(i).getText()
1820 if (!bullets_def.empty())
1821 atlyxpreamble += bullets_def + "}\n\n";
1823 if (!atlyxpreamble.empty())
1824 lyxpreamble += "\n\\makeatletter\n"
1825 + atlyxpreamble + "\\makeatother\n\n";
1827 // We try to load babel late, in case it interferes with other packages.
1828 // Jurabib and Hyperref have to be called after babel, though.
1829 if (use_babel && !features.isRequired("jurabib")
1830 && !features.isRequired("hyperref")
1831 && !features.isRequired("vietnamese")
1832 && !features.isRequired("japanese")) {
1834 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1835 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1838 docstring const i18npreamble = features.getTClassI18nPreamble(use_babel);
1839 if (!i18npreamble.empty())
1840 lyxpreamble += i18npreamble + '\n';
1843 int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1844 texrow.newlines(nlines);
1848 // these packages (xunicode, for that matter) need to be loaded at least
1849 // after amsmath, amssymb, esint and the other packages that provide
1852 os << "\\usepackage{xunicode}\n";
1854 os << "\\usepackage{xltxtra}\n";
1861 void BufferParams::useClassDefaults()
1863 DocumentClass const & tclass = documentClass();
1865 sides = tclass.sides();
1866 columns = tclass.columns();
1867 pagestyle = tclass.pagestyle();
1868 use_default_options = true;
1869 // Only if class has a ToC hierarchy
1870 if (tclass.hasTocLevels()) {
1871 secnumdepth = tclass.secnumdepth();
1872 tocdepth = tclass.tocdepth();
1877 bool BufferParams::hasClassDefaults() const
1879 DocumentClass const & tclass = documentClass();
1881 return sides == tclass.sides()
1882 && columns == tclass.columns()
1883 && pagestyle == tclass.pagestyle()
1884 && use_default_options
1885 && secnumdepth == tclass.secnumdepth()
1886 && tocdepth == tclass.tocdepth();
1890 DocumentClass const & BufferParams::documentClass() const
1896 DocumentClass const * BufferParams::documentClassPtr() const {
1901 void BufferParams::setDocumentClass(DocumentClass const * const tc) {
1902 // evil, but this function is evil
1903 doc_class_ = const_cast<DocumentClass *>(tc);
1907 bool BufferParams::setBaseClass(string const & classname)
1909 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1910 LayoutFileList & bcl = LayoutFileList::get();
1911 if (!bcl.haveClass(classname)) {
1913 bformat(_("The layout file:\n"
1915 "could not be found. A default textclass with default\n"
1916 "layouts will be used. LyX will not be able to produce\n"
1918 from_utf8(classname));
1919 frontend::Alert::error(_("Document class not found"), s);
1920 bcl.addEmptyClass(classname);
1923 bool const success = bcl[classname].load();
1926 bformat(_("Due to some error in it, the layout file:\n"
1928 "could not be loaded. A default textclass with default\n"
1929 "layouts will be used. LyX will not be able to produce\n"
1931 from_utf8(classname));
1932 frontend::Alert::error(_("Could not load class"), s);
1933 bcl.addEmptyClass(classname);
1936 pimpl_->baseClass_ = classname;
1937 layoutModules_.adaptToBaseClass(baseClass(), removedModules_);
1942 LayoutFile const * BufferParams::baseClass() const
1944 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
1945 return &(LayoutFileList::get()[pimpl_->baseClass_]);
1951 LayoutFileIndex const & BufferParams::baseClassID() const
1953 return pimpl_->baseClass_;
1957 void BufferParams::makeDocumentClass()
1962 doc_class_ = &(DocumentClassBundle::get().makeDocumentClass(*baseClass(), layoutModules_));
1964 if (!local_layout.empty()) {
1965 if (!doc_class_->read(local_layout, TextClass::MODULE)) {
1966 docstring const msg = _("Error reading internal layout information");
1967 frontend::Alert::warning(_("Read Error"), msg);
1973 bool BufferParams::moduleCanBeAdded(string const & modName) const
1975 return layoutModules_.moduleCanBeAdded(modName, baseClass());
1979 bool BufferParams::addLayoutModule(string const & modName)
1981 LayoutModuleList::const_iterator it = layoutModules_.begin();
1982 LayoutModuleList::const_iterator end = layoutModules_.end();
1983 for (; it != end; it++)
1986 layoutModules_.push_back(modName);
1991 Font const BufferParams::getFont() const
1993 FontInfo f = documentClass().defaultfont();
1994 if (fontsDefaultFamily == "rmdefault")
1995 f.setFamily(ROMAN_FAMILY);
1996 else if (fontsDefaultFamily == "sfdefault")
1997 f.setFamily(SANS_FAMILY);
1998 else if (fontsDefaultFamily == "ttdefault")
1999 f.setFamily(TYPEWRITER_FAMILY);
2000 return Font(f, language);
2004 void BufferParams::readPreamble(Lexer & lex)
2006 if (lex.getString() != "\\begin_preamble")
2007 lyxerr << "Error (BufferParams::readPreamble):"
2008 "consistency check failed." << endl;
2010 preamble = lex.getLongString("\\end_preamble");
2014 void BufferParams::readLocalLayout(Lexer & lex)
2016 if (lex.getString() != "\\begin_local_layout")
2017 lyxerr << "Error (BufferParams::readLocalLayout):"
2018 "consistency check failed." << endl;
2020 local_layout = lex.getLongString("\\end_local_layout");
2024 void BufferParams::readLanguage(Lexer & lex)
2026 if (!lex.next()) return;
2028 string const tmptok = lex.getString();
2030 // check if tmptok is part of tex_babel in tex-defs.h
2031 language = languages.getLanguage(tmptok);
2033 // Language tmptok was not found
2034 language = default_language;
2035 lyxerr << "Warning: Setting language `"
2036 << tmptok << "' to `" << language->lang()
2042 void BufferParams::readGraphicsDriver(Lexer & lex)
2047 string const tmptok = lex.getString();
2048 // check if tmptok is part of tex_graphics in tex_defs.h
2051 string const test = tex_graphics[n++];
2053 if (test == tmptok) {
2054 graphicsDriver = tmptok;
2059 "Warning: graphics driver `$$Token' not recognized!\n"
2060 " Setting graphics driver to `default'.\n");
2061 graphicsDriver = "default";
2068 void BufferParams::readBullets(Lexer & lex)
2073 int const index = lex.getInteger();
2075 int temp_int = lex.getInteger();
2076 user_defined_bullet(index).setFont(temp_int);
2077 temp_bullet(index).setFont(temp_int);
2079 user_defined_bullet(index).setCharacter(temp_int);
2080 temp_bullet(index).setCharacter(temp_int);
2082 user_defined_bullet(index).setSize(temp_int);
2083 temp_bullet(index).setSize(temp_int);
2087 void BufferParams::readBulletsLaTeX(Lexer & lex)
2089 // The bullet class should be able to read this.
2092 int const index = lex.getInteger();
2094 docstring const temp_str = lex.getDocString();
2096 user_defined_bullet(index).setText(temp_str);
2097 temp_bullet(index).setText(temp_str);
2101 void BufferParams::readModules(Lexer & lex)
2103 if (!lex.eatLine()) {
2104 lyxerr << "Error (BufferParams::readModules):"
2105 "Unexpected end of input." << endl;
2109 string mod = lex.getString();
2110 if (mod == "\\end_modules")
2112 addLayoutModule(mod);
2118 void BufferParams::readRemovedModules(Lexer & lex)
2120 if (!lex.eatLine()) {
2121 lyxerr << "Error (BufferParams::readRemovedModules):"
2122 "Unexpected end of input." << endl;
2126 string mod = lex.getString();
2127 if (mod == "\\end_removed_modules")
2129 removedModules_.push_back(mod);
2132 // now we want to remove any removed modules that were previously
2133 // added. normally, that will be because default modules were added in
2134 // setBaseClass(), which gets called when \textclass is read at the
2135 // start of the read.
2136 list<string>::const_iterator rit = removedModules_.begin();
2137 list<string>::const_iterator const ren = removedModules_.end();
2138 for (; rit != ren; rit++) {
2139 LayoutModuleList::iterator const mit = layoutModules_.begin();
2140 LayoutModuleList::iterator const men = layoutModules_.end();
2141 LayoutModuleList::iterator found = find(mit, men, *rit);
2144 layoutModules_.erase(found);
2149 void BufferParams::readIncludeonly(Lexer & lex)
2151 if (!lex.eatLine()) {
2152 lyxerr << "Error (BufferParams::readIncludeonly):"
2153 "Unexpected end of input." << endl;
2157 string child = lex.getString();
2158 if (child == "\\end_includeonly")
2160 includedChildren_.push_back(child);
2166 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2168 char real_papersize = papersize;
2169 if (real_papersize == PAPER_DEFAULT)
2170 real_papersize = lyxrc.default_papersize;
2172 switch (real_papersize) {
2174 // could be anything, so don't guess
2176 case PAPER_CUSTOM: {
2177 if (purpose == XDVI && !paperwidth.empty() &&
2178 !paperheight.empty()) {
2179 // heightxwidth<unit>
2180 string first = paperwidth;
2181 string second = paperheight;
2182 if (orientation == ORIENTATION_LANDSCAPE)
2185 return first.erase(first.length() - 2)
2191 // dvips and dvipdfm do not know this
2192 if (purpose == DVIPS || purpose == DVIPDFM)
2196 if (purpose == DVIPS || purpose == DVIPDFM)
2200 if (purpose == DVIPS || purpose == DVIPDFM)
2210 if (purpose == DVIPS || purpose == DVIPDFM)
2214 if (purpose == DVIPS || purpose == DVIPDFM)
2218 if (purpose == DVIPS || purpose == DVIPDFM)
2222 if (purpose == DVIPS || purpose == DVIPDFM)
2226 if (purpose == DVIPS || purpose == DVIPDFM)
2230 // dvipdfm does not know this
2231 if (purpose == DVIPDFM)
2235 if (purpose == DVIPDFM)
2239 if (purpose == DVIPS || purpose == DVIPDFM)
2243 if (purpose == DVIPS || purpose == DVIPDFM)
2247 if (purpose == DVIPS || purpose == DVIPDFM)
2251 if (purpose == DVIPS || purpose == DVIPDFM)
2255 if (purpose == DVIPS || purpose == DVIPDFM)
2259 if (purpose == DVIPS || purpose == DVIPDFM)
2263 if (purpose == DVIPS || purpose == DVIPDFM)
2267 if (purpose == DVIPS || purpose == DVIPDFM)
2270 case PAPER_USEXECUTIVE:
2271 // dvipdfm does not know this
2272 if (purpose == DVIPDFM)
2277 case PAPER_USLETTER:
2279 if (purpose == XDVI)
2286 string const BufferParams::dvips_options() const
2291 && papersize == PAPER_CUSTOM
2292 && !lyxrc.print_paper_dimension_flag.empty()
2293 && !paperwidth.empty()
2294 && !paperheight.empty()) {
2295 // using a custom papersize
2296 result = lyxrc.print_paper_dimension_flag;
2297 result += ' ' + paperwidth;
2298 result += ',' + paperheight;
2300 string const paper_option = paperSizeName(DVIPS);
2301 if (!paper_option.empty() && (paper_option != "letter" ||
2302 orientation != ORIENTATION_LANDSCAPE)) {
2303 // dvips won't accept -t letter -t landscape.
2304 // In all other cases, include the paper size
2306 result = lyxrc.print_paper_flag;
2307 result += ' ' + paper_option;
2310 if (orientation == ORIENTATION_LANDSCAPE &&
2311 papersize != PAPER_CUSTOM)
2312 result += ' ' + lyxrc.print_landscape_flag;
2317 string const BufferParams::font_encoding() const
2319 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2323 string BufferParams::babelCall(string const & lang_opts) const
2325 string lang_pack = lyxrc.language_package;
2326 if (lang_pack != "\\usepackage{babel}")
2328 // suppress the babel call when there is no babel language defined
2329 // for the document language in the lib/languages file and if no
2330 // other languages are used (lang_opts is then empty)
2331 if (lang_opts.empty())
2333 // If Vietnamese is used, babel must directly be loaded with the
2334 // language options, see
2335 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
2336 size_t viet = lang_opts.find("vietnam");
2337 // viet = string::npos when not found
2338 // the same is for all other languages that are not directly supported by
2339 // babel, but where LaTeX-packages add babel support.
2340 // this is currently the case for Latvian, Lithuanian, Mongolian
2342 size_t latvian = lang_opts.find("latvian");
2343 size_t lithu = lang_opts.find("lithuanian");
2344 size_t mongo = lang_opts.find("mongolian");
2345 size_t turkmen = lang_opts.find("turkmen");
2346 // If Japanese is used, babel must directly be loaded with the
2347 // language options, see
2348 // http://www.lyx.org/trac/ticket/4597#c4
2349 size_t japan = lang_opts.find("japanese");
2350 if (!lyxrc.language_global_options || viet != string::npos
2351 || japan != string::npos || latvian != string::npos
2352 || lithu != string::npos || mongo != string::npos
2353 || turkmen != string::npos)
2354 return "\\usepackage[" + lang_opts + "]{babel}";
2359 docstring BufferParams::getGraphicsDriver(string const & package) const
2363 if (package == "geometry") {
2364 if (graphicsDriver == "dvips"
2365 || graphicsDriver == "dvipdfm"
2366 || graphicsDriver == "pdftex"
2367 || graphicsDriver == "vtex")
2368 result = from_ascii(graphicsDriver);
2369 else if (graphicsDriver == "dvipdfmx")
2370 result = from_ascii("dvipdfm");
2377 void BufferParams::writeEncodingPreamble(odocstream & os,
2378 LaTeXFeatures & features, TexRow & texrow) const
2382 if (inputenc == "auto") {
2383 string const doc_encoding =
2384 language->encoding()->latexName();
2385 Encoding::Package const package =
2386 language->encoding()->package();
2388 // Create a list with all the input encodings used
2390 set<string> encodings =
2391 features.getEncodingSet(doc_encoding);
2393 // If the "japanese" package (i.e. pLaTeX) is used,
2394 // inputenc must be omitted.
2395 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2396 if (package == Encoding::japanese)
2397 features.require("japanese");
2399 if ((!encodings.empty() || package == Encoding::inputenc)
2400 && !features.isRequired("japanese")) {
2401 os << "\\usepackage[";
2402 set<string>::const_iterator it = encodings.begin();
2403 set<string>::const_iterator const end = encodings.end();
2405 os << from_ascii(*it);
2408 for (; it != end; ++it)
2409 os << ',' << from_ascii(*it);
2410 if (package == Encoding::inputenc) {
2411 if (!encodings.empty())
2413 os << from_ascii(doc_encoding);
2415 os << "]{inputenc}\n";
2418 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2419 if (language->encoding()->name() == "utf8-cjk"
2420 && LaTeXFeatures::isAvailable("CJKutf8"))
2421 os << "\\usepackage{CJKutf8}\n";
2423 os << "\\usepackage{CJK}\n";
2426 } else if (inputenc != "default") {
2427 switch (encoding().package()) {
2428 case Encoding::none:
2429 case Encoding::japanese:
2431 case Encoding::inputenc:
2432 // do not load inputenc if japanese is used
2433 if (features.isRequired("japanese"))
2435 os << "\\usepackage[" << from_ascii(inputenc)
2440 if (encoding().name() == "utf8-cjk"
2441 && LaTeXFeatures::isAvailable("CJKutf8"))
2442 os << "\\usepackage{CJKutf8}\n";
2444 os << "\\usepackage{CJK}\n";
2450 // The encoding "armscii8" (for Armenian) is only available when
2451 // the package "armtex" is loaded.
2452 if (language->encoding()->latexName() == "armscii8"
2453 || inputenc == "armscii8") {
2454 os << "\\usepackage{armtex}\n";
2460 string const BufferParams::parseFontName(string const & name) const
2462 string mangled = name;
2463 size_t const idx = mangled.find('[');
2464 if (idx == string::npos || idx == 0)
2467 return mangled.substr(0, idx - 1);
2471 string const BufferParams::loadFonts(string const & rm,
2472 string const & sf, string const & tt,
2473 bool const & sc, bool const & osf,
2474 int const & sfscale, int const & ttscale,
2475 bool const & xetex) const
2477 /* The LaTeX font world is in a flux. In the PSNFSS font interface,
2478 several packages have been replaced by others, that might not
2479 be installed on every system. We have to take care for that
2480 (see psnfss.pdf). We try to support all psnfss fonts as well
2481 as the fonts that have become de facto standard in the LaTeX
2482 world (e.g. Latin Modern). We do not support obsolete fonts
2483 (like PSLatex). In general, it should be possible to mix any
2484 rm font with any sf or tt font, respectively. (JSpitzm)
2486 -- separate math fonts.
2489 if (rm == "default" && sf == "default" && tt == "default")
2496 if (rm != "default")
2497 os << "\\setmainfont[Mapping=tex-text]{"
2498 << parseFontName(rm) << "}\n";
2499 if (sf != "default") {
2500 string const sans = parseFontName(sf);
2502 os << "\\setsansfont[Scale="
2503 << float(sfscale) / 100
2504 << ",Mapping=tex-text]{"
2507 os << "\\setsansfont[Mapping=tex-text]{"
2510 if (tt != "default") {
2511 string const mono = parseFontName(tt);
2513 os << "\\setmonofont[Scale="
2514 << float(sfscale) / 100
2518 os << "\\setmonofont[Mapping=tex-text]{"
2522 os << "\\defaultfontfeatures{Numbers=OldStyle}\n";
2527 // Computer Modern (must be explicitly selectable -- there might be classes
2528 // that define a different default font!
2530 os << "\\renewcommand{\\rmdefault}{cmr}\n";
2531 // osf for Computer Modern needs eco.sty
2533 os << "\\usepackage{eco}\n";
2535 // Latin Modern Roman
2536 else if (rm == "lmodern")
2537 os << "\\usepackage{lmodern}\n";
2539 else if (rm == "ae") {
2540 // not needed when using OT1 font encoding.
2541 if (font_encoding() != "default")
2542 os << "\\usepackage{ae,aecompl}\n";
2545 else if (rm == "times") {
2546 // try to load the best available package
2547 if (LaTeXFeatures::isAvailable("mathptmx"))
2548 os << "\\usepackage{mathptmx}\n";
2549 else if (LaTeXFeatures::isAvailable("mathptm"))
2550 os << "\\usepackage{mathptm}\n";
2552 os << "\\usepackage{times}\n";
2555 else if (rm == "palatino") {
2556 // try to load the best available package
2557 if (LaTeXFeatures::isAvailable("mathpazo")) {
2558 os << "\\usepackage";
2564 // "osf" includes "sc"!
2568 os << "{mathpazo}\n";
2570 else if (LaTeXFeatures::isAvailable("mathpple"))
2571 os << "\\usepackage{mathpple}\n";
2573 os << "\\usepackage{palatino}\n";
2576 else if (rm == "utopia") {
2577 // fourier supersedes utopia.sty, but does
2578 // not work with OT1 encoding.
2579 if (LaTeXFeatures::isAvailable("fourier")
2580 && font_encoding() != "default") {
2581 os << "\\usepackage";
2592 os << "{fourier}\n";
2595 os << "\\usepackage{utopia}\n";
2597 // Bera (complete fontset)
2598 else if (rm == "bera" && sf == "default" && tt == "default")
2599 os << "\\usepackage{bera}\n";
2601 else if (rm != "default")
2602 os << "\\usepackage" << "{" << rm << "}\n";
2605 // Helvetica, Bera Sans
2606 if (sf == "helvet" || sf == "berasans") {
2608 os << "\\usepackage[scaled=" << float(sfscale) / 100
2609 << "]{" << sf << "}\n";
2611 os << "\\usepackage{" << sf << "}\n";
2614 else if (sf == "avant")
2615 os << "\\usepackage{" << sf << "}\n";
2616 // Computer Modern, Latin Modern, CM Bright
2617 else if (sf != "default")
2618 os << "\\renewcommand{\\sfdefault}{" << sf << "}\n";
2620 // monospaced/typewriter
2621 // Courier, LuxiMono
2622 if (tt == "luximono" || tt == "beramono") {
2624 os << "\\usepackage[scaled=" << float(ttscale) / 100
2625 << "]{" << tt << "}\n";
2627 os << "\\usepackage{" << tt << "}\n";
2630 else if (tt == "courier" )
2631 os << "\\usepackage{" << tt << "}\n";
2632 // Computer Modern, Latin Modern, CM Bright
2633 else if (tt != "default")
2634 os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
2640 Encoding const & BufferParams::encoding() const
2643 return *(encodings.fromLaTeXName("utf8-plain"));
2644 if (inputenc == "auto" || inputenc == "default")
2645 return *language->encoding();
2646 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2649 LYXERR0("Unknown inputenc value `" << inputenc
2650 << "'. Using `auto' instead.");
2651 return *language->encoding();
2655 CiteEngine BufferParams::citeEngine() const
2657 // FIXME the class should provide the numerical/
2658 // authoryear choice
2659 if (documentClass().provides("natbib")
2660 && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
2661 return ENGINE_NATBIB_AUTHORYEAR;
2662 return cite_engine_;
2666 void BufferParams::setCiteEngine(CiteEngine cite_engine)
2668 cite_engine_ = cite_engine;