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"
27 #include "Converter.h"
30 #include "IndicesList.h"
32 #include "LaTeXFeatures.h"
33 #include "ModuleList.h"
37 #include "OutputParams.h"
41 #include "PDFOptions.h"
43 #include "frontends/alert.h"
45 #include "insets/InsetListingsParams.h"
47 #include "support/convert.h"
48 #include "support/debug.h"
49 #include "support/docstream.h"
50 #include "support/FileName.h"
51 #include "support/filetools.h"
52 #include "support/gettext.h"
53 #include "support/Messages.h"
54 #include "support/Translator.h"
55 #include "support/lstrings.h"
61 using namespace lyx::support;
64 static char const * const string_paragraph_separation[] = {
69 static char const * const string_quotes_language[] = {
70 "english", "swedish", "german", "polish", "french", "danish", ""
74 static char const * const string_papersize[] = {
75 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
76 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
77 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
78 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
79 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
84 static char const * const string_orientation[] = {
85 "portrait", "landscape", ""
89 static char const * const string_footnotekinds[] = {
90 "footnote", "margin", "fig", "tab", "alg", "wide-fig", "wide-tab", ""
94 static char const * const tex_graphics[] = {
95 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
96 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
97 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
98 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
109 // Paragraph separation
110 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
113 ParSepTranslator const init_parseptranslator()
115 ParSepTranslator translator
116 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
117 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
122 ParSepTranslator const & parseptranslator()
124 static ParSepTranslator translator = init_parseptranslator();
130 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
133 QuotesLangTranslator const init_quoteslangtranslator()
135 QuotesLangTranslator translator
136 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
137 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
138 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
139 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
140 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
141 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
146 QuotesLangTranslator const & quoteslangtranslator()
148 static QuotesLangTranslator translator = init_quoteslangtranslator();
154 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
157 static PaperSizeTranslator initPaperSizeTranslator()
159 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
160 translator.addPair(string_papersize[1], PAPER_CUSTOM);
161 translator.addPair(string_papersize[2], PAPER_USLETTER);
162 translator.addPair(string_papersize[3], PAPER_USLEGAL);
163 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
164 translator.addPair(string_papersize[5], PAPER_A0);
165 translator.addPair(string_papersize[6], PAPER_A1);
166 translator.addPair(string_papersize[7], PAPER_A2);
167 translator.addPair(string_papersize[8], PAPER_A3);
168 translator.addPair(string_papersize[9], PAPER_A4);
169 translator.addPair(string_papersize[10], PAPER_A5);
170 translator.addPair(string_papersize[11], PAPER_A6);
171 translator.addPair(string_papersize[12], PAPER_B0);
172 translator.addPair(string_papersize[13], PAPER_B1);
173 translator.addPair(string_papersize[14], PAPER_B2);
174 translator.addPair(string_papersize[15], PAPER_B3);
175 translator.addPair(string_papersize[16], PAPER_B4);
176 translator.addPair(string_papersize[17], PAPER_B5);
177 translator.addPair(string_papersize[18], PAPER_B6);
178 translator.addPair(string_papersize[19], PAPER_C0);
179 translator.addPair(string_papersize[20], PAPER_C1);
180 translator.addPair(string_papersize[21], PAPER_C2);
181 translator.addPair(string_papersize[22], PAPER_C3);
182 translator.addPair(string_papersize[23], PAPER_C4);
183 translator.addPair(string_papersize[24], PAPER_C5);
184 translator.addPair(string_papersize[25], PAPER_C6);
185 translator.addPair(string_papersize[26], PAPER_JISB0);
186 translator.addPair(string_papersize[27], PAPER_JISB1);
187 translator.addPair(string_papersize[28], PAPER_JISB2);
188 translator.addPair(string_papersize[29], PAPER_JISB3);
189 translator.addPair(string_papersize[30], PAPER_JISB4);
190 translator.addPair(string_papersize[31], PAPER_JISB5);
191 translator.addPair(string_papersize[32], PAPER_JISB6);
196 PaperSizeTranslator const & papersizetranslator()
198 static PaperSizeTranslator translator = initPaperSizeTranslator();
204 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
207 PaperOrientationTranslator const init_paperorientationtranslator()
209 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
210 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
215 PaperOrientationTranslator const & paperorientationtranslator()
217 static PaperOrientationTranslator translator = init_paperorientationtranslator();
223 typedef Translator<int, PageSides> SidesTranslator;
226 SidesTranslator const init_sidestranslator()
228 SidesTranslator translator(1, OneSide);
229 translator.addPair(2, TwoSides);
234 SidesTranslator const & sidestranslator()
236 static SidesTranslator translator = init_sidestranslator();
242 typedef Translator<int, BufferParams::Package> PackageTranslator;
245 PackageTranslator const init_packagetranslator()
247 PackageTranslator translator(0, BufferParams::package_off);
248 translator.addPair(1, BufferParams::package_auto);
249 translator.addPair(2, BufferParams::package_on);
254 PackageTranslator const & packagetranslator()
256 static PackageTranslator translator = init_packagetranslator();
262 typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
265 CiteEngineTypeTranslator const init_citeenginetypetranslator()
267 CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
268 translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
273 CiteEngineTypeTranslator const & citeenginetypetranslator()
275 static CiteEngineTypeTranslator translator = init_citeenginetypetranslator();
281 typedef Translator<string, Spacing::Space> SpaceTranslator;
284 SpaceTranslator const init_spacetranslator()
286 SpaceTranslator translator("default", Spacing::Default);
287 translator.addPair("single", Spacing::Single);
288 translator.addPair("onehalf", Spacing::Onehalf);
289 translator.addPair("double", Spacing::Double);
290 translator.addPair("other", Spacing::Other);
295 SpaceTranslator const & spacetranslator()
297 static SpaceTranslator translator = init_spacetranslator();
304 class BufferParams::Impl
309 AuthorList authorlist;
310 BranchList branchlist;
311 Bullet temp_bullets[4];
312 Bullet user_defined_bullets[4];
313 IndicesList indiceslist;
315 /** This is the amount of space used for paragraph_separation "skip",
316 * and for detached paragraphs in "indented" documents.
320 PDFOptions pdfoptions;
321 LayoutFileIndex baseClass_;
325 BufferParams::Impl::Impl()
326 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
328 // set initial author
330 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
335 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
339 return new BufferParams::Impl(*ptr);
343 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
349 BufferParams::BufferParams()
352 setBaseClass(defaultBaseclass());
354 paragraph_separation = ParagraphIndentSeparation;
355 quotes_language = InsetQuotes::EnglishQuotes;
356 fontsize = "default";
359 papersize = PAPER_DEFAULT;
360 orientation = ORIENTATION_PORTRAIT;
361 use_geometry = false;
362 cite_engine_.push_back("basic");
363 cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
364 biblio_style = "plain";
365 use_bibtopic = false;
367 trackChanges = false;
368 outputChanges = false;
369 use_default_options = true;
370 maintain_unincluded_children = false;
373 language = default_language;
375 fonts_roman = "default";
376 fonts_sans = "default";
377 fonts_typewriter = "default";
378 fonts_default_family = "default";
379 useNonTeXFonts = false;
380 fonts_expert_sc = false;
381 fonts_old_figures = false;
382 fonts_sans_scale = 100;
383 fonts_typewriter_scale = 100;
385 lang_package = "default";
386 graphics_driver = "default";
387 default_output_format = "default";
388 bibtex_command = "default";
389 index_command = "default";
392 listings_params = string();
393 pagestyle = "default";
394 suppress_date = false;
395 justification = true;
396 // no color is the default (white)
397 backgroundcolor = lyx::rgbFromHexName("#ffffff");
398 isbackgroundcolor = false;
399 // no color is the default (black)
400 fontcolor = lyx::rgbFromHexName("#000000");
402 // light gray is the default font color for greyed-out notes
403 notefontcolor = lyx::rgbFromHexName("#cccccc");
404 boxbgcolor = lyx::rgbFromHexName("#ff0000");
405 compressed = lyxrc.save_compressed;
406 for (int iter = 0; iter < 4; ++iter) {
407 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
408 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
411 indiceslist().addDefault(B_("Index"));
412 html_be_strict = false;
413 html_math_output = MathML;
414 html_math_img_scale = 1.0;
415 html_css_as_file = false;
422 docstring BufferParams::B_(string const & l10n) const
424 LASSERT(language, /**/);
425 return getMessages(language->code()).get(l10n);
429 BufferParams::Package BufferParams::use_package(std::string const & p) const
431 PackageMap::const_iterator it = use_packages.find(p);
432 if (it == use_packages.end())
438 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
444 vector<string> const & BufferParams::auto_packages()
446 static vector<string> packages;
447 if (packages.empty()) {
448 // adding a package here implies a file format change!
449 packages.push_back("amsmath");
450 packages.push_back("esint");
451 packages.push_back("mathdots");
452 packages.push_back("mathtools");
453 packages.push_back("mhchem");
454 packages.push_back("undertilde");
460 AuthorList & BufferParams::authors()
462 return pimpl_->authorlist;
466 AuthorList const & BufferParams::authors() const
468 return pimpl_->authorlist;
472 BranchList & BufferParams::branchlist()
474 return pimpl_->branchlist;
478 BranchList const & BufferParams::branchlist() const
480 return pimpl_->branchlist;
484 IndicesList & BufferParams::indiceslist()
486 return pimpl_->indiceslist;
490 IndicesList const & BufferParams::indiceslist() const
492 return pimpl_->indiceslist;
496 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
498 LASSERT(index < 4, /**/);
499 return pimpl_->temp_bullets[index];
503 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
505 LASSERT(index < 4, /**/);
506 return pimpl_->temp_bullets[index];
510 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
512 LASSERT(index < 4, /**/);
513 return pimpl_->user_defined_bullets[index];
517 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
519 LASSERT(index < 4, /**/);
520 return pimpl_->user_defined_bullets[index];
524 Spacing & BufferParams::spacing()
526 return pimpl_->spacing;
530 Spacing const & BufferParams::spacing() const
532 return pimpl_->spacing;
536 PDFOptions & BufferParams::pdfoptions()
538 return pimpl_->pdfoptions;
542 PDFOptions const & BufferParams::pdfoptions() const
544 return pimpl_->pdfoptions;
548 HSpace const & BufferParams::getIndentation() const
550 return pimpl_->indentation;
554 void BufferParams::setIndentation(HSpace const & indent)
556 pimpl_->indentation = indent;
560 VSpace const & BufferParams::getDefSkip() const
562 return pimpl_->defskip;
566 void BufferParams::setDefSkip(VSpace const & vs)
568 // DEFSKIP will cause an infinite loop
569 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
570 pimpl_->defskip = vs;
574 string BufferParams::readToken(Lexer & lex, string const & token,
575 FileName const & filepath)
577 if (token == "\\textclass") {
579 string const classname = lex.getString();
580 // if there exists a local layout file, ignore the system one
581 // NOTE: in this case, the textclass (.cls file) is assumed to
584 LayoutFileList & bcl = LayoutFileList::get();
585 if (tcp.empty() && !filepath.empty())
586 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
590 setBaseClass(classname);
591 // We assume that a tex class exists for local or unknown
592 // layouts so this warning, will only be given for system layouts.
593 if (!baseClass()->isTeXClassAvailable()) {
594 docstring const desc =
595 translateIfPossible(from_utf8(baseClass()->description()));
596 docstring const prereqs =
597 from_utf8(baseClass()->prerequisites());
598 docstring const msg =
599 bformat(_("The selected document class\n"
601 "requires external files that are not available.\n"
602 "The document class can still be used, but the\n"
603 "document cannot be compiled until the following\n"
604 "prerequisites are installed:\n"
606 "See section 3.1.2.2 (Class Availability) of the\n"
607 "User's Guide for more information."), desc, prereqs);
608 frontend::Alert::warning(_("Document class not available"),
611 } else if (token == "\\begin_preamble") {
613 } else if (token == "\\begin_local_layout") {
614 readLocalLayout(lex);
615 } else if (token == "\\begin_modules") {
617 } else if (token == "\\begin_removed_modules") {
618 readRemovedModules(lex);
619 } else if (token == "\\begin_includeonly") {
620 readIncludeonly(lex);
621 } else if (token == "\\maintain_unincluded_children") {
622 lex >> maintain_unincluded_children;
623 } else if (token == "\\options") {
625 options = lex.getString();
626 } else if (token == "\\use_default_options") {
627 lex >> use_default_options;
628 } else if (token == "\\master") {
630 master = lex.getString();
631 } else if (token == "\\suppress_date") {
632 lex >> suppress_date;
633 } else if (token == "\\justification") {
634 lex >> justification;
635 } else if (token == "\\language") {
637 } else if (token == "\\language_package") {
639 lang_package = lex.getString();
640 } else if (token == "\\inputencoding") {
642 } else if (token == "\\graphics") {
643 readGraphicsDriver(lex);
644 } else if (token == "\\default_output_format") {
645 lex >> default_output_format;
646 } else if (token == "\\bibtex_command") {
648 bibtex_command = lex.getString();
649 } else if (token == "\\index_command") {
651 index_command = lex.getString();
652 } else if (token == "\\fontencoding") {
654 fontenc = lex.getString();
655 } else if (token == "\\font_roman") {
657 fonts_roman = lex.getString();
658 } else if (token == "\\font_sans") {
660 fonts_sans = lex.getString();
661 } else if (token == "\\font_typewriter") {
663 fonts_typewriter = lex.getString();
664 } else if (token == "\\font_default_family") {
665 lex >> fonts_default_family;
666 } else if (token == "\\use_non_tex_fonts") {
667 lex >> useNonTeXFonts;
668 } else if (token == "\\font_sc") {
669 lex >> fonts_expert_sc;
670 } else if (token == "\\font_osf") {
671 lex >> fonts_old_figures;
672 } else if (token == "\\font_sf_scale") {
673 lex >> fonts_sans_scale;
674 } else if (token == "\\font_tt_scale") {
675 lex >> fonts_typewriter_scale;
676 } else if (token == "\\font_cjk") {
678 } else if (token == "\\paragraph_separation") {
681 paragraph_separation = parseptranslator().find(parsep);
682 } else if (token == "\\paragraph_indentation") {
684 string indentation = lex.getString();
685 pimpl_->indentation = HSpace(indentation);
686 } else if (token == "\\defskip") {
688 string const defskip = lex.getString();
689 pimpl_->defskip = VSpace(defskip);
690 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
692 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
693 } else if (token == "\\quotes_language") {
696 quotes_language = quoteslangtranslator().find(quotes_lang);
697 } else if (token == "\\papersize") {
700 papersize = papersizetranslator().find(ppsize);
701 } else if (token == "\\use_geometry") {
703 } else if (token == "\\use_package") {
708 use_package(package, packagetranslator().find(use));
709 } else if (token == "\\cite_engine") {
711 vector<string> engine = getVectorFromString(lex.getString());
712 setCiteEngine(engine);
713 } else if (token == "\\cite_engine_type") {
716 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
717 } else if (token == "\\biblio_style") {
719 biblio_style = lex.getString();
720 } else if (token == "\\use_bibtopic") {
722 } else if (token == "\\use_indices") {
724 } else if (token == "\\tracking_changes") {
726 } else if (token == "\\output_changes") {
727 lex >> outputChanges;
728 } else if (token == "\\branch") {
730 docstring branch = lex.getDocString();
731 branchlist().add(branch);
734 string const tok = lex.getString();
735 if (tok == "\\end_branch")
737 Branch * branch_ptr = branchlist().find(branch);
738 if (tok == "\\selected") {
741 branch_ptr->setSelected(lex.getInteger());
743 if (tok == "\\filename_suffix") {
746 branch_ptr->setFileNameSuffix(lex.getInteger());
748 if (tok == "\\color") {
750 string color = lex.getString();
752 branch_ptr->setColor(color);
753 // Update also the Color table:
755 color = lcolor.getX11Name(Color_background);
757 lcolor.setColor(to_utf8(branch), color);
760 } else if (token == "\\index") {
762 docstring index = lex.getDocString();
764 indiceslist().add(index);
767 string const tok = lex.getString();
768 if (tok == "\\end_index")
770 Index * index_ptr = indiceslist().find(index);
771 if (tok == "\\shortcut") {
773 shortcut = lex.getDocString();
775 index_ptr->setShortcut(shortcut);
777 if (tok == "\\color") {
779 string color = lex.getString();
781 index_ptr->setColor(color);
782 // Update also the Color table:
784 color = lcolor.getX11Name(Color_background);
786 if (!shortcut.empty())
787 lcolor.setColor(to_utf8(shortcut), color);
790 } else if (token == "\\author") {
792 istringstream ss(lex.getString());
795 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
796 } else if (token == "\\paperorientation") {
799 orientation = paperorientationtranslator().find(orient);
800 } else if (token == "\\backgroundcolor") {
802 backgroundcolor = lyx::rgbFromHexName(lex.getString());
803 isbackgroundcolor = true;
804 } else if (token == "\\fontcolor") {
806 fontcolor = lyx::rgbFromHexName(lex.getString());
808 } else if (token == "\\notefontcolor") {
810 string color = lex.getString();
811 notefontcolor = lyx::rgbFromHexName(color);
812 } else if (token == "\\boxbgcolor") {
814 string color = lex.getString();
815 boxbgcolor = lyx::rgbFromHexName(color);
816 } else if (token == "\\paperwidth") {
818 } else if (token == "\\paperheight") {
820 } else if (token == "\\leftmargin") {
822 } else if (token == "\\topmargin") {
824 } else if (token == "\\rightmargin") {
826 } else if (token == "\\bottommargin") {
828 } else if (token == "\\headheight") {
830 } else if (token == "\\headsep") {
832 } else if (token == "\\footskip") {
834 } else if (token == "\\columnsep") {
836 } else if (token == "\\paperfontsize") {
838 } else if (token == "\\papercolumns") {
840 } else if (token == "\\listings_params") {
843 listings_params = InsetListingsParams(par).params();
844 } else if (token == "\\papersides") {
847 sides = sidestranslator().find(psides);
848 } else if (token == "\\paperpagestyle") {
850 } else if (token == "\\bullet") {
852 } else if (token == "\\bulletLaTeX") {
853 readBulletsLaTeX(lex);
854 } else if (token == "\\secnumdepth") {
856 } else if (token == "\\tocdepth") {
858 } else if (token == "\\spacing") {
862 if (nspacing == "other") {
865 spacing().set(spacetranslator().find(nspacing), tmp_val);
866 } else if (token == "\\float_placement") {
867 lex >> float_placement;
869 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
870 string toktmp = pdfoptions().readToken(lex, token);
871 if (!toktmp.empty()) {
872 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
876 } else if (token == "\\html_math_output") {
879 html_math_output = static_cast<MathOutput>(temp);
880 } else if (token == "\\html_be_strict") {
881 lex >> html_be_strict;
882 } else if (token == "\\html_css_as_file") {
883 lex >> html_css_as_file;
884 } else if (token == "\\html_math_img_scale") {
885 lex >> html_math_img_scale;
886 } else if (token == "\\html_latex_start") {
888 html_latex_start = lex.getString();
889 } else if (token == "\\html_latex_end") {
891 html_latex_end = lex.getString();
892 } else if (token == "\\output_sync") {
894 } else if (token == "\\output_sync_macro") {
895 lex >> output_sync_macro;
896 } else if (token == "\\use_refstyle") {
899 lyxerr << "BufferParams::readToken(): Unknown token: " <<
908 void BufferParams::writeFile(ostream & os) const
910 // The top of the file is written by the buffer.
911 // Prints out the buffer info into the .lyx file given by file
914 os << "\\textclass " << baseClass()->name() << '\n';
917 if (!preamble.empty()) {
918 // remove '\n' from the end of preamble
919 string const tmppreamble = rtrim(preamble, "\n");
920 os << "\\begin_preamble\n"
922 << "\n\\end_preamble\n";
926 if (!options.empty()) {
927 os << "\\options " << options << '\n';
930 // use the class options defined in the layout?
931 os << "\\use_default_options "
932 << convert<string>(use_default_options) << "\n";
934 // the master document
935 if (!master.empty()) {
936 os << "\\master " << master << '\n';
940 if (!removed_modules_.empty()) {
941 os << "\\begin_removed_modules" << '\n';
942 list<string>::const_iterator it = removed_modules_.begin();
943 list<string>::const_iterator en = removed_modules_.end();
944 for (; it != en; it++)
946 os << "\\end_removed_modules" << '\n';
950 if (!layout_modules_.empty()) {
951 os << "\\begin_modules" << '\n';
952 LayoutModuleList::const_iterator it = layout_modules_.begin();
953 LayoutModuleList::const_iterator en = layout_modules_.end();
954 for (; it != en; it++)
956 os << "\\end_modules" << '\n';
960 if (!included_children_.empty()) {
961 os << "\\begin_includeonly" << '\n';
962 list<string>::const_iterator it = included_children_.begin();
963 list<string>::const_iterator en = included_children_.end();
964 for (; it != en; it++)
966 os << "\\end_includeonly" << '\n';
968 os << "\\maintain_unincluded_children "
969 << convert<string>(maintain_unincluded_children) << '\n';
971 // local layout information
972 if (!local_layout.empty()) {
973 // remove '\n' from the end
974 string const tmplocal = rtrim(local_layout, "\n");
975 os << "\\begin_local_layout\n"
977 << "\n\\end_local_layout\n";
980 // then the text parameters
981 if (language != ignore_language)
982 os << "\\language " << language->lang() << '\n';
983 os << "\\language_package " << lang_package
984 << "\n\\inputencoding " << inputenc
985 << "\n\\fontencoding " << fontenc
986 << "\n\\font_roman " << fonts_roman
987 << "\n\\font_sans " << fonts_sans
988 << "\n\\font_typewriter " << fonts_typewriter
989 << "\n\\font_default_family " << fonts_default_family
990 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
991 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
992 << "\n\\font_osf " << convert<string>(fonts_old_figures)
993 << "\n\\font_sf_scale " << fonts_sans_scale
994 << "\n\\font_tt_scale " << fonts_typewriter_scale
996 if (!fonts_cjk.empty()) {
997 os << "\\font_cjk " << fonts_cjk << '\n';
999 os << "\n\\graphics " << graphics_driver << '\n';
1000 os << "\\default_output_format " << default_output_format << '\n';
1001 os << "\\output_sync " << output_sync << '\n';
1002 if (!output_sync_macro.empty())
1003 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1004 os << "\\bibtex_command " << bibtex_command << '\n';
1005 os << "\\index_command " << index_command << '\n';
1007 if (!float_placement.empty()) {
1008 os << "\\float_placement " << float_placement << '\n';
1010 os << "\\paperfontsize " << fontsize << '\n';
1012 spacing().writeFile(os);
1013 pdfoptions().writeFile(os);
1015 os << "\\papersize " << string_papersize[papersize]
1016 << "\n\\use_geometry " << convert<string>(use_geometry);
1017 vector<string> const & packages = auto_packages();
1018 for (size_t i = 0; i < packages.size(); ++i)
1019 os << "\n\\use_package " << packages[i] << ' '
1020 << use_package(packages[i]);
1022 os << "\n\\cite_engine ";
1024 if (!cite_engine_.empty()) {
1025 LayoutModuleList::const_iterator be = cite_engine_.begin();
1026 LayoutModuleList::const_iterator en = cite_engine_.end();
1027 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1036 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1037 << "\n\\biblio_style " << biblio_style
1038 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1039 << "\n\\use_indices " << convert<string>(use_indices)
1040 << "\n\\paperorientation " << string_orientation[orientation]
1041 << "\n\\suppress_date " << convert<string>(suppress_date)
1042 << "\n\\justification " << convert<string>(justification)
1043 << "\n\\use_refstyle " << use_refstyle
1045 if (isbackgroundcolor == true)
1046 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1047 if (isfontcolor == true)
1048 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1049 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1050 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1051 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1052 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1054 BranchList::const_iterator it = branchlist().begin();
1055 BranchList::const_iterator end = branchlist().end();
1056 for (; it != end; ++it) {
1057 os << "\\branch " << to_utf8(it->branch())
1058 << "\n\\selected " << it->isSelected()
1059 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1060 << "\n\\color " << lyx::X11hexname(it->color())
1065 IndicesList::const_iterator iit = indiceslist().begin();
1066 IndicesList::const_iterator iend = indiceslist().end();
1067 for (; iit != iend; ++iit) {
1068 os << "\\index " << to_utf8(iit->index())
1069 << "\n\\shortcut " << to_utf8(iit->shortcut())
1070 << "\n\\color " << lyx::X11hexname(iit->color())
1075 if (!paperwidth.empty())
1076 os << "\\paperwidth "
1077 << VSpace(paperwidth).asLyXCommand() << '\n';
1078 if (!paperheight.empty())
1079 os << "\\paperheight "
1080 << VSpace(paperheight).asLyXCommand() << '\n';
1081 if (!leftmargin.empty())
1082 os << "\\leftmargin "
1083 << VSpace(leftmargin).asLyXCommand() << '\n';
1084 if (!topmargin.empty())
1085 os << "\\topmargin "
1086 << VSpace(topmargin).asLyXCommand() << '\n';
1087 if (!rightmargin.empty())
1088 os << "\\rightmargin "
1089 << VSpace(rightmargin).asLyXCommand() << '\n';
1090 if (!bottommargin.empty())
1091 os << "\\bottommargin "
1092 << VSpace(bottommargin).asLyXCommand() << '\n';
1093 if (!headheight.empty())
1094 os << "\\headheight "
1095 << VSpace(headheight).asLyXCommand() << '\n';
1096 if (!headsep.empty())
1098 << VSpace(headsep).asLyXCommand() << '\n';
1099 if (!footskip.empty())
1101 << VSpace(footskip).asLyXCommand() << '\n';
1102 if (!columnsep.empty())
1103 os << "\\columnsep "
1104 << VSpace(columnsep).asLyXCommand() << '\n';
1105 os << "\\secnumdepth " << secnumdepth
1106 << "\n\\tocdepth " << tocdepth
1107 << "\n\\paragraph_separation "
1108 << string_paragraph_separation[paragraph_separation];
1109 if (!paragraph_separation)
1110 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1112 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1113 os << "\n\\quotes_language "
1114 << string_quotes_language[quotes_language]
1115 << "\n\\papercolumns " << columns
1116 << "\n\\papersides " << sides
1117 << "\n\\paperpagestyle " << pagestyle << '\n';
1118 if (!listings_params.empty())
1119 os << "\\listings_params \"" <<
1120 InsetListingsParams(listings_params).encodedString() << "\"\n";
1121 for (int i = 0; i < 4; ++i) {
1122 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1123 if (user_defined_bullet(i).getFont() != -1) {
1124 os << "\\bullet " << i << " "
1125 << user_defined_bullet(i).getFont() << " "
1126 << user_defined_bullet(i).getCharacter() << " "
1127 << user_defined_bullet(i).getSize() << "\n";
1131 os << "\\bulletLaTeX " << i << " \""
1132 << lyx::to_ascii(user_defined_bullet(i).getText())
1138 os << "\\tracking_changes " << convert<string>(trackChanges) << '\n'
1139 << "\\output_changes " << convert<string>(outputChanges) << '\n'
1140 << "\\html_math_output " << html_math_output << '\n'
1141 << "\\html_css_as_file " << html_css_as_file << '\n'
1142 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1144 if (html_math_img_scale != 1.0)
1145 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1146 if (!html_latex_start.empty())
1147 os << "\\html_latex_start " << html_latex_start << '\n';
1148 if (!html_latex_end.empty())
1149 os << "\\html_latex_end " << html_latex_end << '\n';
1151 os << pimpl_->authorlist;
1155 void BufferParams::validate(LaTeXFeatures & features) const
1157 features.require(documentClass().requires());
1159 if (outputChanges) {
1160 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1161 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1162 LaTeXFeatures::isAvailable("xcolor");
1164 switch (features.runparams().flavor) {
1165 case OutputParams::LATEX:
1166 case OutputParams::DVILUATEX:
1168 features.require("ct-dvipost");
1169 features.require("dvipost");
1170 } else if (xcolorulem) {
1171 features.require("ct-xcolor-ulem");
1172 features.require("ulem");
1173 features.require("xcolor");
1175 features.require("ct-none");
1178 case OutputParams::LUATEX:
1179 case OutputParams::PDFLATEX:
1180 case OutputParams::XETEX:
1182 features.require("ct-xcolor-ulem");
1183 features.require("ulem");
1184 features.require("xcolor");
1185 // improves color handling in PDF output
1186 features.require("pdfcolmk");
1188 features.require("ct-none");
1196 // Floats with 'Here definitely' as default setting.
1197 if (float_placement.find('H') != string::npos)
1198 features.require("float");
1200 for (PackageMap::const_iterator it = use_packages.begin();
1201 it != use_packages.end(); ++it) {
1202 if (it->first == "amsmath") {
1203 // AMS Style is at document level
1204 if (it->second == package_on ||
1205 documentClass().provides("amsmath"))
1206 features.require(it->first);
1207 } else if (it->second == package_on)
1208 features.require(it->first);
1211 // Document-level line spacing
1212 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1213 features.require("setspace");
1215 // the bullet shapes are buffer level not paragraph level
1216 // so they are tested here
1217 for (int i = 0; i < 4; ++i) {
1218 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1220 int const font = user_defined_bullet(i).getFont();
1222 int const c = user_defined_bullet(i).getCharacter();
1228 features.require("latexsym");
1230 } else if (font == 1) {
1231 features.require("amssymb");
1232 } else if (font >= 2 && font <= 5) {
1233 features.require("pifont");
1237 if (pdfoptions().use_hyperref) {
1238 features.require("hyperref");
1239 // due to interferences with babel and hyperref, the color package has to
1240 // be loaded after hyperref when hyperref is used with the colorlinks
1241 // option, see http://www.lyx.org/trac/ticket/5291
1242 if (pdfoptions().colorlinks)
1243 features.require("color");
1246 if (features.runparams().flavor == OutputParams::XETEX
1248 features.require("polyglossia");
1250 if (language->lang() == "vietnamese")
1251 features.require("vietnamese");
1252 else if (language->lang() == "japanese")
1253 features.require("japanese");
1257 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1258 FileName const & filepath) const
1260 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1261 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1262 // \RequirePackage to do so, rather than the normal \usepackage
1263 // Do not try to load any other package before the document class, unless you
1264 // have a thorough understanding of the LATEX internals and know exactly what you
1266 if (features.mustProvide("fix-cm"))
1267 os << "\\RequirePackage{fix-cm}\n";
1269 os << "\\documentclass";
1271 DocumentClass const & tclass = documentClass();
1273 ostringstream clsoptions; // the document class options.
1275 if (tokenPos(tclass.opt_fontsize(),
1276 '|', fontsize) >= 0) {
1277 // only write if existing in list (and not default)
1278 clsoptions << fontsize << "pt,";
1281 // all paper sizes except of A4, A5, B5 and the US sizes need the
1283 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1284 && papersize != PAPER_USLETTER
1285 && papersize != PAPER_USLEGAL
1286 && papersize != PAPER_USEXECUTIVE
1287 && papersize != PAPER_A4
1288 && papersize != PAPER_A5
1289 && papersize != PAPER_B5;
1291 if (!use_geometry) {
1292 switch (papersize) {
1294 clsoptions << "a4paper,";
1296 case PAPER_USLETTER:
1297 clsoptions << "letterpaper,";
1300 clsoptions << "a5paper,";
1303 clsoptions << "b5paper,";
1305 case PAPER_USEXECUTIVE:
1306 clsoptions << "executivepaper,";
1309 clsoptions << "legalpaper,";
1343 if (sides != tclass.sides()) {
1346 clsoptions << "oneside,";
1349 clsoptions << "twoside,";
1355 if (columns != tclass.columns()) {
1357 clsoptions << "twocolumn,";
1359 clsoptions << "onecolumn,";
1363 && orientation == ORIENTATION_LANDSCAPE)
1364 clsoptions << "landscape,";
1366 // language should be a parameter to \documentclass
1367 if (language->babel() == "hebrew"
1368 && default_language->babel() != "hebrew")
1369 // This seems necessary
1370 features.useLanguage(default_language);
1372 ostringstream language_options;
1373 bool const use_babel = features.useBabel() && !tclass.provides("babel");
1374 bool const use_polyglossia = features.usePolyglossia();
1375 bool const global = lyxrc.language_global_options;
1376 if (use_babel || (use_polyglossia && global)) {
1377 language_options << features.getLanguages();
1378 if (!language->babel().empty()) {
1379 if (!language_options.str().empty())
1380 language_options << ',';
1381 language_options << language->babel();
1383 if (global && !features.needBabelLangOptions())
1384 clsoptions << language_options.str() << ',';
1387 // the predefined options from the layout
1388 if (use_default_options && !tclass.options().empty())
1389 clsoptions << tclass.options() << ',';
1391 // the user-defined options
1392 if (!options.empty()) {
1393 clsoptions << options << ',';
1396 string strOptions(clsoptions.str());
1397 if (!strOptions.empty()) {
1398 strOptions = rtrim(strOptions, ",");
1400 os << '[' << from_utf8(strOptions) << ']';
1403 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1404 // end of \documentclass defs
1406 // if we use fontspec, we have to load the AMS packages here
1407 string const ams = features.loadAMSPackages();
1408 if (useNonTeXFonts && !ams.empty())
1409 os << from_ascii(ams);
1412 os << "\\usepackage{fontspec}\n";
1414 // font selection must be done before loading fontenc.sty
1415 string const fonts =
1416 loadFonts(fonts_roman, fonts_sans, fonts_typewriter,
1417 fonts_expert_sc, fonts_old_figures,
1418 fonts_sans_scale, fonts_typewriter_scale,
1419 useNonTeXFonts, features);
1421 os << from_utf8(fonts);
1423 if (fonts_default_family != "default")
1424 os << "\\renewcommand{\\familydefault}{\\"
1425 << from_ascii(fonts_default_family) << "}\n";
1427 // set font encoding
1428 // for arabic_arabi and farsi we also need to load the LAE and
1430 // XeTeX and LuaTeX (with OS fonts) work without fontenc
1431 if (font_encoding() != "default" && language->lang() != "japanese"
1432 && !useNonTeXFonts && !tclass.provides("fontenc")) {
1433 size_t fars = language_options.str().find("farsi");
1434 size_t arab = language_options.str().find("arabic");
1435 if (language->lang() == "arabic_arabi"
1436 || language->lang() == "farsi" || fars != string::npos
1437 || arab != string::npos) {
1438 os << "\\usepackage[" << from_ascii(font_encoding())
1439 << ",LFE,LAE]{fontenc}\n";
1441 os << "\\usepackage[" << from_ascii(font_encoding())
1446 // handle inputenc etc.
1447 writeEncodingPreamble(os, features);
1450 if (!features.runparams().includeall && !included_children_.empty()) {
1451 os << "\\includeonly{";
1452 list<string>::const_iterator it = included_children_.begin();
1453 list<string>::const_iterator en = included_children_.end();
1455 for (; it != en; ++it) {
1456 string incfile = *it;
1457 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1458 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1460 if (!features.runparams().nice)
1462 // \includeonly doesn't want an extension
1463 incfile = changeExtension(incfile, string());
1464 incfile = support::latex_path(incfile);
1465 if (!incfile.empty()) {
1468 os << from_utf8(incfile);
1475 if (!listings_params.empty() || features.isRequired("listings"))
1476 os << "\\usepackage{listings}\n";
1478 if (!listings_params.empty()) {
1480 // do not test validity because listings_params is
1481 // supposed to be valid
1483 InsetListingsParams(listings_params).separatedParams(true);
1484 // we can't support all packages, but we should load the color package
1485 if (par.find("\\color", 0) != string::npos)
1486 features.require("color");
1487 os << from_utf8(par)
1490 if (!tclass.provides("geometry")
1491 && (use_geometry || nonstandard_papersize)) {
1492 odocstringstream ods;
1493 if (!getGraphicsDriver("geometry").empty())
1494 ods << getGraphicsDriver("geometry");
1495 if (orientation == ORIENTATION_LANDSCAPE)
1496 ods << ",landscape";
1497 switch (papersize) {
1499 if (!paperwidth.empty())
1500 ods << ",paperwidth="
1501 << from_ascii(paperwidth);
1502 if (!paperheight.empty())
1503 ods << ",paperheight="
1504 << from_ascii(paperheight);
1506 case PAPER_USLETTER:
1507 ods << ",letterpaper";
1510 ods << ",legalpaper";
1512 case PAPER_USEXECUTIVE:
1513 ods << ",executivepaper";
1602 docstring const g_options = trim(ods.str(), ",");
1603 os << "\\usepackage";
1604 if (!g_options.empty())
1605 os << '[' << g_options << ']';
1606 os << "{geometry}\n";
1607 // output this only if use_geometry is true
1609 os << "\\geometry{verbose";
1610 if (!topmargin.empty())
1611 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1612 if (!bottommargin.empty())
1613 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1614 if (!leftmargin.empty())
1615 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1616 if (!rightmargin.empty())
1617 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1618 if (!headheight.empty())
1619 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1620 if (!headsep.empty())
1621 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1622 if (!footskip.empty())
1623 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1624 if (!columnsep.empty())
1625 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1628 } else if (orientation == ORIENTATION_LANDSCAPE
1629 || papersize != PAPER_DEFAULT) {
1630 features.require("papersize");
1633 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1634 if (pagestyle == "fancy")
1635 os << "\\usepackage{fancyhdr}\n";
1636 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1639 // only output when the background color is not default
1640 if (isbackgroundcolor == true) {
1641 // only require color here, the background color will be defined
1642 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1644 features.require("color");
1645 features.require("pagecolor");
1648 // only output when the font color is not default
1649 if (isfontcolor == true) {
1650 // only require color here, the font color will be defined
1651 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1653 features.require("color");
1654 features.require("fontcolor");
1657 // Only if class has a ToC hierarchy
1658 if (tclass.hasTocLevels()) {
1659 if (secnumdepth != tclass.secnumdepth()) {
1660 os << "\\setcounter{secnumdepth}{"
1664 if (tocdepth != tclass.tocdepth()) {
1665 os << "\\setcounter{tocdepth}{"
1671 if (paragraph_separation) {
1672 // when skip separation
1673 switch (getDefSkip().kind()) {
1674 case VSpace::SMALLSKIP:
1675 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1677 case VSpace::MEDSKIP:
1678 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1680 case VSpace::BIGSKIP:
1681 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1683 case VSpace::LENGTH:
1684 os << "\\setlength{\\parskip}{"
1685 << from_utf8(getDefSkip().length().asLatexString())
1688 default: // should never happen // Then delete it.
1689 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1692 os << "\\setlength{\\parindent}{0pt}\n";
1694 // when separation by indentation
1695 // only output something when a width is given
1696 if (getIndentation().asLyXCommand() != "default") {
1697 os << "\\setlength{\\parindent}{"
1698 << from_utf8(getIndentation().asLatexCommand())
1703 // Now insert the LyX specific LaTeX commands...
1704 docstring lyxpreamble;
1705 features.resolveAlternatives();
1708 if (!output_sync_macro.empty())
1709 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1710 else if (features.runparams().flavor == OutputParams::LATEX)
1711 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1712 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1713 lyxpreamble += "\\synctex=-1\n";
1716 // due to interferences with babel and hyperref, the color package has to
1717 // be loaded (when it is not already loaded) before babel when hyperref
1718 // is used with the colorlinks option, see
1719 // http://www.lyx.org/trac/ticket/5291
1720 // we decided therefore to load color always before babel, see
1721 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1722 lyxpreamble += from_ascii(features.getColorOptions());
1724 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1726 && (features.isRequired("jurabib")
1727 || features.isRequired("hyperref")
1728 || features.isRequired("vietnamese")
1729 || features.isRequired("japanese"))) {
1731 lyxpreamble += from_utf8(features.getBabelPresettings());
1732 lyxpreamble += from_utf8(babelCall(language_options.str(),
1733 features.needBabelLangOptions())) + '\n';
1734 lyxpreamble += from_utf8(features.getBabelPostsettings());
1737 // The optional packages;
1738 lyxpreamble += from_ascii(features.getPackages());
1740 // Additional Indices
1741 if (features.isRequired("splitidx")) {
1742 IndicesList::const_iterator iit = indiceslist().begin();
1743 IndicesList::const_iterator iend = indiceslist().end();
1744 for (; iit != iend; ++iit) {
1745 lyxpreamble += "\\newindex[";
1746 lyxpreamble += iit->index();
1747 lyxpreamble += "]{";
1748 lyxpreamble += iit->shortcut();
1749 lyxpreamble += "}\n";
1754 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1757 // * Hyperref manual: "Make sure it comes last of your loaded
1758 // packages, to give it a fighting chance of not being over-written,
1759 // since its job is to redefine many LaTeX commands."
1760 // * Email from Heiko Oberdiek: "It is usually better to load babel
1761 // before hyperref. Then hyperref has a chance to detect babel.
1762 // * Has to be loaded before the "LyX specific LaTeX commands" to
1763 // avoid errors with algorithm floats.
1764 // use hyperref explicitly if it is required
1765 if (features.isRequired("hyperref")) {
1766 // pass what we have to stream here, since we need
1767 // to access the stream itself in PDFOptions.
1770 OutputParams tmp_params = features.runparams();
1771 pdfoptions().writeLaTeX(tmp_params, os,
1772 documentClass().provides("hyperref"));
1773 // set back for the rest
1774 lyxpreamble.clear();
1775 // correctly break URLs with hyperref and dvi output
1776 if (features.runparams().flavor == OutputParams::LATEX
1777 && features.isAvailable("breakurl"))
1778 lyxpreamble += "\\usepackage{breakurl}\n";
1779 } else if (features.isRequired("nameref"))
1780 // hyperref loads this automatically
1781 lyxpreamble += "\\usepackage{nameref}\n";
1783 // Will be surrounded by \makeatletter and \makeatother when not empty
1784 docstring atlyxpreamble;
1786 // Some macros LyX will need
1787 docstring tmppreamble(features.getMacros());
1789 if (!tmppreamble.empty())
1790 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1791 "LyX specific LaTeX commands.\n"
1792 + tmppreamble + '\n';
1794 // the text class specific preamble
1795 tmppreamble = features.getTClassPreamble();
1796 if (!tmppreamble.empty())
1797 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1798 "Textclass specific LaTeX commands.\n"
1799 + tmppreamble + '\n';
1801 // suppress date if selected
1802 // use \@ifundefined because we cannot be sure that every document class
1803 // has a \date command
1805 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1807 /* the user-defined preamble */
1808 if (!containsOnly(preamble, " \n\t"))
1810 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1811 "User specified LaTeX commands.\n"
1812 + from_utf8(preamble) + '\n';
1814 // subfig loads internally the LaTeX package "caption". As
1815 // caption is a very popular package, users will load it in
1816 // the preamble. Therefore we must load subfig behind the
1817 // user-defined preamble and check if the caption package was
1818 // loaded or not. For the case that caption is loaded before
1819 // subfig, there is the subfig option "caption=false". This
1820 // option also works when a koma-script class is used and
1821 // koma's own caption commands are used instead of caption. We
1822 // use \PassOptionsToPackage here because the user could have
1823 // already loaded subfig in the preamble.
1824 if (features.isRequired("subfig")) {
1825 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1826 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1827 "\\usepackage{subfig}\n";
1830 // Itemize bullet settings need to be last in case the user
1831 // defines their own bullets that use a package included
1832 // in the user-defined preamble -- ARRae
1833 // Actually it has to be done much later than that
1834 // since some packages like frenchb make modifications
1835 // at \begin{document} time -- JMarc
1836 docstring bullets_def;
1837 for (int i = 0; i < 4; ++i) {
1838 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1839 if (bullets_def.empty())
1840 bullets_def += "\\AtBeginDocument{\n";
1841 bullets_def += " \\def\\labelitemi";
1843 // `i' is one less than the item to modify
1850 bullets_def += "ii";
1856 bullets_def += '{' +
1857 user_defined_bullet(i).getText()
1862 if (!bullets_def.empty())
1863 atlyxpreamble += bullets_def + "}\n\n";
1865 if (!atlyxpreamble.empty())
1866 lyxpreamble += "\n\\makeatletter\n"
1867 + atlyxpreamble + "\\makeatother\n\n";
1869 // We try to load babel late, in case it interferes with other packages.
1870 // Jurabib and Hyperref have to be called after babel, though.
1871 if (use_babel && !features.isRequired("jurabib")
1872 && !features.isRequired("hyperref")
1873 && !features.isRequired("vietnamese")
1874 && !features.isRequired("japanese")) {
1876 lyxpreamble += from_utf8(features.getBabelPresettings());
1877 lyxpreamble += from_utf8(babelCall(language_options.str(),
1878 features.needBabelLangOptions())) + '\n';
1879 lyxpreamble += from_utf8(features.getBabelPostsettings());
1882 // xunicode needs to be loaded at least after amsmath, amssymb,
1883 // esint and the other packages that provide special glyphs
1884 if (features.runparams().flavor == OutputParams::XETEX)
1885 lyxpreamble += "\\usepackage{xunicode}\n";
1887 // Polyglossia must be loaded last
1888 if (use_polyglossia) {
1890 lyxpreamble += "\\usepackage{polyglossia}\n";
1891 // set the main language
1892 lyxpreamble += "\\setdefaultlanguage";
1893 if (!language->polyglossiaOpts().empty())
1894 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
1895 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
1896 // now setup the other languages
1897 std::map<std::string, std::string> const polylangs =
1898 features.getPolyglossiaLanguages();
1899 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
1900 mit != polylangs.end() ; ++mit) {
1901 lyxpreamble += "\\setotherlanguage";
1902 if (!mit->second.empty())
1903 lyxpreamble += "[" + from_ascii(mit->second) + "]";
1904 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
1908 docstring const i18npreamble =
1909 features.getTClassI18nPreamble(use_babel, use_polyglossia);
1910 if (!i18npreamble.empty())
1911 lyxpreamble += i18npreamble + '\n';
1919 void BufferParams::useClassDefaults()
1921 DocumentClass const & tclass = documentClass();
1923 sides = tclass.sides();
1924 columns = tclass.columns();
1925 pagestyle = tclass.pagestyle();
1926 use_default_options = true;
1927 // Only if class has a ToC hierarchy
1928 if (tclass.hasTocLevels()) {
1929 secnumdepth = tclass.secnumdepth();
1930 tocdepth = tclass.tocdepth();
1935 bool BufferParams::hasClassDefaults() const
1937 DocumentClass const & tclass = documentClass();
1939 return sides == tclass.sides()
1940 && columns == tclass.columns()
1941 && pagestyle == tclass.pagestyle()
1942 && use_default_options
1943 && secnumdepth == tclass.secnumdepth()
1944 && tocdepth == tclass.tocdepth();
1948 DocumentClass const & BufferParams::documentClass() const
1954 DocumentClass const * BufferParams::documentClassPtr() const
1960 void BufferParams::setDocumentClass(DocumentClass const * const tc)
1962 // evil, but this function is evil
1963 doc_class_ = const_cast<DocumentClass *>(tc);
1967 bool BufferParams::setBaseClass(string const & classname)
1969 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1970 LayoutFileList & bcl = LayoutFileList::get();
1971 if (!bcl.haveClass(classname)) {
1973 bformat(_("The layout file:\n"
1975 "could not be found. A default textclass with default\n"
1976 "layouts will be used. LyX will not be able to produce\n"
1978 from_utf8(classname));
1979 frontend::Alert::error(_("Document class not found"), s);
1980 bcl.addEmptyClass(classname);
1983 bool const success = bcl[classname].load();
1986 bformat(_("Due to some error in it, the layout file:\n"
1988 "could not be loaded. A default textclass with default\n"
1989 "layouts will be used. LyX will not be able to produce\n"
1991 from_utf8(classname));
1992 frontend::Alert::error(_("Could not load class"), s);
1993 bcl.addEmptyClass(classname);
1996 pimpl_->baseClass_ = classname;
1997 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2002 LayoutFile const * BufferParams::baseClass() const
2004 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2005 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2011 LayoutFileIndex const & BufferParams::baseClassID() const
2013 return pimpl_->baseClass_;
2017 void BufferParams::makeDocumentClass()
2022 LayoutModuleList mods;
2023 LayoutModuleList::iterator it;
2024 LayoutModuleList::iterator en;
2026 it = layout_modules_.begin();
2027 en = layout_modules_.end();
2028 for (; it != en; it++)
2029 mods.push_back(*it);
2030 it = cite_engine_.begin();
2031 en = cite_engine_.end();
2032 for (; it != en; it++)
2033 mods.push_back(*it);
2034 doc_class_ = &(DocumentClassBundle::get().makeDocumentClass(*baseClass(), mods));
2036 if (!local_layout.empty()) {
2037 TextClass::ReturnValues success =
2038 doc_class_->read(local_layout, TextClass::MODULE);
2039 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2040 docstring const msg = _("Error reading internal layout information");
2041 frontend::Alert::warning(_("Read Error"), msg);
2047 bool BufferParams::moduleCanBeAdded(string const & modName) const
2049 return cite_engine_.moduleCanBeAdded(modName, baseClass()) &&
2050 layout_modules_.moduleCanBeAdded(modName, baseClass());
2054 bool BufferParams::addLayoutModule(string const & modName)
2056 LayoutModuleList::const_iterator it = layout_modules_.begin();
2057 LayoutModuleList::const_iterator end = layout_modules_.end();
2058 for (; it != end; it++)
2061 layout_modules_.push_back(modName);
2066 string BufferParams::bufferFormat() const
2068 string format = documentClass().outputFormat();
2069 if (format == "latex") {
2072 if (encoding().package() == Encoding::japanese)
2079 bool BufferParams::isExportable(string const & format) const
2081 vector<string> backs = backends();
2082 for (vector<string>::const_iterator it = backs.begin();
2083 it != backs.end(); ++it)
2084 if (theConverters().isReachable(*it, format))
2091 bool formatSorter(Format const * lhs, Format const * rhs) {
2092 return _(lhs->prettyname()) < _(rhs->prettyname());
2097 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2099 vector<string> const backs = backends();
2100 set<string> excludes;
2101 if (useNonTeXFonts) {
2102 excludes.insert("latex");
2103 excludes.insert("pdflatex");
2105 vector<Format const *> result =
2106 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2107 for (vector<string>::const_iterator it = backs.begin() + 1;
2108 it != backs.end(); ++it) {
2109 vector<Format const *> r =
2110 theConverters().getReachable(*it, only_viewable, false, excludes);
2111 result.insert(result.end(), r.begin(), r.end());
2113 sort(result.begin(), result.end(), formatSorter);
2118 bool BufferParams::isExportableFormat(string const & format) const
2120 typedef vector<Format const *> Formats;
2122 formats = exportableFormats(true);
2123 Formats::const_iterator fit = formats.begin();
2124 Formats::const_iterator end = formats.end();
2125 for (; fit != end ; ++fit) {
2126 if ((*fit)->name() == format)
2133 vector<string> BufferParams::backends() const
2136 v.push_back(bufferFormat());
2137 // FIXME: Don't hardcode format names here, but use a flag
2138 if (v.back() == "latex") {
2139 v.push_back("pdflatex");
2140 v.push_back("luatex");
2141 v.push_back("dviluatex");
2142 v.push_back("xetex");
2143 } else if (v.back() == "xetex") {
2144 v.push_back("luatex");
2145 v.push_back("dviluatex");
2147 v.push_back("xhtml");
2148 v.push_back("text");
2154 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
2156 string const dformat = (format.empty() || format == "default") ?
2157 getDefaultOutputFormat() : format;
2158 DefaultFlavorCache::const_iterator it =
2159 default_flavors_.find(dformat);
2161 if (it != default_flavors_.end())
2164 OutputParams::FLAVOR result = OutputParams::LATEX;
2166 if (dformat == "xhtml")
2167 result = OutputParams::HTML;
2169 // Try to determine flavor of default output format
2170 vector<string> backs = backends();
2171 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2172 // Get shortest path to format
2173 Graph::EdgePath path;
2174 for (vector<string>::const_iterator it = backs.begin();
2175 it != backs.end(); ++it) {
2176 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2177 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2182 result = theConverters().getFlavor(path);
2185 // cache this flavor
2186 default_flavors_[dformat] = result;
2191 string BufferParams::getDefaultOutputFormat() const
2193 if (!default_output_format.empty()
2194 && default_output_format != "default")
2195 return default_output_format;
2198 || encoding().package() == Encoding::japanese) {
2199 vector<Format const *> const formats = exportableFormats(true);
2200 if (formats.empty())
2202 // return the first we find
2203 return formats.front()->name();
2205 return lyxrc.default_view_format;
2208 Font const BufferParams::getFont() const
2210 FontInfo f = documentClass().defaultfont();
2211 if (fonts_default_family == "rmdefault")
2212 f.setFamily(ROMAN_FAMILY);
2213 else if (fonts_default_family == "sfdefault")
2214 f.setFamily(SANS_FAMILY);
2215 else if (fonts_default_family == "ttdefault")
2216 f.setFamily(TYPEWRITER_FAMILY);
2217 return Font(f, language);
2221 bool BufferParams::isLatex() const
2223 return documentClass().outputType() == LATEX;
2227 bool BufferParams::isLiterate() const
2229 return documentClass().outputType() == LITERATE;
2233 bool BufferParams::isDocBook() const
2235 return documentClass().outputType() == DOCBOOK;
2239 void BufferParams::readPreamble(Lexer & lex)
2241 if (lex.getString() != "\\begin_preamble")
2242 lyxerr << "Error (BufferParams::readPreamble):"
2243 "consistency check failed." << endl;
2245 preamble = lex.getLongString("\\end_preamble");
2249 void BufferParams::readLocalLayout(Lexer & lex)
2251 if (lex.getString() != "\\begin_local_layout")
2252 lyxerr << "Error (BufferParams::readLocalLayout):"
2253 "consistency check failed." << endl;
2255 local_layout = lex.getLongString("\\end_local_layout");
2259 bool BufferParams::setLanguage(string const & lang)
2261 Language const *new_language = languages.getLanguage(lang);
2262 if (!new_language) {
2263 // Language lang was not found
2266 language = new_language;
2271 void BufferParams::readLanguage(Lexer & lex)
2273 if (!lex.next()) return;
2275 string const tmptok = lex.getString();
2277 // check if tmptok is part of tex_babel in tex-defs.h
2278 if (!setLanguage(tmptok)) {
2279 // Language tmptok was not found
2280 language = default_language;
2281 lyxerr << "Warning: Setting language `"
2282 << tmptok << "' to `" << language->lang()
2288 void BufferParams::readGraphicsDriver(Lexer & lex)
2293 string const tmptok = lex.getString();
2294 // check if tmptok is part of tex_graphics in tex_defs.h
2297 string const test = tex_graphics[n++];
2299 if (test == tmptok) {
2300 graphics_driver = tmptok;
2305 "Warning: graphics driver `$$Token' not recognized!\n"
2306 " Setting graphics driver to `default'.\n");
2307 graphics_driver = "default";
2314 void BufferParams::readBullets(Lexer & lex)
2319 int const index = lex.getInteger();
2321 int temp_int = lex.getInteger();
2322 user_defined_bullet(index).setFont(temp_int);
2323 temp_bullet(index).setFont(temp_int);
2325 user_defined_bullet(index).setCharacter(temp_int);
2326 temp_bullet(index).setCharacter(temp_int);
2328 user_defined_bullet(index).setSize(temp_int);
2329 temp_bullet(index).setSize(temp_int);
2333 void BufferParams::readBulletsLaTeX(Lexer & lex)
2335 // The bullet class should be able to read this.
2338 int const index = lex.getInteger();
2340 docstring const temp_str = lex.getDocString();
2342 user_defined_bullet(index).setText(temp_str);
2343 temp_bullet(index).setText(temp_str);
2347 void BufferParams::readModules(Lexer & lex)
2349 if (!lex.eatLine()) {
2350 lyxerr << "Error (BufferParams::readModules):"
2351 "Unexpected end of input." << endl;
2355 string mod = lex.getString();
2356 if (mod == "\\end_modules")
2358 addLayoutModule(mod);
2364 void BufferParams::readRemovedModules(Lexer & lex)
2366 if (!lex.eatLine()) {
2367 lyxerr << "Error (BufferParams::readRemovedModules):"
2368 "Unexpected end of input." << endl;
2372 string mod = lex.getString();
2373 if (mod == "\\end_removed_modules")
2375 removed_modules_.push_back(mod);
2378 // now we want to remove any removed modules that were previously
2379 // added. normally, that will be because default modules were added in
2380 // setBaseClass(), which gets called when \textclass is read at the
2381 // start of the read.
2382 list<string>::const_iterator rit = removed_modules_.begin();
2383 list<string>::const_iterator const ren = removed_modules_.end();
2384 for (; rit != ren; rit++) {
2385 LayoutModuleList::iterator const mit = layout_modules_.begin();
2386 LayoutModuleList::iterator const men = layout_modules_.end();
2387 LayoutModuleList::iterator found = find(mit, men, *rit);
2390 layout_modules_.erase(found);
2395 void BufferParams::readIncludeonly(Lexer & lex)
2397 if (!lex.eatLine()) {
2398 lyxerr << "Error (BufferParams::readIncludeonly):"
2399 "Unexpected end of input." << endl;
2403 string child = lex.getString();
2404 if (child == "\\end_includeonly")
2406 included_children_.push_back(child);
2412 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2414 switch (papersize) {
2416 // could be anything, so don't guess
2418 case PAPER_CUSTOM: {
2419 if (purpose == XDVI && !paperwidth.empty() &&
2420 !paperheight.empty()) {
2421 // heightxwidth<unit>
2422 string first = paperwidth;
2423 string second = paperheight;
2424 if (orientation == ORIENTATION_LANDSCAPE)
2427 return first.erase(first.length() - 2)
2433 // dvips and dvipdfm do not know this
2434 if (purpose == DVIPS || purpose == DVIPDFM)
2438 if (purpose == DVIPS || purpose == DVIPDFM)
2442 if (purpose == DVIPS || purpose == DVIPDFM)
2452 if (purpose == DVIPS || purpose == DVIPDFM)
2456 if (purpose == DVIPS || purpose == DVIPDFM)
2460 if (purpose == DVIPS || purpose == DVIPDFM)
2464 if (purpose == DVIPS || purpose == DVIPDFM)
2468 if (purpose == DVIPS || purpose == DVIPDFM)
2472 // dvipdfm does not know this
2473 if (purpose == DVIPDFM)
2477 if (purpose == DVIPDFM)
2481 if (purpose == DVIPS || purpose == DVIPDFM)
2485 if (purpose == DVIPS || purpose == DVIPDFM)
2489 if (purpose == DVIPS || purpose == DVIPDFM)
2493 if (purpose == DVIPS || purpose == DVIPDFM)
2497 if (purpose == DVIPS || purpose == DVIPDFM)
2501 if (purpose == DVIPS || purpose == DVIPDFM)
2505 if (purpose == DVIPS || purpose == DVIPDFM)
2509 if (purpose == DVIPS || purpose == DVIPDFM)
2513 if (purpose == DVIPS || purpose == DVIPDFM)
2517 if (purpose == DVIPS || purpose == DVIPDFM)
2521 if (purpose == DVIPS || purpose == DVIPDFM)
2525 if (purpose == DVIPS || purpose == DVIPDFM)
2529 if (purpose == DVIPS || purpose == DVIPDFM)
2533 if (purpose == DVIPS || purpose == DVIPDFM)
2537 if (purpose == DVIPS || purpose == DVIPDFM)
2540 case PAPER_USEXECUTIVE:
2541 // dvipdfm does not know this
2542 if (purpose == DVIPDFM)
2547 case PAPER_USLETTER:
2549 if (purpose == XDVI)
2556 string const BufferParams::dvips_options() const
2560 // If the class loads the geometry package, we do not know which
2561 // paper size is used, since we do not set it (bug 7013).
2562 // Therefore we must not specify any argument here.
2563 // dvips gets the correct paper size via DVI specials in this case
2564 // (if the class uses the geometry package correctly).
2565 if (documentClass().provides("geometry"))
2569 && papersize == PAPER_CUSTOM
2570 && !lyxrc.print_paper_dimension_flag.empty()
2571 && !paperwidth.empty()
2572 && !paperheight.empty()) {
2573 // using a custom papersize
2574 result = lyxrc.print_paper_dimension_flag;
2575 result += ' ' + paperwidth;
2576 result += ',' + paperheight;
2578 string const paper_option = paperSizeName(DVIPS);
2579 if (!paper_option.empty() && (paper_option != "letter" ||
2580 orientation != ORIENTATION_LANDSCAPE)) {
2581 // dvips won't accept -t letter -t landscape.
2582 // In all other cases, include the paper size
2584 result = lyxrc.print_paper_flag;
2585 result += ' ' + paper_option;
2588 if (orientation == ORIENTATION_LANDSCAPE &&
2589 papersize != PAPER_CUSTOM)
2590 result += ' ' + lyxrc.print_landscape_flag;
2595 string const BufferParams::font_encoding() const
2597 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2601 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2603 if (lang_package != "auto" && lang_package != "babel"
2604 && lang_package != "default" && lang_package != "none")
2605 return lang_package;
2606 if (lyxrc.language_package_selection == LyXRC::LP_CUSTOM)
2607 return lyxrc.language_custom_package;
2608 // suppress the babel call if there is no BabelName defined
2609 // for the document language in the lib/languages file and if no
2610 // other languages are used (lang_opts is then empty)
2611 if (lang_opts.empty())
2613 // either a specific language (AsBabelOptions setting in
2614 // lib/languages) or the prefs require the languages to
2615 // be submitted to babel itself (not the class).
2617 return "\\usepackage[" + lang_opts + "]{babel}";
2618 return "\\usepackage{babel}";
2622 docstring BufferParams::getGraphicsDriver(string const & package) const
2626 if (package == "geometry") {
2627 if (graphics_driver == "dvips"
2628 || graphics_driver == "dvipdfm"
2629 || graphics_driver == "pdftex"
2630 || graphics_driver == "vtex")
2631 result = from_ascii(graphics_driver);
2632 else if (graphics_driver == "dvipdfmx")
2633 result = from_ascii("dvipdfm");
2640 void BufferParams::writeEncodingPreamble(otexstream & os,
2641 LaTeXFeatures & features) const
2643 // XeTeX does not need this
2644 if (features.runparams().flavor == OutputParams::XETEX)
2646 // LuaTeX neither, but with tex fonts, we need to load
2647 // the luainputenc package.
2648 if (features.runparams().flavor == OutputParams::LUATEX
2649 || features.runparams().flavor == OutputParams::DVILUATEX) {
2650 if (!useNonTeXFonts && inputenc != "default"
2651 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2652 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2653 os << "\\usepackage[utf8]{luainputenc}\n";
2657 if (inputenc == "auto") {
2658 string const doc_encoding =
2659 language->encoding()->latexName();
2660 Encoding::Package const package =
2661 language->encoding()->package();
2663 // Create a list with all the input encodings used
2665 set<string> encodings =
2666 features.getEncodingSet(doc_encoding);
2668 // If the "japanese" package (i.e. pLaTeX) is used,
2669 // inputenc must be omitted.
2670 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2671 if (package == Encoding::japanese)
2672 features.require("japanese");
2674 if ((!encodings.empty() || package == Encoding::inputenc)
2675 && !features.isRequired("japanese")) {
2676 os << "\\usepackage[";
2677 set<string>::const_iterator it = encodings.begin();
2678 set<string>::const_iterator const end = encodings.end();
2680 os << from_ascii(*it);
2683 for (; it != end; ++it)
2684 os << ',' << from_ascii(*it);
2685 if (package == Encoding::inputenc) {
2686 if (!encodings.empty())
2688 os << from_ascii(doc_encoding);
2690 os << "]{inputenc}\n";
2692 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2693 if (language->encoding()->name() == "utf8-cjk"
2694 && LaTeXFeatures::isAvailable("CJKutf8"))
2695 os << "\\usepackage{CJKutf8}\n";
2697 os << "\\usepackage{CJK}\n";
2699 } else if (inputenc != "default") {
2700 switch (encoding().package()) {
2701 case Encoding::none:
2702 case Encoding::japanese:
2704 case Encoding::inputenc:
2705 // do not load inputenc if japanese is used
2706 if (features.isRequired("japanese"))
2708 os << "\\usepackage[" << from_ascii(inputenc)
2712 if (encoding().name() == "utf8-cjk"
2713 && LaTeXFeatures::isAvailable("CJKutf8"))
2714 os << "\\usepackage{CJKutf8}\n";
2716 os << "\\usepackage{CJK}\n";
2721 // The encoding "armscii8" (for Armenian) is only available when
2722 // the package "armtex" is loaded.
2723 if (language->encoding()->latexName() == "armscii8"
2724 || inputenc == "armscii8")
2725 os << "\\usepackage{armtex}\n";
2729 string const BufferParams::parseFontName(string const & name) const
2731 string mangled = name;
2732 size_t const idx = mangled.find('[');
2733 if (idx == string::npos || idx == 0)
2736 return mangled.substr(0, idx - 1);
2740 string const BufferParams::loadFonts(string const & rm,
2741 string const & sf, string const & tt,
2742 bool const & sc, bool const & osf,
2743 int const & sfscale, int const & ttscale,
2744 bool const & use_systemfonts,
2745 LaTeXFeatures & features) const
2747 /* The LaTeX font world is in a flux. In the PSNFSS font interface,
2748 several packages have been replaced by others, that might not
2749 be installed on every system. We have to take care for that
2750 (see psnfss.pdf). We try to support all psnfss fonts as well
2751 as the fonts that have become de facto standard in the LaTeX
2752 world (e.g. Latin Modern). We do not support obsolete fonts
2753 (like PSLatex). In general, it should be possible to mix any
2754 rm font with any sf or tt font, respectively. (JSpitzm)
2756 -- separate math fonts.
2759 if (rm == "default" && sf == "default" && tt == "default")
2765 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
2766 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
2767 * Mapping=tex-text option assures TeX ligatures (such as "--")
2768 * are resolved. Note that tt does not use these ligatures.
2770 * -- add more GUI options?
2771 * -- add more fonts (fonts for other scripts)
2772 * -- if there's a way to find out if a font really supports
2773 * OldStyle, enable/disable the widget accordingly.
2775 if (use_systemfonts && features.isAvailable("fontspec")) {
2776 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
2777 // However, until v.2 (2010/07/11) fontspec only knew
2778 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
2779 // was introduced for both XeTeX and LuaTeX (LuaTeX
2780 // didn't understand "Mapping=tex-text", while XeTeX
2781 // understood both. With most recent versions, both
2782 // variants are understood by both engines. However,
2783 // we want to provide support for at least TeXLive 2009
2784 // (for XeTeX; LuaTeX is only supported as of v.2)
2785 string const texmapping =
2786 (features.runparams().flavor == OutputParams::XETEX) ?
2787 "Mapping=tex-text" : "Ligatures=TeX";
2788 if (rm != "default") {
2789 os << "\\setmainfont[" << texmapping;
2791 os << ",Numbers=OldStyle";
2792 os << "]{" << parseFontName(rm) << "}\n";
2794 if (sf != "default") {
2795 string const sans = parseFontName(sf);
2797 os << "\\setsansfont[Scale="
2798 << float(sfscale) / 100
2799 << "," << texmapping << "]{"
2802 os << "\\setsansfont[" << texmapping << "]{"
2805 if (tt != "default") {
2806 string const mono = parseFontName(tt);
2808 os << "\\setmonofont[Scale="
2809 << float(ttscale) / 100
2813 os << "\\setmonofont{"
2820 // Computer Modern (must be explicitly selectable -- there might be classes
2821 // that define a different default font!
2823 os << "\\renewcommand{\\rmdefault}{cmr}\n";
2824 // osf for Computer Modern needs eco.sty
2826 os << "\\usepackage{eco}\n";
2828 // Latin Modern Roman
2829 else if (rm == "lmodern")
2830 os << "\\usepackage{lmodern}\n";
2832 else if (rm == "ae") {
2833 // not needed when using OT1 font encoding.
2834 if (font_encoding() != "default")
2835 os << "\\usepackage{ae,aecompl}\n";
2838 else if (rm == "times") {
2839 // try to load the best available package
2840 if (LaTeXFeatures::isAvailable("mathptmx"))
2841 os << "\\usepackage{mathptmx}\n";
2842 else if (LaTeXFeatures::isAvailable("mathptm"))
2843 os << "\\usepackage{mathptm}\n";
2845 os << "\\usepackage{times}\n";
2848 else if (rm == "palatino") {
2849 // try to load the best available package
2850 if (LaTeXFeatures::isAvailable("mathpazo")) {
2851 os << "\\usepackage";
2857 // "osf" includes "sc"!
2861 os << "{mathpazo}\n";
2863 else if (LaTeXFeatures::isAvailable("mathpple"))
2864 os << "\\usepackage{mathpple}\n";
2866 os << "\\usepackage{palatino}\n";
2869 else if (rm == "utopia") {
2870 // fourier supersedes utopia.sty, but does
2871 // not work with OT1 encoding.
2872 if (LaTeXFeatures::isAvailable("fourier")
2873 && font_encoding() != "default") {
2874 os << "\\usepackage";
2885 os << "{fourier}\n";
2888 os << "\\usepackage{utopia}\n";
2890 // Bera (complete fontset)
2891 else if (rm == "bera" && sf == "default" && tt == "default")
2892 os << "\\usepackage{bera}\n";
2894 else if (rm != "default")
2895 os << "\\usepackage" << "{" << rm << "}\n";
2898 // Helvetica, Bera Sans
2899 if (sf == "helvet" || sf == "berasans") {
2901 os << "\\usepackage[scaled=" << float(sfscale) / 100
2902 << "]{" << sf << "}\n";
2904 os << "\\usepackage{" << sf << "}\n";
2907 else if (sf == "avant")
2908 os << "\\usepackage{" << sf << "}\n";
2909 // Computer Modern, Latin Modern, CM Bright
2910 else if (sf != "default")
2911 os << "\\renewcommand{\\sfdefault}{" << sf << "}\n";
2913 // monospaced/typewriter
2914 // Courier, LuxiMono
2915 if (tt == "luximono" || tt == "beramono") {
2917 os << "\\usepackage[scaled=" << float(ttscale) / 100
2918 << "]{" << tt << "}\n";
2920 os << "\\usepackage{" << tt << "}\n";
2923 else if (tt == "courier" )
2924 os << "\\usepackage{" << tt << "}\n";
2925 // Computer Modern, Latin Modern, CM Bright
2926 else if (tt != "default")
2927 os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
2933 Encoding const & BufferParams::encoding() const
2935 // FIXME: actually, we should check for the flavor
2936 // or runparams.isFullyUnicode() here:
2937 // This check will not work with XeTeX/LuaTeX and tex fonts.
2938 // Thus we have to reset the encoding in Buffer::makeLaTeXFile.
2940 return *(encodings.fromLaTeXName("utf8-plain"));
2941 if (inputenc == "auto" || inputenc == "default")
2942 return *language->encoding();
2943 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2946 LYXERR0("Unknown inputenc value `" << inputenc
2947 << "'. Using `auto' instead.");
2948 return *language->encoding();
2952 bool BufferParams::addCiteEngine(string const & engine)
2954 LayoutModuleList::const_iterator it = cite_engine_.begin();
2955 LayoutModuleList::const_iterator en = cite_engine_.end();
2956 for (; it != en; ++it)
2959 cite_engine_.push_back(engine);
2964 bool BufferParams::addCiteEngine(vector<string> const & engine)
2966 vector<string>::const_iterator it = engine.begin();
2967 vector<string>::const_iterator en = engine.end();
2969 for (; it != en; ++it)
2970 if (!addCiteEngine(*it))
2976 string const & BufferParams::defaultBiblioStyle() const
2978 return documentClass().defaultBiblioStyle();
2982 bool const & BufferParams::fullAuthorList() const
2984 return documentClass().fullAuthorList();
2988 void BufferParams::setCiteEngine(string const & engine)
2991 addCiteEngine(engine);
2995 void BufferParams::setCiteEngine(vector<string> const & engine)
2998 addCiteEngine(engine);
3002 vector<string> BufferParams::citeCommands() const
3004 static CitationStyle const default_style;
3005 vector<string> commands =
3006 documentClass().citeCommands(citeEngineType());
3007 if (commands.empty())
3008 commands.push_back(default_style.cmd);
3013 vector<CitationStyle> BufferParams::citeStyles() const
3015 static CitationStyle const default_style;
3016 vector<CitationStyle> styles =
3017 documentClass().citeStyles(citeEngineType());
3019 styles.push_back(default_style);