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 "LaTeXFonts.h"
34 #include "ModuleList.h"
38 #include "OutputParams.h"
42 #include "PDFOptions.h"
44 #include "frontends/alert.h"
46 #include "insets/InsetListingsParams.h"
48 #include "support/convert.h"
49 #include "support/debug.h"
50 #include "support/docstream.h"
51 #include "support/FileName.h"
52 #include "support/filetools.h"
53 #include "support/gettext.h"
54 #include "support/Messages.h"
55 #include "support/Translator.h"
56 #include "support/lstrings.h"
62 using namespace lyx::support;
65 static char const * const string_paragraph_separation[] = {
70 static char const * const string_quotes_language[] = {
71 "english", "swedish", "german", "polish", "french", "danish", ""
75 static char const * const string_papersize[] = {
76 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
77 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
78 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
79 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
80 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
85 static char const * const string_orientation[] = {
86 "portrait", "landscape", ""
90 static char const * const string_footnotekinds[] = {
91 "footnote", "margin", "fig", "tab", "alg", "wide-fig", "wide-tab", ""
95 static char const * const tex_graphics[] = {
96 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
97 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
98 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
99 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
110 // Paragraph separation
111 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
114 ParSepTranslator const init_parseptranslator()
116 ParSepTranslator translator
117 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
118 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
123 ParSepTranslator const & parseptranslator()
125 static ParSepTranslator translator = init_parseptranslator();
131 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
134 QuotesLangTranslator const init_quoteslangtranslator()
136 QuotesLangTranslator translator
137 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
138 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
139 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
140 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
141 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
142 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
147 QuotesLangTranslator const & quoteslangtranslator()
149 static QuotesLangTranslator translator = init_quoteslangtranslator();
155 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
158 static PaperSizeTranslator initPaperSizeTranslator()
160 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
161 translator.addPair(string_papersize[1], PAPER_CUSTOM);
162 translator.addPair(string_papersize[2], PAPER_USLETTER);
163 translator.addPair(string_papersize[3], PAPER_USLEGAL);
164 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
165 translator.addPair(string_papersize[5], PAPER_A0);
166 translator.addPair(string_papersize[6], PAPER_A1);
167 translator.addPair(string_papersize[7], PAPER_A2);
168 translator.addPair(string_papersize[8], PAPER_A3);
169 translator.addPair(string_papersize[9], PAPER_A4);
170 translator.addPair(string_papersize[10], PAPER_A5);
171 translator.addPair(string_papersize[11], PAPER_A6);
172 translator.addPair(string_papersize[12], PAPER_B0);
173 translator.addPair(string_papersize[13], PAPER_B1);
174 translator.addPair(string_papersize[14], PAPER_B2);
175 translator.addPair(string_papersize[15], PAPER_B3);
176 translator.addPair(string_papersize[16], PAPER_B4);
177 translator.addPair(string_papersize[17], PAPER_B5);
178 translator.addPair(string_papersize[18], PAPER_B6);
179 translator.addPair(string_papersize[19], PAPER_C0);
180 translator.addPair(string_papersize[20], PAPER_C1);
181 translator.addPair(string_papersize[21], PAPER_C2);
182 translator.addPair(string_papersize[22], PAPER_C3);
183 translator.addPair(string_papersize[23], PAPER_C4);
184 translator.addPair(string_papersize[24], PAPER_C5);
185 translator.addPair(string_papersize[25], PAPER_C6);
186 translator.addPair(string_papersize[26], PAPER_JISB0);
187 translator.addPair(string_papersize[27], PAPER_JISB1);
188 translator.addPair(string_papersize[28], PAPER_JISB2);
189 translator.addPair(string_papersize[29], PAPER_JISB3);
190 translator.addPair(string_papersize[30], PAPER_JISB4);
191 translator.addPair(string_papersize[31], PAPER_JISB5);
192 translator.addPair(string_papersize[32], PAPER_JISB6);
197 PaperSizeTranslator const & papersizetranslator()
199 static PaperSizeTranslator translator = initPaperSizeTranslator();
205 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
208 PaperOrientationTranslator const init_paperorientationtranslator()
210 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
211 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
216 PaperOrientationTranslator const & paperorientationtranslator()
218 static PaperOrientationTranslator translator = init_paperorientationtranslator();
224 typedef Translator<int, PageSides> SidesTranslator;
227 SidesTranslator const init_sidestranslator()
229 SidesTranslator translator(1, OneSide);
230 translator.addPair(2, TwoSides);
235 SidesTranslator const & sidestranslator()
237 static SidesTranslator translator = init_sidestranslator();
243 typedef Translator<int, BufferParams::Package> PackageTranslator;
246 PackageTranslator const init_packagetranslator()
248 PackageTranslator translator(0, BufferParams::package_off);
249 translator.addPair(1, BufferParams::package_auto);
250 translator.addPair(2, BufferParams::package_on);
255 PackageTranslator const & packagetranslator()
257 static PackageTranslator translator = init_packagetranslator();
263 typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
266 CiteEngineTypeTranslator const init_citeenginetypetranslator()
268 CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
269 translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
274 CiteEngineTypeTranslator const & citeenginetypetranslator()
276 static CiteEngineTypeTranslator translator = init_citeenginetypetranslator();
282 typedef Translator<string, Spacing::Space> SpaceTranslator;
285 SpaceTranslator const init_spacetranslator()
287 SpaceTranslator translator("default", Spacing::Default);
288 translator.addPair("single", Spacing::Single);
289 translator.addPair("onehalf", Spacing::Onehalf);
290 translator.addPair("double", Spacing::Double);
291 translator.addPair("other", Spacing::Other);
296 SpaceTranslator const & spacetranslator()
298 static SpaceTranslator translator = init_spacetranslator();
305 class BufferParams::Impl
310 AuthorList authorlist;
311 BranchList branchlist;
312 Bullet temp_bullets[4];
313 Bullet user_defined_bullets[4];
314 IndicesList indiceslist;
316 /** This is the amount of space used for paragraph_separation "skip",
317 * and for detached paragraphs in "indented" documents.
321 PDFOptions pdfoptions;
322 LayoutFileIndex baseClass_;
326 BufferParams::Impl::Impl()
327 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
329 // set initial author
331 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
336 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
340 return new BufferParams::Impl(*ptr);
344 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
350 BufferParams::BufferParams()
353 setBaseClass(defaultBaseclass());
355 paragraph_separation = ParagraphIndentSeparation;
356 quotes_language = InsetQuotes::EnglishQuotes;
357 fontsize = "default";
360 papersize = PAPER_DEFAULT;
361 orientation = ORIENTATION_PORTRAIT;
362 use_geometry = false;
363 cite_engine_.push_back("basic");
364 cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
365 biblio_style = "plain";
366 use_bibtopic = false;
368 trackChanges = false;
369 outputChanges = false;
370 use_default_options = true;
371 maintain_unincluded_children = false;
374 language = default_language;
376 fonts_roman = "default";
377 fonts_sans = "default";
378 fonts_typewriter = "default";
379 fonts_default_family = "default";
380 useNonTeXFonts = false;
381 fonts_expert_sc = false;
382 fonts_old_figures = false;
383 fonts_sans_scale = 100;
384 fonts_typewriter_scale = 100;
386 lang_package = "default";
387 graphics_driver = "default";
388 default_output_format = "default";
389 bibtex_command = "default";
390 index_command = "default";
393 listings_params = string();
394 pagestyle = "default";
395 suppress_date = false;
396 justification = true;
397 // no color is the default (white)
398 backgroundcolor = lyx::rgbFromHexName("#ffffff");
399 isbackgroundcolor = false;
400 // no color is the default (black)
401 fontcolor = lyx::rgbFromHexName("#000000");
403 // light gray is the default font color for greyed-out notes
404 notefontcolor = lyx::rgbFromHexName("#cccccc");
405 boxbgcolor = lyx::rgbFromHexName("#ff0000");
406 compressed = lyxrc.save_compressed;
407 for (int iter = 0; iter < 4; ++iter) {
408 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
409 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
412 indiceslist().addDefault(B_("Index"));
413 html_be_strict = false;
414 html_math_output = MathML;
415 html_math_img_scale = 1.0;
416 html_css_as_file = false;
423 docstring BufferParams::B_(string const & l10n) const
425 LASSERT(language, /**/);
426 return getMessages(language->code()).get(l10n);
430 BufferParams::Package BufferParams::use_package(std::string const & p) const
432 PackageMap::const_iterator it = use_packages.find(p);
433 if (it == use_packages.end())
439 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
445 vector<string> const & BufferParams::auto_packages()
447 static vector<string> packages;
448 if (packages.empty()) {
449 // adding a package here implies a file format change!
450 packages.push_back("amsmath");
451 packages.push_back("amssymb");
452 packages.push_back("esint");
453 packages.push_back("mathdots");
454 packages.push_back("mathtools");
455 packages.push_back("mhchem");
456 packages.push_back("undertilde");
462 AuthorList & BufferParams::authors()
464 return pimpl_->authorlist;
468 AuthorList const & BufferParams::authors() const
470 return pimpl_->authorlist;
474 BranchList & BufferParams::branchlist()
476 return pimpl_->branchlist;
480 BranchList const & BufferParams::branchlist() const
482 return pimpl_->branchlist;
486 IndicesList & BufferParams::indiceslist()
488 return pimpl_->indiceslist;
492 IndicesList const & BufferParams::indiceslist() const
494 return pimpl_->indiceslist;
498 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
500 LASSERT(index < 4, /**/);
501 return pimpl_->temp_bullets[index];
505 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
507 LASSERT(index < 4, /**/);
508 return pimpl_->temp_bullets[index];
512 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
514 LASSERT(index < 4, /**/);
515 return pimpl_->user_defined_bullets[index];
519 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
521 LASSERT(index < 4, /**/);
522 return pimpl_->user_defined_bullets[index];
526 Spacing & BufferParams::spacing()
528 return pimpl_->spacing;
532 Spacing const & BufferParams::spacing() const
534 return pimpl_->spacing;
538 PDFOptions & BufferParams::pdfoptions()
540 return pimpl_->pdfoptions;
544 PDFOptions const & BufferParams::pdfoptions() const
546 return pimpl_->pdfoptions;
550 HSpace const & BufferParams::getIndentation() const
552 return pimpl_->indentation;
556 void BufferParams::setIndentation(HSpace const & indent)
558 pimpl_->indentation = indent;
562 VSpace const & BufferParams::getDefSkip() const
564 return pimpl_->defskip;
568 void BufferParams::setDefSkip(VSpace const & vs)
570 // DEFSKIP will cause an infinite loop
571 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
572 pimpl_->defskip = vs;
576 string BufferParams::readToken(Lexer & lex, string const & token,
577 FileName const & filepath)
579 if (token == "\\textclass") {
581 string const classname = lex.getString();
582 // if there exists a local layout file, ignore the system one
583 // NOTE: in this case, the textclass (.cls file) is assumed to
586 LayoutFileList & bcl = LayoutFileList::get();
587 if (tcp.empty() && !filepath.empty())
588 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
592 setBaseClass(classname);
593 // We assume that a tex class exists for local or unknown
594 // layouts so this warning, will only be given for system layouts.
595 if (!baseClass()->isTeXClassAvailable()) {
596 docstring const desc =
597 translateIfPossible(from_utf8(baseClass()->description()));
598 docstring const prereqs =
599 from_utf8(baseClass()->prerequisites());
600 docstring const msg =
601 bformat(_("The selected document class\n"
603 "requires external files that are not available.\n"
604 "The document class can still be used, but the\n"
605 "document cannot be compiled until the following\n"
606 "prerequisites are installed:\n"
608 "See section 3.1.2.2 (Class Availability) of the\n"
609 "User's Guide for more information."), desc, prereqs);
610 frontend::Alert::warning(_("Document class not available"),
613 } else if (token == "\\begin_preamble") {
615 } else if (token == "\\begin_local_layout") {
616 readLocalLayout(lex);
617 } else if (token == "\\begin_modules") {
619 } else if (token == "\\begin_removed_modules") {
620 readRemovedModules(lex);
621 } else if (token == "\\begin_includeonly") {
622 readIncludeonly(lex);
623 } else if (token == "\\maintain_unincluded_children") {
624 lex >> maintain_unincluded_children;
625 } else if (token == "\\options") {
627 options = lex.getString();
628 } else if (token == "\\use_default_options") {
629 lex >> use_default_options;
630 } else if (token == "\\master") {
632 master = lex.getString();
633 } else if (token == "\\suppress_date") {
634 lex >> suppress_date;
635 } else if (token == "\\justification") {
636 lex >> justification;
637 } else if (token == "\\language") {
639 } else if (token == "\\language_package") {
641 lang_package = lex.getString();
642 } else if (token == "\\inputencoding") {
644 } else if (token == "\\graphics") {
645 readGraphicsDriver(lex);
646 } else if (token == "\\default_output_format") {
647 lex >> default_output_format;
648 } else if (token == "\\bibtex_command") {
650 bibtex_command = lex.getString();
651 } else if (token == "\\index_command") {
653 index_command = lex.getString();
654 } else if (token == "\\fontencoding") {
656 fontenc = lex.getString();
657 } else if (token == "\\font_roman") {
659 fonts_roman = lex.getString();
660 } else if (token == "\\font_sans") {
662 fonts_sans = lex.getString();
663 } else if (token == "\\font_typewriter") {
665 fonts_typewriter = lex.getString();
666 } else if (token == "\\font_default_family") {
667 lex >> fonts_default_family;
668 } else if (token == "\\use_non_tex_fonts") {
669 lex >> useNonTeXFonts;
670 } else if (token == "\\font_sc") {
671 lex >> fonts_expert_sc;
672 } else if (token == "\\font_osf") {
673 lex >> fonts_old_figures;
674 } else if (token == "\\font_sf_scale") {
675 lex >> fonts_sans_scale;
676 } else if (token == "\\font_tt_scale") {
677 lex >> fonts_typewriter_scale;
678 } else if (token == "\\font_cjk") {
680 } else if (token == "\\paragraph_separation") {
683 paragraph_separation = parseptranslator().find(parsep);
684 } else if (token == "\\paragraph_indentation") {
686 string indentation = lex.getString();
687 pimpl_->indentation = HSpace(indentation);
688 } else if (token == "\\defskip") {
690 string const defskip = lex.getString();
691 pimpl_->defskip = VSpace(defskip);
692 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
694 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
695 } else if (token == "\\quotes_language") {
698 quotes_language = quoteslangtranslator().find(quotes_lang);
699 } else if (token == "\\papersize") {
702 papersize = papersizetranslator().find(ppsize);
703 } else if (token == "\\use_geometry") {
705 } else if (token == "\\use_package") {
710 use_package(package, packagetranslator().find(use));
711 } else if (token == "\\cite_engine") {
713 vector<string> engine = getVectorFromString(lex.getString());
714 setCiteEngine(engine);
715 } else if (token == "\\cite_engine_type") {
718 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
719 } else if (token == "\\biblio_style") {
721 biblio_style = lex.getString();
722 } else if (token == "\\use_bibtopic") {
724 } else if (token == "\\use_indices") {
726 } else if (token == "\\tracking_changes") {
728 } else if (token == "\\output_changes") {
729 lex >> outputChanges;
730 } else if (token == "\\branch") {
732 docstring branch = lex.getDocString();
733 branchlist().add(branch);
736 string const tok = lex.getString();
737 if (tok == "\\end_branch")
739 Branch * branch_ptr = branchlist().find(branch);
740 if (tok == "\\selected") {
743 branch_ptr->setSelected(lex.getInteger());
745 if (tok == "\\filename_suffix") {
748 branch_ptr->setFileNameSuffix(lex.getInteger());
750 if (tok == "\\color") {
752 string color = lex.getString();
754 branch_ptr->setColor(color);
755 // Update also the Color table:
757 color = lcolor.getX11Name(Color_background);
759 lcolor.setColor(to_utf8(branch), color);
762 } else if (token == "\\index") {
764 docstring index = lex.getDocString();
766 indiceslist().add(index);
769 string const tok = lex.getString();
770 if (tok == "\\end_index")
772 Index * index_ptr = indiceslist().find(index);
773 if (tok == "\\shortcut") {
775 shortcut = lex.getDocString();
777 index_ptr->setShortcut(shortcut);
779 if (tok == "\\color") {
781 string color = lex.getString();
783 index_ptr->setColor(color);
784 // Update also the Color table:
786 color = lcolor.getX11Name(Color_background);
788 if (!shortcut.empty())
789 lcolor.setColor(to_utf8(shortcut), color);
792 } else if (token == "\\author") {
794 istringstream ss(lex.getString());
797 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
798 } else if (token == "\\paperorientation") {
801 orientation = paperorientationtranslator().find(orient);
802 } else if (token == "\\backgroundcolor") {
804 backgroundcolor = lyx::rgbFromHexName(lex.getString());
805 isbackgroundcolor = true;
806 } else if (token == "\\fontcolor") {
808 fontcolor = lyx::rgbFromHexName(lex.getString());
810 } else if (token == "\\notefontcolor") {
812 string color = lex.getString();
813 notefontcolor = lyx::rgbFromHexName(color);
814 } else if (token == "\\boxbgcolor") {
816 string color = lex.getString();
817 boxbgcolor = lyx::rgbFromHexName(color);
818 } else if (token == "\\paperwidth") {
820 } else if (token == "\\paperheight") {
822 } else if (token == "\\leftmargin") {
824 } else if (token == "\\topmargin") {
826 } else if (token == "\\rightmargin") {
828 } else if (token == "\\bottommargin") {
830 } else if (token == "\\headheight") {
832 } else if (token == "\\headsep") {
834 } else if (token == "\\footskip") {
836 } else if (token == "\\columnsep") {
838 } else if (token == "\\paperfontsize") {
840 } else if (token == "\\papercolumns") {
842 } else if (token == "\\listings_params") {
845 listings_params = InsetListingsParams(par).params();
846 } else if (token == "\\papersides") {
849 sides = sidestranslator().find(psides);
850 } else if (token == "\\paperpagestyle") {
852 } else if (token == "\\bullet") {
854 } else if (token == "\\bulletLaTeX") {
855 readBulletsLaTeX(lex);
856 } else if (token == "\\secnumdepth") {
858 } else if (token == "\\tocdepth") {
860 } else if (token == "\\spacing") {
864 if (nspacing == "other") {
867 spacing().set(spacetranslator().find(nspacing), tmp_val);
868 } else if (token == "\\float_placement") {
869 lex >> float_placement;
871 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
872 string toktmp = pdfoptions().readToken(lex, token);
873 if (!toktmp.empty()) {
874 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
878 } else if (token == "\\html_math_output") {
881 html_math_output = static_cast<MathOutput>(temp);
882 } else if (token == "\\html_be_strict") {
883 lex >> html_be_strict;
884 } else if (token == "\\html_css_as_file") {
885 lex >> html_css_as_file;
886 } else if (token == "\\html_math_img_scale") {
887 lex >> html_math_img_scale;
888 } else if (token == "\\html_latex_start") {
890 html_latex_start = lex.getString();
891 } else if (token == "\\html_latex_end") {
893 html_latex_end = lex.getString();
894 } else if (token == "\\output_sync") {
896 } else if (token == "\\output_sync_macro") {
897 lex >> output_sync_macro;
898 } else if (token == "\\use_refstyle") {
901 lyxerr << "BufferParams::readToken(): Unknown token: " <<
910 void BufferParams::writeFile(ostream & os) const
912 // The top of the file is written by the buffer.
913 // Prints out the buffer info into the .lyx file given by file
916 os << "\\textclass " << baseClass()->name() << '\n';
919 if (!preamble.empty()) {
920 // remove '\n' from the end of preamble
921 string const tmppreamble = rtrim(preamble, "\n");
922 os << "\\begin_preamble\n"
924 << "\n\\end_preamble\n";
928 if (!options.empty()) {
929 os << "\\options " << options << '\n';
932 // use the class options defined in the layout?
933 os << "\\use_default_options "
934 << convert<string>(use_default_options) << "\n";
936 // the master document
937 if (!master.empty()) {
938 os << "\\master " << master << '\n';
942 if (!removed_modules_.empty()) {
943 os << "\\begin_removed_modules" << '\n';
944 list<string>::const_iterator it = removed_modules_.begin();
945 list<string>::const_iterator en = removed_modules_.end();
946 for (; it != en; ++it)
948 os << "\\end_removed_modules" << '\n';
952 if (!layout_modules_.empty()) {
953 os << "\\begin_modules" << '\n';
954 LayoutModuleList::const_iterator it = layout_modules_.begin();
955 LayoutModuleList::const_iterator en = layout_modules_.end();
956 for (; it != en; ++it)
958 os << "\\end_modules" << '\n';
962 if (!included_children_.empty()) {
963 os << "\\begin_includeonly" << '\n';
964 list<string>::const_iterator it = included_children_.begin();
965 list<string>::const_iterator en = included_children_.end();
966 for (; it != en; ++it)
968 os << "\\end_includeonly" << '\n';
970 os << "\\maintain_unincluded_children "
971 << convert<string>(maintain_unincluded_children) << '\n';
973 // local layout information
974 if (!local_layout.empty()) {
975 // remove '\n' from the end
976 string const tmplocal = rtrim(local_layout, "\n");
977 os << "\\begin_local_layout\n"
979 << "\n\\end_local_layout\n";
982 // then the text parameters
983 if (language != ignore_language)
984 os << "\\language " << language->lang() << '\n';
985 os << "\\language_package " << lang_package
986 << "\n\\inputencoding " << inputenc
987 << "\n\\fontencoding " << fontenc
988 << "\n\\font_roman " << fonts_roman
989 << "\n\\font_sans " << fonts_sans
990 << "\n\\font_typewriter " << fonts_typewriter
991 << "\n\\font_default_family " << fonts_default_family
992 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
993 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
994 << "\n\\font_osf " << convert<string>(fonts_old_figures)
995 << "\n\\font_sf_scale " << fonts_sans_scale
996 << "\n\\font_tt_scale " << fonts_typewriter_scale
998 if (!fonts_cjk.empty()) {
999 os << "\\font_cjk " << fonts_cjk << '\n';
1001 os << "\\graphics " << graphics_driver << '\n';
1002 os << "\\default_output_format " << default_output_format << '\n';
1003 os << "\\output_sync " << output_sync << '\n';
1004 if (!output_sync_macro.empty())
1005 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1006 os << "\\bibtex_command " << bibtex_command << '\n';
1007 os << "\\index_command " << index_command << '\n';
1009 if (!float_placement.empty()) {
1010 os << "\\float_placement " << float_placement << '\n';
1012 os << "\\paperfontsize " << fontsize << '\n';
1014 spacing().writeFile(os);
1015 pdfoptions().writeFile(os);
1017 os << "\\papersize " << string_papersize[papersize]
1018 << "\n\\use_geometry " << convert<string>(use_geometry);
1019 vector<string> const & packages = auto_packages();
1020 for (size_t i = 0; i < packages.size(); ++i)
1021 os << "\n\\use_package " << packages[i] << ' '
1022 << use_package(packages[i]);
1024 os << "\n\\cite_engine ";
1026 if (!cite_engine_.empty()) {
1027 LayoutModuleList::const_iterator be = cite_engine_.begin();
1028 LayoutModuleList::const_iterator en = cite_engine_.end();
1029 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1038 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1039 << "\n\\biblio_style " << biblio_style
1040 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1041 << "\n\\use_indices " << convert<string>(use_indices)
1042 << "\n\\paperorientation " << string_orientation[orientation]
1043 << "\n\\suppress_date " << convert<string>(suppress_date)
1044 << "\n\\justification " << convert<string>(justification)
1045 << "\n\\use_refstyle " << use_refstyle
1047 if (isbackgroundcolor == true)
1048 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1049 if (isfontcolor == true)
1050 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1051 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1052 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1053 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1054 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1056 BranchList::const_iterator it = branchlist().begin();
1057 BranchList::const_iterator end = branchlist().end();
1058 for (; it != end; ++it) {
1059 os << "\\branch " << to_utf8(it->branch())
1060 << "\n\\selected " << it->isSelected()
1061 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1062 << "\n\\color " << lyx::X11hexname(it->color())
1067 IndicesList::const_iterator iit = indiceslist().begin();
1068 IndicesList::const_iterator iend = indiceslist().end();
1069 for (; iit != iend; ++iit) {
1070 os << "\\index " << to_utf8(iit->index())
1071 << "\n\\shortcut " << to_utf8(iit->shortcut())
1072 << "\n\\color " << lyx::X11hexname(iit->color())
1077 if (!paperwidth.empty())
1078 os << "\\paperwidth "
1079 << VSpace(paperwidth).asLyXCommand() << '\n';
1080 if (!paperheight.empty())
1081 os << "\\paperheight "
1082 << VSpace(paperheight).asLyXCommand() << '\n';
1083 if (!leftmargin.empty())
1084 os << "\\leftmargin "
1085 << VSpace(leftmargin).asLyXCommand() << '\n';
1086 if (!topmargin.empty())
1087 os << "\\topmargin "
1088 << VSpace(topmargin).asLyXCommand() << '\n';
1089 if (!rightmargin.empty())
1090 os << "\\rightmargin "
1091 << VSpace(rightmargin).asLyXCommand() << '\n';
1092 if (!bottommargin.empty())
1093 os << "\\bottommargin "
1094 << VSpace(bottommargin).asLyXCommand() << '\n';
1095 if (!headheight.empty())
1096 os << "\\headheight "
1097 << VSpace(headheight).asLyXCommand() << '\n';
1098 if (!headsep.empty())
1100 << VSpace(headsep).asLyXCommand() << '\n';
1101 if (!footskip.empty())
1103 << VSpace(footskip).asLyXCommand() << '\n';
1104 if (!columnsep.empty())
1105 os << "\\columnsep "
1106 << VSpace(columnsep).asLyXCommand() << '\n';
1107 os << "\\secnumdepth " << secnumdepth
1108 << "\n\\tocdepth " << tocdepth
1109 << "\n\\paragraph_separation "
1110 << string_paragraph_separation[paragraph_separation];
1111 if (!paragraph_separation)
1112 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1114 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1115 os << "\n\\quotes_language "
1116 << string_quotes_language[quotes_language]
1117 << "\n\\papercolumns " << columns
1118 << "\n\\papersides " << sides
1119 << "\n\\paperpagestyle " << pagestyle << '\n';
1120 if (!listings_params.empty())
1121 os << "\\listings_params \"" <<
1122 InsetListingsParams(listings_params).encodedString() << "\"\n";
1123 for (int i = 0; i < 4; ++i) {
1124 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1125 if (user_defined_bullet(i).getFont() != -1) {
1126 os << "\\bullet " << i << " "
1127 << user_defined_bullet(i).getFont() << " "
1128 << user_defined_bullet(i).getCharacter() << " "
1129 << user_defined_bullet(i).getSize() << "\n";
1133 os << "\\bulletLaTeX " << i << " \""
1134 << lyx::to_ascii(user_defined_bullet(i).getText())
1140 os << "\\tracking_changes " << convert<string>(trackChanges) << '\n'
1141 << "\\output_changes " << convert<string>(outputChanges) << '\n'
1142 << "\\html_math_output " << html_math_output << '\n'
1143 << "\\html_css_as_file " << html_css_as_file << '\n'
1144 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1146 if (html_math_img_scale != 1.0)
1147 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1148 if (!html_latex_start.empty())
1149 os << "\\html_latex_start " << html_latex_start << '\n';
1150 if (!html_latex_end.empty())
1151 os << "\\html_latex_end " << html_latex_end << '\n';
1153 os << pimpl_->authorlist;
1157 void BufferParams::validate(LaTeXFeatures & features) const
1159 features.require(documentClass().requires());
1161 if (outputChanges) {
1162 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1163 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1164 LaTeXFeatures::isAvailable("xcolor");
1166 switch (features.runparams().flavor) {
1167 case OutputParams::LATEX:
1168 case OutputParams::DVILUATEX:
1170 features.require("ct-dvipost");
1171 features.require("dvipost");
1172 } else if (xcolorulem) {
1173 features.require("ct-xcolor-ulem");
1174 features.require("ulem");
1175 features.require("xcolor");
1177 features.require("ct-none");
1180 case OutputParams::LUATEX:
1181 case OutputParams::PDFLATEX:
1182 case OutputParams::XETEX:
1184 features.require("ct-xcolor-ulem");
1185 features.require("ulem");
1186 features.require("xcolor");
1187 // improves color handling in PDF output
1188 features.require("pdfcolmk");
1190 features.require("ct-none");
1198 // Floats with 'Here definitely' as default setting.
1199 if (float_placement.find('H') != string::npos)
1200 features.require("float");
1202 for (PackageMap::const_iterator it = use_packages.begin();
1203 it != use_packages.end(); ++it) {
1204 if (it->first == "amsmath") {
1205 // AMS Style is at document level
1206 if (it->second == package_on ||
1207 documentClass().provides("amsmath"))
1208 features.require(it->first);
1209 } else if (it->second == package_on)
1210 features.require(it->first);
1213 // Document-level line spacing
1214 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1215 features.require("setspace");
1217 // the bullet shapes are buffer level not paragraph level
1218 // so they are tested here
1219 for (int i = 0; i < 4; ++i) {
1220 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1222 int const font = user_defined_bullet(i).getFont();
1224 int const c = user_defined_bullet(i).getCharacter();
1230 features.require("latexsym");
1232 } else if (font == 1) {
1233 features.require("amssymb");
1234 } else if (font >= 2 && font <= 5) {
1235 features.require("pifont");
1239 if (pdfoptions().use_hyperref) {
1240 features.require("hyperref");
1241 // due to interferences with babel and hyperref, the color package has to
1242 // be loaded after hyperref when hyperref is used with the colorlinks
1243 // option, see http://www.lyx.org/trac/ticket/5291
1244 if (pdfoptions().colorlinks)
1245 features.require("color");
1248 // some languages are only available via polyglossia
1249 if (features.runparams().flavor == OutputParams::XETEX
1250 && (features.hasPolyglossiaExclusiveLanguages()
1252 features.require("polyglossia");
1254 if (!language->requires().empty())
1255 features.require(language->requires());
1259 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1260 FileName const & filepath) const
1262 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1263 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1264 // \RequirePackage to do so, rather than the normal \usepackage
1265 // Do not try to load any other package before the document class, unless you
1266 // have a thorough understanding of the LATEX internals and know exactly what you
1268 if (features.mustProvide("fix-cm"))
1269 os << "\\RequirePackage{fix-cm}\n";
1271 os << "\\documentclass";
1273 DocumentClass const & tclass = documentClass();
1275 ostringstream clsoptions; // the document class options.
1277 if (tokenPos(tclass.opt_fontsize(),
1278 '|', fontsize) >= 0) {
1279 // only write if existing in list (and not default)
1280 clsoptions << fontsize << "pt,";
1283 // all paper sizes except of A4, A5, B5 and the US sizes need the
1285 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1286 && papersize != PAPER_USLETTER
1287 && papersize != PAPER_USLEGAL
1288 && papersize != PAPER_USEXECUTIVE
1289 && papersize != PAPER_A4
1290 && papersize != PAPER_A5
1291 && papersize != PAPER_B5;
1293 if (!use_geometry) {
1294 switch (papersize) {
1296 clsoptions << "a4paper,";
1298 case PAPER_USLETTER:
1299 clsoptions << "letterpaper,";
1302 clsoptions << "a5paper,";
1305 clsoptions << "b5paper,";
1307 case PAPER_USEXECUTIVE:
1308 clsoptions << "executivepaper,";
1311 clsoptions << "legalpaper,";
1345 if (sides != tclass.sides()) {
1348 clsoptions << "oneside,";
1351 clsoptions << "twoside,";
1357 if (columns != tclass.columns()) {
1359 clsoptions << "twocolumn,";
1361 clsoptions << "onecolumn,";
1365 && orientation == ORIENTATION_LANDSCAPE)
1366 clsoptions << "landscape,";
1368 // language should be a parameter to \documentclass
1369 if (language->babel() == "hebrew"
1370 && default_language->babel() != "hebrew")
1371 // This seems necessary
1372 features.useLanguage(default_language);
1374 ostringstream language_options;
1375 bool const use_babel = features.useBabel() && !tclass.provides("babel");
1376 bool const use_polyglossia = features.usePolyglossia();
1377 bool const global = lyxrc.language_global_options;
1378 if (use_babel || (use_polyglossia && global)) {
1379 language_options << features.getBabelLanguages();
1380 if (!language->babel().empty()) {
1381 if (!language_options.str().empty())
1382 language_options << ',';
1383 language_options << language->babel();
1385 if (global && !features.needBabelLangOptions()
1386 && !language_options.str().empty())
1387 clsoptions << language_options.str() << ',';
1390 // the predefined options from the layout
1391 if (use_default_options && !tclass.options().empty())
1392 clsoptions << tclass.options() << ',';
1394 // the user-defined options
1395 if (!options.empty()) {
1396 clsoptions << options << ',';
1399 string strOptions(clsoptions.str());
1400 if (!strOptions.empty()) {
1401 strOptions = rtrim(strOptions, ",");
1403 os << '[' << from_utf8(strOptions) << ']';
1406 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1407 // end of \documentclass defs
1409 // if we use fontspec, we have to load the AMS packages here
1410 string const ams = features.loadAMSPackages();
1411 if (useNonTeXFonts && !ams.empty())
1412 os << from_ascii(ams);
1415 os << "\\usepackage{fontspec}\n";
1417 // font selection must be done before loading fontenc.sty
1418 string const fonts =
1419 loadFonts(fonts_roman, fonts_sans, fonts_typewriter,
1420 fonts_expert_sc, fonts_old_figures,
1421 fonts_sans_scale, fonts_typewriter_scale,
1422 useNonTeXFonts, features);
1424 os << from_utf8(fonts);
1426 if (fonts_default_family != "default")
1427 os << "\\renewcommand{\\familydefault}{\\"
1428 << from_ascii(fonts_default_family) << "}\n";
1430 // set font encoding
1431 // for arabic_arabi and farsi we also need to load the LAE and
1433 // XeTeX and LuaTeX (with OS fonts) work without fontenc
1434 if (font_encoding() != "default" && language->lang() != "japanese"
1435 && !useNonTeXFonts && !tclass.provides("fontenc")) {
1436 size_t fars = language_options.str().find("farsi");
1437 size_t arab = language_options.str().find("arabic");
1438 if (language->lang() == "arabic_arabi"
1439 || language->lang() == "farsi" || fars != string::npos
1440 || arab != string::npos) {
1441 os << "\\usepackage[" << from_ascii(font_encoding())
1442 << ",LFE,LAE]{fontenc}\n";
1444 os << "\\usepackage[" << from_ascii(font_encoding())
1449 // handle inputenc etc.
1450 writeEncodingPreamble(os, features);
1453 if (!features.runparams().includeall && !included_children_.empty()) {
1454 os << "\\includeonly{";
1455 list<string>::const_iterator it = included_children_.begin();
1456 list<string>::const_iterator en = included_children_.end();
1458 for (; it != en; ++it) {
1459 string incfile = *it;
1460 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1461 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1463 if (!features.runparams().nice)
1465 // \includeonly doesn't want an extension
1466 incfile = changeExtension(incfile, string());
1467 incfile = support::latex_path(incfile);
1468 if (!incfile.empty()) {
1471 os << from_utf8(incfile);
1478 if (!listings_params.empty() || features.isRequired("listings"))
1479 os << "\\usepackage{listings}\n";
1481 if (!listings_params.empty()) {
1483 // do not test validity because listings_params is
1484 // supposed to be valid
1486 InsetListingsParams(listings_params).separatedParams(true);
1487 // we can't support all packages, but we should load the color package
1488 if (par.find("\\color", 0) != string::npos)
1489 features.require("color");
1490 os << from_utf8(par)
1493 if (!tclass.provides("geometry")
1494 && (use_geometry || nonstandard_papersize)) {
1495 odocstringstream ods;
1496 if (!getGraphicsDriver("geometry").empty())
1497 ods << getGraphicsDriver("geometry");
1498 if (orientation == ORIENTATION_LANDSCAPE)
1499 ods << ",landscape";
1500 switch (papersize) {
1502 if (!paperwidth.empty())
1503 ods << ",paperwidth="
1504 << from_ascii(paperwidth);
1505 if (!paperheight.empty())
1506 ods << ",paperheight="
1507 << from_ascii(paperheight);
1509 case PAPER_USLETTER:
1510 ods << ",letterpaper";
1513 ods << ",legalpaper";
1515 case PAPER_USEXECUTIVE:
1516 ods << ",executivepaper";
1605 docstring const g_options = trim(ods.str(), ",");
1606 os << "\\usepackage";
1607 if (!g_options.empty())
1608 os << '[' << g_options << ']';
1609 os << "{geometry}\n";
1610 // output this only if use_geometry is true
1612 os << "\\geometry{verbose";
1613 if (!topmargin.empty())
1614 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1615 if (!bottommargin.empty())
1616 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1617 if (!leftmargin.empty())
1618 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1619 if (!rightmargin.empty())
1620 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1621 if (!headheight.empty())
1622 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1623 if (!headsep.empty())
1624 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1625 if (!footskip.empty())
1626 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1627 if (!columnsep.empty())
1628 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1631 } else if (orientation == ORIENTATION_LANDSCAPE
1632 || papersize != PAPER_DEFAULT) {
1633 features.require("papersize");
1636 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1637 if (pagestyle == "fancy")
1638 os << "\\usepackage{fancyhdr}\n";
1639 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1642 // only output when the background color is not default
1643 if (isbackgroundcolor == true) {
1644 // only require color here, the background color will be defined
1645 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1647 features.require("color");
1648 features.require("pagecolor");
1651 // only output when the font color is not default
1652 if (isfontcolor == true) {
1653 // only require color here, the font color will be defined
1654 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1656 features.require("color");
1657 features.require("fontcolor");
1660 // Only if class has a ToC hierarchy
1661 if (tclass.hasTocLevels()) {
1662 if (secnumdepth != tclass.secnumdepth()) {
1663 os << "\\setcounter{secnumdepth}{"
1667 if (tocdepth != tclass.tocdepth()) {
1668 os << "\\setcounter{tocdepth}{"
1674 if (paragraph_separation) {
1675 // when skip separation
1676 switch (getDefSkip().kind()) {
1677 case VSpace::SMALLSKIP:
1678 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1680 case VSpace::MEDSKIP:
1681 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1683 case VSpace::BIGSKIP:
1684 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1686 case VSpace::LENGTH:
1687 os << "\\setlength{\\parskip}{"
1688 << from_utf8(getDefSkip().length().asLatexString())
1691 default: // should never happen // Then delete it.
1692 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1695 os << "\\setlength{\\parindent}{0pt}\n";
1697 // when separation by indentation
1698 // only output something when a width is given
1699 if (getIndentation().asLyXCommand() != "default") {
1700 os << "\\setlength{\\parindent}{"
1701 << from_utf8(getIndentation().asLatexCommand())
1706 // Now insert the LyX specific LaTeX commands...
1707 docstring lyxpreamble;
1708 features.resolveAlternatives();
1711 if (!output_sync_macro.empty())
1712 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1713 else if (features.runparams().flavor == OutputParams::LATEX)
1714 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1715 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1716 lyxpreamble += "\\synctex=-1\n";
1719 // due to interferences with babel and hyperref, the color package has to
1720 // be loaded (when it is not already loaded) before babel when hyperref
1721 // is used with the colorlinks option, see
1722 // http://www.lyx.org/trac/ticket/5291
1723 // we decided therefore to load color always before babel, see
1724 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1725 lyxpreamble += from_ascii(features.getColorOptions());
1727 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1729 && (features.isRequired("jurabib")
1730 || features.isRequired("hyperref")
1731 || features.isRequired("vietnamese")
1732 || features.isRequired("japanese"))) {
1734 lyxpreamble += from_utf8(features.getBabelPresettings());
1735 lyxpreamble += from_utf8(babelCall(language_options.str(),
1736 features.needBabelLangOptions())) + '\n';
1737 lyxpreamble += from_utf8(features.getBabelPostsettings());
1740 // The optional packages;
1741 lyxpreamble += from_ascii(features.getPackages());
1743 // Additional Indices
1744 if (features.isRequired("splitidx")) {
1745 IndicesList::const_iterator iit = indiceslist().begin();
1746 IndicesList::const_iterator iend = indiceslist().end();
1747 for (; iit != iend; ++iit) {
1748 pair<docstring, docstring> indexname_latex =
1749 features.runparams().encoding->latexString(iit->index(),
1750 features.runparams().dryrun);
1751 if (!indexname_latex.second.empty()) {
1752 // issue a warning about omitted characters
1753 // FIXME: should be passed to the error dialog
1754 frontend::Alert::warning(_("Uncodable characters"),
1755 bformat(_("The following characters that are used in an index name are not\n"
1756 "representable in the current encoding and therefore have been omitted:\n%1$s."),
1757 indexname_latex.second));
1759 lyxpreamble += "\\newindex[";
1760 lyxpreamble += indexname_latex.first;
1761 lyxpreamble += "]{";
1762 lyxpreamble += escape(iit->shortcut());
1763 lyxpreamble += "}\n";
1768 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1771 // * Hyperref manual: "Make sure it comes last of your loaded
1772 // packages, to give it a fighting chance of not being over-written,
1773 // since its job is to redefine many LaTeX commands."
1774 // * Email from Heiko Oberdiek: "It is usually better to load babel
1775 // before hyperref. Then hyperref has a chance to detect babel.
1776 // * Has to be loaded before the "LyX specific LaTeX commands" to
1777 // avoid errors with algorithm floats.
1778 // use hyperref explicitly if it is required
1779 if (features.isRequired("hyperref")) {
1780 // pass what we have to stream here, since we need
1781 // to access the stream itself in PDFOptions.
1784 OutputParams tmp_params = features.runparams();
1785 pdfoptions().writeLaTeX(tmp_params, os,
1786 documentClass().provides("hyperref"));
1787 // set back for the rest
1788 lyxpreamble.clear();
1789 // correctly break URLs with hyperref and dvi output
1790 if (features.runparams().flavor == OutputParams::LATEX
1791 && features.isAvailable("breakurl"))
1792 lyxpreamble += "\\usepackage{breakurl}\n";
1793 } else if (features.isRequired("nameref"))
1794 // hyperref loads this automatically
1795 lyxpreamble += "\\usepackage{nameref}\n";
1797 // bibtopic needs to be loaded after hyperref.
1798 // the dot provides the aux file naming which LyX can detect.
1799 if (features.mustProvide("bibtopic"))
1800 lyxpreamble += "\\usepackage[dot]{bibtopic}\n";
1802 // Will be surrounded by \makeatletter and \makeatother when not empty
1803 docstring atlyxpreamble;
1805 // Some macros LyX will need
1806 docstring tmppreamble(features.getMacros());
1808 if (!tmppreamble.empty())
1809 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1810 "LyX specific LaTeX commands.\n"
1811 + tmppreamble + '\n';
1813 // the text class specific preamble
1814 tmppreamble = features.getTClassPreamble();
1815 if (!tmppreamble.empty())
1816 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1817 "Textclass specific LaTeX commands.\n"
1818 + tmppreamble + '\n';
1820 // suppress date if selected
1821 // use \@ifundefined because we cannot be sure that every document class
1822 // has a \date command
1824 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1826 /* the user-defined preamble */
1827 if (!containsOnly(preamble, " \n\t"))
1829 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1830 "User specified LaTeX commands.\n"
1831 + from_utf8(preamble) + '\n';
1833 // subfig loads internally the LaTeX package "caption". As
1834 // caption is a very popular package, users will load it in
1835 // the preamble. Therefore we must load subfig behind the
1836 // user-defined preamble and check if the caption package was
1837 // loaded or not. For the case that caption is loaded before
1838 // subfig, there is the subfig option "caption=false". This
1839 // option also works when a koma-script class is used and
1840 // koma's own caption commands are used instead of caption. We
1841 // use \PassOptionsToPackage here because the user could have
1842 // already loaded subfig in the preamble.
1843 if (features.isRequired("subfig")) {
1844 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1845 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1846 "\\usepackage{subfig}\n";
1849 // Itemize bullet settings need to be last in case the user
1850 // defines their own bullets that use a package included
1851 // in the user-defined preamble -- ARRae
1852 // Actually it has to be done much later than that
1853 // since some packages like frenchb make modifications
1854 // at \begin{document} time -- JMarc
1855 docstring bullets_def;
1856 for (int i = 0; i < 4; ++i) {
1857 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1858 if (bullets_def.empty())
1859 bullets_def += "\\AtBeginDocument{\n";
1860 bullets_def += " \\def\\labelitemi";
1862 // `i' is one less than the item to modify
1869 bullets_def += "ii";
1875 bullets_def += '{' +
1876 user_defined_bullet(i).getText()
1881 if (!bullets_def.empty())
1882 atlyxpreamble += bullets_def + "}\n\n";
1884 if (!atlyxpreamble.empty())
1885 lyxpreamble += "\n\\makeatletter\n"
1886 + atlyxpreamble + "\\makeatother\n\n";
1888 // We try to load babel late, in case it interferes with other packages.
1889 // Jurabib and Hyperref have to be called after babel, though.
1890 if (use_babel && !features.isRequired("jurabib")
1891 && !features.isRequired("hyperref")
1892 && !features.isRequired("vietnamese")
1893 && !features.isRequired("japanese")) {
1895 lyxpreamble += from_utf8(features.getBabelPresettings());
1896 lyxpreamble += from_utf8(babelCall(language_options.str(),
1897 features.needBabelLangOptions())) + '\n';
1898 lyxpreamble += from_utf8(features.getBabelPostsettings());
1901 // xunicode needs to be loaded at least after amsmath, amssymb,
1902 // esint and the other packages that provide special glyphs
1903 if (features.runparams().flavor == OutputParams::XETEX)
1904 lyxpreamble += "\\usepackage{xunicode}\n";
1906 // Polyglossia must be loaded last
1907 if (use_polyglossia) {
1909 lyxpreamble += "\\usepackage{polyglossia}\n";
1910 // set the main language
1911 lyxpreamble += "\\setdefaultlanguage";
1912 if (!language->polyglossiaOpts().empty())
1913 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
1914 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
1915 // now setup the other languages
1916 std::map<std::string, std::string> const polylangs =
1917 features.getPolyglossiaLanguages();
1918 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
1919 mit != polylangs.end() ; ++mit) {
1920 lyxpreamble += "\\setotherlanguage";
1921 if (!mit->second.empty())
1922 lyxpreamble += "[" + from_ascii(mit->second) + "]";
1923 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
1927 // Load custom language package here
1928 if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
1929 if (lang_package == "default")
1930 lyxpreamble += from_utf8(lyxrc.language_custom_package);
1932 lyxpreamble += from_utf8(lang_package);
1933 lyxpreamble += '\n';
1936 docstring const i18npreamble =
1937 features.getTClassI18nPreamble(use_babel, use_polyglossia);
1938 if (!i18npreamble.empty())
1939 lyxpreamble += i18npreamble + '\n';
1947 void BufferParams::useClassDefaults()
1949 DocumentClass const & tclass = documentClass();
1951 sides = tclass.sides();
1952 columns = tclass.columns();
1953 pagestyle = tclass.pagestyle();
1954 use_default_options = true;
1955 // Only if class has a ToC hierarchy
1956 if (tclass.hasTocLevels()) {
1957 secnumdepth = tclass.secnumdepth();
1958 tocdepth = tclass.tocdepth();
1963 bool BufferParams::hasClassDefaults() const
1965 DocumentClass const & tclass = documentClass();
1967 return sides == tclass.sides()
1968 && columns == tclass.columns()
1969 && pagestyle == tclass.pagestyle()
1970 && use_default_options
1971 && secnumdepth == tclass.secnumdepth()
1972 && tocdepth == tclass.tocdepth();
1976 DocumentClass const & BufferParams::documentClass() const
1978 return *doc_class_.get();
1982 DocumentClassConstPtr BufferParams::documentClassPtr() const
1988 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
1990 // evil, but this function is evil
1991 doc_class_ = const_pointer_cast<DocumentClass>(tc);
1995 bool BufferParams::setBaseClass(string const & classname)
1997 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1998 LayoutFileList & bcl = LayoutFileList::get();
1999 if (!bcl.haveClass(classname)) {
2001 bformat(_("The layout file:\n"
2003 "could not be found. A default textclass with default\n"
2004 "layouts will be used. LyX will not be able to produce\n"
2006 from_utf8(classname));
2007 frontend::Alert::error(_("Document class not found"), s);
2008 bcl.addEmptyClass(classname);
2011 bool const success = bcl[classname].load();
2014 bformat(_("Due to some error in it, the layout file:\n"
2016 "could not be loaded. A default textclass with default\n"
2017 "layouts will be used. LyX will not be able to produce\n"
2019 from_utf8(classname));
2020 frontend::Alert::error(_("Could not load class"), s);
2021 bcl.addEmptyClass(classname);
2024 pimpl_->baseClass_ = classname;
2025 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2030 LayoutFile const * BufferParams::baseClass() const
2032 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2033 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2039 LayoutFileIndex const & BufferParams::baseClassID() const
2041 return pimpl_->baseClass_;
2045 void BufferParams::makeDocumentClass()
2050 LayoutModuleList mods;
2051 LayoutModuleList::iterator it;
2052 LayoutModuleList::iterator en;
2054 it = layout_modules_.begin();
2055 en = layout_modules_.end();
2056 for (; it != en; ++it)
2057 mods.push_back(*it);
2058 it = cite_engine_.begin();
2059 en = cite_engine_.end();
2060 for (; it != en; ++it)
2061 mods.push_back(*it);
2062 doc_class_ = getDocumentClass(*baseClass(), mods);
2064 if (!local_layout.empty()) {
2065 TextClass::ReturnValues success =
2066 doc_class_->read(local_layout, TextClass::MODULE);
2067 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2068 docstring const msg = _("Error reading internal layout information");
2069 frontend::Alert::warning(_("Read Error"), msg);
2075 bool BufferParams::moduleCanBeAdded(string const & modName) const
2077 return cite_engine_.moduleCanBeAdded(modName, baseClass()) &&
2078 layout_modules_.moduleCanBeAdded(modName, baseClass());
2082 bool BufferParams::addLayoutModule(string const & modName)
2084 LayoutModuleList::const_iterator it = layout_modules_.begin();
2085 LayoutModuleList::const_iterator end = layout_modules_.end();
2086 for (; it != end; ++it)
2089 layout_modules_.push_back(modName);
2094 string BufferParams::bufferFormat() const
2096 string format = documentClass().outputFormat();
2097 if (format == "latex") {
2100 if (encoding().package() == Encoding::japanese)
2107 bool BufferParams::isExportable(string const & format) const
2109 vector<string> backs = backends();
2110 for (vector<string>::const_iterator it = backs.begin();
2111 it != backs.end(); ++it)
2112 if (theConverters().isReachable(*it, format))
2119 bool formatSorter(Format const * lhs, Format const * rhs) {
2120 return _(lhs->prettyname()) < _(rhs->prettyname());
2125 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2127 vector<string> const backs = backends();
2128 set<string> excludes;
2129 if (useNonTeXFonts) {
2130 excludes.insert("latex");
2131 excludes.insert("pdflatex");
2133 vector<Format const *> result =
2134 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2135 for (vector<string>::const_iterator it = backs.begin() + 1;
2136 it != backs.end(); ++it) {
2137 vector<Format const *> r =
2138 theConverters().getReachable(*it, only_viewable, false, excludes);
2139 result.insert(result.end(), r.begin(), r.end());
2141 sort(result.begin(), result.end(), formatSorter);
2146 bool BufferParams::isExportableFormat(string const & format) const
2148 typedef vector<Format const *> Formats;
2150 formats = exportableFormats(true);
2151 Formats::const_iterator fit = formats.begin();
2152 Formats::const_iterator end = formats.end();
2153 for (; fit != end ; ++fit) {
2154 if ((*fit)->name() == format)
2161 vector<string> BufferParams::backends() const
2164 string const buffmt = bufferFormat();
2166 // FIXME: Don't hardcode format names here, but use a flag
2167 if (buffmt == "latex") {
2168 if (!useNonTeXFonts) {
2169 v.push_back("pdflatex");
2170 v.push_back("latex");
2172 v.push_back("luatex");
2173 v.push_back("dviluatex");
2174 v.push_back("xetex");
2175 } else if (buffmt == "xetex") {
2176 v.push_back("xetex");
2177 v.push_back("luatex");
2178 v.push_back("dviluatex");
2180 v.push_back(buffmt);
2182 v.push_back("xhtml");
2183 v.push_back("text");
2189 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
2191 string const dformat = (format.empty() || format == "default") ?
2192 getDefaultOutputFormat() : format;
2193 DefaultFlavorCache::const_iterator it =
2194 default_flavors_.find(dformat);
2196 if (it != default_flavors_.end())
2199 OutputParams::FLAVOR result = OutputParams::LATEX;
2201 // FIXME It'd be better not to hardcode this, but to do
2202 // something with formats.
2203 if (dformat == "xhtml")
2204 result = OutputParams::HTML;
2205 else if (dformat == "text")
2206 result = OutputParams::TEXT;
2207 else if (dformat == "lyx")
2208 result = OutputParams::LYX;
2209 else if (dformat == "pdflatex")
2210 result = OutputParams::PDFLATEX;
2211 else if (dformat == "xetex")
2212 result = OutputParams::XETEX;
2213 else if (dformat == "luatex")
2214 result = OutputParams::LUATEX;
2215 else if (dformat == "dviluatex")
2216 result = OutputParams::DVILUATEX;
2218 // Try to determine flavor of default output format
2219 vector<string> backs = backends();
2220 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2221 // Get shortest path to format
2222 Graph::EdgePath path;
2223 for (vector<string>::const_iterator it = backs.begin();
2224 it != backs.end(); ++it) {
2225 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2226 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2231 result = theConverters().getFlavor(path);
2234 // cache this flavor
2235 default_flavors_[dformat] = result;
2240 string BufferParams::getDefaultOutputFormat() const
2242 if (!default_output_format.empty()
2243 && default_output_format != "default")
2244 return default_output_format;
2247 || encoding().package() == Encoding::japanese) {
2248 vector<Format const *> const formats = exportableFormats(true);
2249 if (formats.empty())
2251 // return the first we find
2252 return formats.front()->name();
2254 return lyxrc.default_view_format;
2257 Font const BufferParams::getFont() const
2259 FontInfo f = documentClass().defaultfont();
2260 if (fonts_default_family == "rmdefault")
2261 f.setFamily(ROMAN_FAMILY);
2262 else if (fonts_default_family == "sfdefault")
2263 f.setFamily(SANS_FAMILY);
2264 else if (fonts_default_family == "ttdefault")
2265 f.setFamily(TYPEWRITER_FAMILY);
2266 return Font(f, language);
2270 InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const qs) const
2272 return quoteslangtranslator().find(qs);
2276 bool BufferParams::isLatex() const
2278 return documentClass().outputType() == LATEX;
2282 bool BufferParams::isLiterate() const
2284 return documentClass().outputType() == LITERATE;
2288 bool BufferParams::isDocBook() const
2290 return documentClass().outputType() == DOCBOOK;
2294 void BufferParams::readPreamble(Lexer & lex)
2296 if (lex.getString() != "\\begin_preamble")
2297 lyxerr << "Error (BufferParams::readPreamble):"
2298 "consistency check failed." << endl;
2300 preamble = lex.getLongString("\\end_preamble");
2304 void BufferParams::readLocalLayout(Lexer & lex)
2306 if (lex.getString() != "\\begin_local_layout")
2307 lyxerr << "Error (BufferParams::readLocalLayout):"
2308 "consistency check failed." << endl;
2310 local_layout = lex.getLongString("\\end_local_layout");
2314 bool BufferParams::setLanguage(string const & lang)
2316 Language const *new_language = languages.getLanguage(lang);
2317 if (!new_language) {
2318 // Language lang was not found
2321 language = new_language;
2326 void BufferParams::readLanguage(Lexer & lex)
2328 if (!lex.next()) return;
2330 string const tmptok = lex.getString();
2332 // check if tmptok is part of tex_babel in tex-defs.h
2333 if (!setLanguage(tmptok)) {
2334 // Language tmptok was not found
2335 language = default_language;
2336 lyxerr << "Warning: Setting language `"
2337 << tmptok << "' to `" << language->lang()
2343 void BufferParams::readGraphicsDriver(Lexer & lex)
2348 string const tmptok = lex.getString();
2349 // check if tmptok is part of tex_graphics in tex_defs.h
2352 string const test = tex_graphics[n++];
2354 if (test == tmptok) {
2355 graphics_driver = tmptok;
2360 "Warning: graphics driver `$$Token' not recognized!\n"
2361 " Setting graphics driver to `default'.\n");
2362 graphics_driver = "default";
2369 void BufferParams::readBullets(Lexer & lex)
2374 int const index = lex.getInteger();
2376 int temp_int = lex.getInteger();
2377 user_defined_bullet(index).setFont(temp_int);
2378 temp_bullet(index).setFont(temp_int);
2380 user_defined_bullet(index).setCharacter(temp_int);
2381 temp_bullet(index).setCharacter(temp_int);
2383 user_defined_bullet(index).setSize(temp_int);
2384 temp_bullet(index).setSize(temp_int);
2388 void BufferParams::readBulletsLaTeX(Lexer & lex)
2390 // The bullet class should be able to read this.
2393 int const index = lex.getInteger();
2395 docstring const temp_str = lex.getDocString();
2397 user_defined_bullet(index).setText(temp_str);
2398 temp_bullet(index).setText(temp_str);
2402 void BufferParams::readModules(Lexer & lex)
2404 if (!lex.eatLine()) {
2405 lyxerr << "Error (BufferParams::readModules):"
2406 "Unexpected end of input." << endl;
2410 string mod = lex.getString();
2411 if (mod == "\\end_modules")
2413 addLayoutModule(mod);
2419 void BufferParams::readRemovedModules(Lexer & lex)
2421 if (!lex.eatLine()) {
2422 lyxerr << "Error (BufferParams::readRemovedModules):"
2423 "Unexpected end of input." << endl;
2427 string mod = lex.getString();
2428 if (mod == "\\end_removed_modules")
2430 removed_modules_.push_back(mod);
2433 // now we want to remove any removed modules that were previously
2434 // added. normally, that will be because default modules were added in
2435 // setBaseClass(), which gets called when \textclass is read at the
2436 // start of the read.
2437 list<string>::const_iterator rit = removed_modules_.begin();
2438 list<string>::const_iterator const ren = removed_modules_.end();
2439 for (; rit != ren; ++rit) {
2440 LayoutModuleList::iterator const mit = layout_modules_.begin();
2441 LayoutModuleList::iterator const men = layout_modules_.end();
2442 LayoutModuleList::iterator found = find(mit, men, *rit);
2445 layout_modules_.erase(found);
2450 void BufferParams::readIncludeonly(Lexer & lex)
2452 if (!lex.eatLine()) {
2453 lyxerr << "Error (BufferParams::readIncludeonly):"
2454 "Unexpected end of input." << endl;
2458 string child = lex.getString();
2459 if (child == "\\end_includeonly")
2461 included_children_.push_back(child);
2467 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2469 switch (papersize) {
2471 // could be anything, so don't guess
2473 case PAPER_CUSTOM: {
2474 if (purpose == XDVI && !paperwidth.empty() &&
2475 !paperheight.empty()) {
2476 // heightxwidth<unit>
2477 string first = paperwidth;
2478 string second = paperheight;
2479 if (orientation == ORIENTATION_LANDSCAPE)
2482 return first.erase(first.length() - 2)
2488 // dvips and dvipdfm do not know this
2489 if (purpose == DVIPS || purpose == DVIPDFM)
2493 if (purpose == DVIPS || purpose == DVIPDFM)
2497 if (purpose == DVIPS || purpose == DVIPDFM)
2507 if (purpose == DVIPS || purpose == DVIPDFM)
2511 if (purpose == DVIPS || purpose == DVIPDFM)
2515 if (purpose == DVIPS || purpose == DVIPDFM)
2519 if (purpose == DVIPS || purpose == DVIPDFM)
2523 if (purpose == DVIPS || purpose == DVIPDFM)
2527 // dvipdfm does not know this
2528 if (purpose == DVIPDFM)
2532 if (purpose == DVIPDFM)
2536 if (purpose == DVIPS || purpose == DVIPDFM)
2540 if (purpose == DVIPS || purpose == DVIPDFM)
2544 if (purpose == DVIPS || purpose == DVIPDFM)
2548 if (purpose == DVIPS || purpose == DVIPDFM)
2552 if (purpose == DVIPS || purpose == DVIPDFM)
2556 if (purpose == DVIPS || purpose == DVIPDFM)
2560 if (purpose == DVIPS || purpose == DVIPDFM)
2564 if (purpose == DVIPS || purpose == DVIPDFM)
2568 if (purpose == DVIPS || purpose == DVIPDFM)
2572 if (purpose == DVIPS || purpose == DVIPDFM)
2576 if (purpose == DVIPS || purpose == DVIPDFM)
2580 if (purpose == DVIPS || purpose == DVIPDFM)
2584 if (purpose == DVIPS || purpose == DVIPDFM)
2588 if (purpose == DVIPS || purpose == DVIPDFM)
2592 if (purpose == DVIPS || purpose == DVIPDFM)
2595 case PAPER_USEXECUTIVE:
2596 // dvipdfm does not know this
2597 if (purpose == DVIPDFM)
2602 case PAPER_USLETTER:
2604 if (purpose == XDVI)
2611 string const BufferParams::dvips_options() const
2615 // If the class loads the geometry package, we do not know which
2616 // paper size is used, since we do not set it (bug 7013).
2617 // Therefore we must not specify any argument here.
2618 // dvips gets the correct paper size via DVI specials in this case
2619 // (if the class uses the geometry package correctly).
2620 if (documentClass().provides("geometry"))
2624 && papersize == PAPER_CUSTOM
2625 && !lyxrc.print_paper_dimension_flag.empty()
2626 && !paperwidth.empty()
2627 && !paperheight.empty()) {
2628 // using a custom papersize
2629 result = lyxrc.print_paper_dimension_flag;
2630 result += ' ' + paperwidth;
2631 result += ',' + paperheight;
2633 string const paper_option = paperSizeName(DVIPS);
2634 if (!paper_option.empty() && (paper_option != "letter" ||
2635 orientation != ORIENTATION_LANDSCAPE)) {
2636 // dvips won't accept -t letter -t landscape.
2637 // In all other cases, include the paper size
2639 result = lyxrc.print_paper_flag;
2640 result += ' ' + paper_option;
2643 if (orientation == ORIENTATION_LANDSCAPE &&
2644 papersize != PAPER_CUSTOM)
2645 result += ' ' + lyxrc.print_landscape_flag;
2650 string const BufferParams::font_encoding() const
2652 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2656 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2658 // suppress the babel call if there is no BabelName defined
2659 // for the document language in the lib/languages file and if no
2660 // other languages are used (lang_opts is then empty)
2661 if (lang_opts.empty())
2663 // either a specific language (AsBabelOptions setting in
2664 // lib/languages) or the prefs require the languages to
2665 // be submitted to babel itself (not the class).
2667 return "\\usepackage[" + lang_opts + "]{babel}";
2668 return "\\usepackage{babel}";
2672 docstring BufferParams::getGraphicsDriver(string const & package) const
2676 if (package == "geometry") {
2677 if (graphics_driver == "dvips"
2678 || graphics_driver == "dvipdfm"
2679 || graphics_driver == "pdftex"
2680 || graphics_driver == "vtex")
2681 result = from_ascii(graphics_driver);
2682 else if (graphics_driver == "dvipdfmx")
2683 result = from_ascii("dvipdfm");
2690 void BufferParams::writeEncodingPreamble(otexstream & os,
2691 LaTeXFeatures & features) const
2693 // XeTeX does not need this
2694 if (features.runparams().flavor == OutputParams::XETEX)
2696 // LuaTeX neither, but with tex fonts, we need to load
2697 // the luainputenc package.
2698 if (features.runparams().flavor == OutputParams::LUATEX
2699 || features.runparams().flavor == OutputParams::DVILUATEX) {
2700 if (!useNonTeXFonts && inputenc != "default"
2701 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2702 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2703 os << "\\usepackage[utf8]{luainputenc}\n";
2707 if (inputenc == "auto") {
2708 string const doc_encoding =
2709 language->encoding()->latexName();
2710 Encoding::Package const package =
2711 language->encoding()->package();
2713 // Create a list with all the input encodings used
2715 set<string> encodings =
2716 features.getEncodingSet(doc_encoding);
2718 // If the "japanese" package (i.e. pLaTeX) is used,
2719 // inputenc must be omitted.
2720 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2721 if ((!encodings.empty() || package == Encoding::inputenc)
2722 && !features.isRequired("japanese")) {
2723 os << "\\usepackage[";
2724 set<string>::const_iterator it = encodings.begin();
2725 set<string>::const_iterator const end = encodings.end();
2727 os << from_ascii(*it);
2730 for (; it != end; ++it)
2731 os << ',' << from_ascii(*it);
2732 if (package == Encoding::inputenc) {
2733 if (!encodings.empty())
2735 os << from_ascii(doc_encoding);
2737 os << "]{inputenc}\n";
2739 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2740 if (language->encoding()->name() == "utf8-cjk"
2741 && LaTeXFeatures::isAvailable("CJKutf8"))
2742 os << "\\usepackage{CJKutf8}\n";
2744 os << "\\usepackage{CJK}\n";
2746 } else if (inputenc != "default") {
2747 switch (encoding().package()) {
2748 case Encoding::none:
2749 case Encoding::japanese:
2751 case Encoding::inputenc:
2752 // do not load inputenc if japanese is used
2753 if (features.isRequired("japanese"))
2755 os << "\\usepackage[" << from_ascii(inputenc)
2759 if (encoding().name() == "utf8-cjk"
2760 && LaTeXFeatures::isAvailable("CJKutf8"))
2761 os << "\\usepackage{CJKutf8}\n";
2763 os << "\\usepackage{CJK}\n";
2770 string const BufferParams::parseFontName(string const & name) const
2772 string mangled = name;
2773 size_t const idx = mangled.find('[');
2774 if (idx == string::npos || idx == 0)
2777 return mangled.substr(0, idx - 1);
2781 string const BufferParams::loadFonts(string const & rm,
2782 string const & sf, string const & tt,
2783 bool const & sc, bool const & osf,
2784 int const & sfscale, int const & ttscale,
2785 bool const & use_systemfonts,
2786 LaTeXFeatures & features) const
2788 // TODO: separate math fonts.
2790 if (rm == "default" && sf == "default" && tt == "default")
2796 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
2797 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
2798 * Mapping=tex-text option assures TeX ligatures (such as "--")
2799 * are resolved. Note that tt does not use these ligatures.
2801 * -- add more GUI options?
2802 * -- add more fonts (fonts for other scripts)
2803 * -- if there's a way to find out if a font really supports
2804 * OldStyle, enable/disable the widget accordingly.
2806 if (use_systemfonts && features.isAvailable("fontspec")) {
2807 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
2808 // However, until v.2 (2010/07/11) fontspec only knew
2809 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
2810 // was introduced for both XeTeX and LuaTeX (LuaTeX
2811 // didn't understand "Mapping=tex-text", while XeTeX
2812 // understood both. With most recent versions, both
2813 // variants are understood by both engines. However,
2814 // we want to provide support for at least TeXLive 2009
2815 // (for XeTeX; LuaTeX is only supported as of v.2)
2816 string const texmapping =
2817 (features.runparams().flavor == OutputParams::XETEX) ?
2818 "Mapping=tex-text" : "Ligatures=TeX";
2819 if (rm != "default") {
2820 os << "\\setmainfont[" << texmapping;
2822 os << ",Numbers=OldStyle";
2823 os << "]{" << parseFontName(rm) << "}\n";
2825 if (sf != "default") {
2826 string const sans = parseFontName(sf);
2828 os << "\\setsansfont[Scale="
2829 << float(sfscale) / 100
2830 << "," << texmapping << "]{"
2833 os << "\\setsansfont[" << texmapping << "]{"
2836 if (tt != "default") {
2837 string const mono = parseFontName(tt);
2839 os << "\\setmonofont[Scale="
2840 << float(ttscale) / 100
2844 os << "\\setmonofont{"
2851 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
2852 bool const dryrun = features.runparams().dryrun;
2853 bool const complete = (sf == "default" && tt == "default");
2856 os << theLaTeXFonts().getLaTeXFont(from_ascii(rm)).getLaTeXCode(dryrun, ot1, complete, sc, osf);
2859 os << theLaTeXFonts().getLaTeXFont(from_ascii(sf)).getLaTeXCode(dryrun, ot1, complete, sc, osf, sfscale);
2861 // MONOSPACED/TYPEWRITER
2862 os << theLaTeXFonts().getLaTeXFont(from_ascii(tt)).getLaTeXCode(dryrun, ot1, complete, sc, osf, ttscale);
2868 Encoding const & BufferParams::encoding() const
2870 // FIXME: actually, we should check for the flavor
2871 // or runparams.isFullyUnicode() here:
2872 // This check will not work with XeTeX/LuaTeX and tex fonts.
2873 // Thus we have to reset the encoding in Buffer::makeLaTeXFile.
2875 return *(encodings.fromLaTeXName("utf8-plain"));
2876 if (inputenc == "auto" || inputenc == "default")
2877 return *language->encoding();
2878 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2881 LYXERR0("Unknown inputenc value `" << inputenc
2882 << "'. Using `auto' instead.");
2883 return *language->encoding();
2887 bool BufferParams::addCiteEngine(string const & engine)
2889 LayoutModuleList::const_iterator it = cite_engine_.begin();
2890 LayoutModuleList::const_iterator en = cite_engine_.end();
2891 for (; it != en; ++it)
2894 cite_engine_.push_back(engine);
2899 bool BufferParams::addCiteEngine(vector<string> const & engine)
2901 vector<string>::const_iterator it = engine.begin();
2902 vector<string>::const_iterator en = engine.end();
2904 for (; it != en; ++it)
2905 if (!addCiteEngine(*it))
2911 string const & BufferParams::defaultBiblioStyle() const
2913 return documentClass().defaultBiblioStyle();
2917 bool const & BufferParams::fullAuthorList() const
2919 return documentClass().fullAuthorList();
2923 void BufferParams::setCiteEngine(string const & engine)
2926 addCiteEngine(engine);
2930 void BufferParams::setCiteEngine(vector<string> const & engine)
2933 addCiteEngine(engine);
2937 vector<string> BufferParams::citeCommands() const
2939 static CitationStyle const default_style;
2940 vector<string> commands =
2941 documentClass().citeCommands(citeEngineType());
2942 if (commands.empty())
2943 commands.push_back(default_style.cmd);
2948 vector<CitationStyle> BufferParams::citeStyles() const
2950 static CitationStyle const default_style;
2951 vector<CitationStyle> styles =
2952 documentClass().citeStyles(citeEngineType());
2954 styles.push_back(default_style);