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";
380 fonts_default_family = "default";
381 useNonTeXFonts = false;
382 fonts_expert_sc = false;
383 fonts_old_figures = false;
384 fonts_sans_scale = 100;
385 fonts_typewriter_scale = 100;
387 lang_package = "default";
388 graphics_driver = "default";
389 default_output_format = "default";
390 bibtex_command = "default";
391 index_command = "default";
394 listings_params = string();
395 pagestyle = "default";
396 suppress_date = false;
397 justification = true;
398 // no color is the default (white)
399 backgroundcolor = lyx::rgbFromHexName("#ffffff");
400 isbackgroundcolor = false;
401 // no color is the default (black)
402 fontcolor = lyx::rgbFromHexName("#000000");
404 // light gray is the default font color for greyed-out notes
405 notefontcolor = lyx::rgbFromHexName("#cccccc");
406 boxbgcolor = lyx::rgbFromHexName("#ff0000");
407 compressed = lyxrc.save_compressed;
408 for (int iter = 0; iter < 4; ++iter) {
409 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
410 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
413 indiceslist().addDefault(B_("Index"));
414 html_be_strict = false;
415 html_math_output = MathML;
416 html_math_img_scale = 1.0;
417 html_css_as_file = false;
424 docstring BufferParams::B_(string const & l10n) const
426 LASSERT(language, /**/);
427 return getMessages(language->code()).get(l10n);
431 BufferParams::Package BufferParams::use_package(std::string const & p) const
433 PackageMap::const_iterator it = use_packages.find(p);
434 if (it == use_packages.end())
440 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
446 vector<string> const & BufferParams::auto_packages()
448 static vector<string> packages;
449 if (packages.empty()) {
450 // adding a package here implies a file format change!
451 packages.push_back("amsmath");
452 packages.push_back("amssymb");
453 packages.push_back("esint");
454 packages.push_back("mathdots");
455 packages.push_back("mathtools");
456 packages.push_back("mhchem");
457 packages.push_back("undertilde");
463 AuthorList & BufferParams::authors()
465 return pimpl_->authorlist;
469 AuthorList const & BufferParams::authors() const
471 return pimpl_->authorlist;
475 BranchList & BufferParams::branchlist()
477 return pimpl_->branchlist;
481 BranchList const & BufferParams::branchlist() const
483 return pimpl_->branchlist;
487 IndicesList & BufferParams::indiceslist()
489 return pimpl_->indiceslist;
493 IndicesList const & BufferParams::indiceslist() const
495 return pimpl_->indiceslist;
499 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
501 LASSERT(index < 4, /**/);
502 return pimpl_->temp_bullets[index];
506 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
508 LASSERT(index < 4, /**/);
509 return pimpl_->temp_bullets[index];
513 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
515 LASSERT(index < 4, /**/);
516 return pimpl_->user_defined_bullets[index];
520 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
522 LASSERT(index < 4, /**/);
523 return pimpl_->user_defined_bullets[index];
527 Spacing & BufferParams::spacing()
529 return pimpl_->spacing;
533 Spacing const & BufferParams::spacing() const
535 return pimpl_->spacing;
539 PDFOptions & BufferParams::pdfoptions()
541 return pimpl_->pdfoptions;
545 PDFOptions const & BufferParams::pdfoptions() const
547 return pimpl_->pdfoptions;
551 HSpace const & BufferParams::getIndentation() const
553 return pimpl_->indentation;
557 void BufferParams::setIndentation(HSpace const & indent)
559 pimpl_->indentation = indent;
563 VSpace const & BufferParams::getDefSkip() const
565 return pimpl_->defskip;
569 void BufferParams::setDefSkip(VSpace const & vs)
571 // DEFSKIP will cause an infinite loop
572 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
573 pimpl_->defskip = vs;
577 string BufferParams::readToken(Lexer & lex, string const & token,
578 FileName const & filepath)
580 if (token == "\\textclass") {
582 string const classname = lex.getString();
583 // if there exists a local layout file, ignore the system one
584 // NOTE: in this case, the textclass (.cls file) is assumed to
587 LayoutFileList & bcl = LayoutFileList::get();
588 if (tcp.empty() && !filepath.empty())
589 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
593 setBaseClass(classname);
594 // We assume that a tex class exists for local or unknown
595 // layouts so this warning, will only be given for system layouts.
596 if (!baseClass()->isTeXClassAvailable()) {
597 docstring const desc =
598 translateIfPossible(from_utf8(baseClass()->description()));
599 docstring const prereqs =
600 from_utf8(baseClass()->prerequisites());
601 docstring const msg =
602 bformat(_("The selected document class\n"
604 "requires external files that are not available.\n"
605 "The document class can still be used, but the\n"
606 "document cannot be compiled until the following\n"
607 "prerequisites are installed:\n"
609 "See section 3.1.2.2 (Class Availability) of the\n"
610 "User's Guide for more information."), desc, prereqs);
611 frontend::Alert::warning(_("Document class not available"),
614 } else if (token == "\\begin_preamble") {
616 } else if (token == "\\begin_local_layout") {
617 readLocalLayout(lex);
618 } else if (token == "\\begin_modules") {
620 } else if (token == "\\begin_removed_modules") {
621 readRemovedModules(lex);
622 } else if (token == "\\begin_includeonly") {
623 readIncludeonly(lex);
624 } else if (token == "\\maintain_unincluded_children") {
625 lex >> maintain_unincluded_children;
626 } else if (token == "\\options") {
628 options = lex.getString();
629 } else if (token == "\\use_default_options") {
630 lex >> use_default_options;
631 } else if (token == "\\master") {
633 master = lex.getString();
634 } else if (token == "\\suppress_date") {
635 lex >> suppress_date;
636 } else if (token == "\\justification") {
637 lex >> justification;
638 } else if (token == "\\language") {
640 } else if (token == "\\language_package") {
642 lang_package = lex.getString();
643 } else if (token == "\\inputencoding") {
645 } else if (token == "\\graphics") {
646 readGraphicsDriver(lex);
647 } else if (token == "\\default_output_format") {
648 lex >> default_output_format;
649 } else if (token == "\\bibtex_command") {
651 bibtex_command = lex.getString();
652 } else if (token == "\\index_command") {
654 index_command = lex.getString();
655 } else if (token == "\\fontencoding") {
657 fontenc = lex.getString();
658 } else if (token == "\\font_roman") {
660 fonts_roman = lex.getString();
661 } else if (token == "\\font_sans") {
663 fonts_sans = lex.getString();
664 } else if (token == "\\font_typewriter") {
666 fonts_typewriter = lex.getString();
667 } else if (token == "\\font_math") {
669 fonts_math = lex.getString();
670 } else if (token == "\\font_default_family") {
671 lex >> fonts_default_family;
672 } else if (token == "\\use_non_tex_fonts") {
673 lex >> useNonTeXFonts;
674 } else if (token == "\\font_sc") {
675 lex >> fonts_expert_sc;
676 } else if (token == "\\font_osf") {
677 lex >> fonts_old_figures;
678 } else if (token == "\\font_sf_scale") {
679 lex >> fonts_sans_scale;
680 } else if (token == "\\font_tt_scale") {
681 lex >> fonts_typewriter_scale;
682 } else if (token == "\\font_cjk") {
684 } else if (token == "\\paragraph_separation") {
687 paragraph_separation = parseptranslator().find(parsep);
688 } else if (token == "\\paragraph_indentation") {
690 string indentation = lex.getString();
691 pimpl_->indentation = HSpace(indentation);
692 } else if (token == "\\defskip") {
694 string const defskip = lex.getString();
695 pimpl_->defskip = VSpace(defskip);
696 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
698 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
699 } else if (token == "\\quotes_language") {
702 quotes_language = quoteslangtranslator().find(quotes_lang);
703 } else if (token == "\\papersize") {
706 papersize = papersizetranslator().find(ppsize);
707 } else if (token == "\\use_geometry") {
709 } else if (token == "\\use_package") {
714 use_package(package, packagetranslator().find(use));
715 } else if (token == "\\cite_engine") {
717 vector<string> engine = getVectorFromString(lex.getString());
718 setCiteEngine(engine);
719 } else if (token == "\\cite_engine_type") {
722 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
723 } else if (token == "\\biblio_style") {
725 biblio_style = lex.getString();
726 } else if (token == "\\use_bibtopic") {
728 } else if (token == "\\use_indices") {
730 } else if (token == "\\tracking_changes") {
732 } else if (token == "\\output_changes") {
733 lex >> outputChanges;
734 } else if (token == "\\branch") {
736 docstring branch = lex.getDocString();
737 branchlist().add(branch);
740 string const tok = lex.getString();
741 if (tok == "\\end_branch")
743 Branch * branch_ptr = branchlist().find(branch);
744 if (tok == "\\selected") {
747 branch_ptr->setSelected(lex.getInteger());
749 if (tok == "\\filename_suffix") {
752 branch_ptr->setFileNameSuffix(lex.getInteger());
754 if (tok == "\\color") {
756 string color = lex.getString();
758 branch_ptr->setColor(color);
759 // Update also the Color table:
761 color = lcolor.getX11Name(Color_background);
763 lcolor.setColor(to_utf8(branch), color);
766 } else if (token == "\\index") {
768 docstring index = lex.getDocString();
770 indiceslist().add(index);
773 string const tok = lex.getString();
774 if (tok == "\\end_index")
776 Index * index_ptr = indiceslist().find(index);
777 if (tok == "\\shortcut") {
779 shortcut = lex.getDocString();
781 index_ptr->setShortcut(shortcut);
783 if (tok == "\\color") {
785 string color = lex.getString();
787 index_ptr->setColor(color);
788 // Update also the Color table:
790 color = lcolor.getX11Name(Color_background);
792 if (!shortcut.empty())
793 lcolor.setColor(to_utf8(shortcut), color);
796 } else if (token == "\\author") {
798 istringstream ss(lex.getString());
801 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
802 } else if (token == "\\paperorientation") {
805 orientation = paperorientationtranslator().find(orient);
806 } else if (token == "\\backgroundcolor") {
808 backgroundcolor = lyx::rgbFromHexName(lex.getString());
809 isbackgroundcolor = true;
810 } else if (token == "\\fontcolor") {
812 fontcolor = lyx::rgbFromHexName(lex.getString());
814 } else if (token == "\\notefontcolor") {
816 string color = lex.getString();
817 notefontcolor = lyx::rgbFromHexName(color);
818 } else if (token == "\\boxbgcolor") {
820 string color = lex.getString();
821 boxbgcolor = lyx::rgbFromHexName(color);
822 } else if (token == "\\paperwidth") {
824 } else if (token == "\\paperheight") {
826 } else if (token == "\\leftmargin") {
828 } else if (token == "\\topmargin") {
830 } else if (token == "\\rightmargin") {
832 } else if (token == "\\bottommargin") {
834 } else if (token == "\\headheight") {
836 } else if (token == "\\headsep") {
838 } else if (token == "\\footskip") {
840 } else if (token == "\\columnsep") {
842 } else if (token == "\\paperfontsize") {
844 } else if (token == "\\papercolumns") {
846 } else if (token == "\\listings_params") {
849 listings_params = InsetListingsParams(par).params();
850 } else if (token == "\\papersides") {
853 sides = sidestranslator().find(psides);
854 } else if (token == "\\paperpagestyle") {
856 } else if (token == "\\bullet") {
858 } else if (token == "\\bulletLaTeX") {
859 readBulletsLaTeX(lex);
860 } else if (token == "\\secnumdepth") {
862 } else if (token == "\\tocdepth") {
864 } else if (token == "\\spacing") {
868 if (nspacing == "other") {
871 spacing().set(spacetranslator().find(nspacing), tmp_val);
872 } else if (token == "\\float_placement") {
873 lex >> float_placement;
875 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
876 string toktmp = pdfoptions().readToken(lex, token);
877 if (!toktmp.empty()) {
878 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
882 } else if (token == "\\html_math_output") {
885 html_math_output = static_cast<MathOutput>(temp);
886 } else if (token == "\\html_be_strict") {
887 lex >> html_be_strict;
888 } else if (token == "\\html_css_as_file") {
889 lex >> html_css_as_file;
890 } else if (token == "\\html_math_img_scale") {
891 lex >> html_math_img_scale;
892 } else if (token == "\\html_latex_start") {
894 html_latex_start = lex.getString();
895 } else if (token == "\\html_latex_end") {
897 html_latex_end = lex.getString();
898 } else if (token == "\\output_sync") {
900 } else if (token == "\\output_sync_macro") {
901 lex >> output_sync_macro;
902 } else if (token == "\\use_refstyle") {
905 lyxerr << "BufferParams::readToken(): Unknown token: " <<
914 void BufferParams::writeFile(ostream & os) const
916 // The top of the file is written by the buffer.
917 // Prints out the buffer info into the .lyx file given by file
920 os << "\\textclass " << baseClass()->name() << '\n';
923 if (!preamble.empty()) {
924 // remove '\n' from the end of preamble
925 string const tmppreamble = rtrim(preamble, "\n");
926 os << "\\begin_preamble\n"
928 << "\n\\end_preamble\n";
932 if (!options.empty()) {
933 os << "\\options " << options << '\n';
936 // use the class options defined in the layout?
937 os << "\\use_default_options "
938 << convert<string>(use_default_options) << "\n";
940 // the master document
941 if (!master.empty()) {
942 os << "\\master " << master << '\n';
946 if (!removed_modules_.empty()) {
947 os << "\\begin_removed_modules" << '\n';
948 list<string>::const_iterator it = removed_modules_.begin();
949 list<string>::const_iterator en = removed_modules_.end();
950 for (; it != en; ++it)
952 os << "\\end_removed_modules" << '\n';
956 if (!layout_modules_.empty()) {
957 os << "\\begin_modules" << '\n';
958 LayoutModuleList::const_iterator it = layout_modules_.begin();
959 LayoutModuleList::const_iterator en = layout_modules_.end();
960 for (; it != en; ++it)
962 os << "\\end_modules" << '\n';
966 if (!included_children_.empty()) {
967 os << "\\begin_includeonly" << '\n';
968 list<string>::const_iterator it = included_children_.begin();
969 list<string>::const_iterator en = included_children_.end();
970 for (; it != en; ++it)
972 os << "\\end_includeonly" << '\n';
974 os << "\\maintain_unincluded_children "
975 << convert<string>(maintain_unincluded_children) << '\n';
977 // local layout information
978 if (!local_layout.empty()) {
979 // remove '\n' from the end
980 string const tmplocal = rtrim(local_layout, "\n");
981 os << "\\begin_local_layout\n"
983 << "\n\\end_local_layout\n";
986 // then the text parameters
987 if (language != ignore_language)
988 os << "\\language " << language->lang() << '\n';
989 os << "\\language_package " << lang_package
990 << "\n\\inputencoding " << inputenc
991 << "\n\\fontencoding " << fontenc
992 << "\n\\font_roman " << fonts_roman
993 << "\n\\font_sans " << fonts_sans
994 << "\n\\font_typewriter " << fonts_typewriter
995 << "\n\\font_math " << fonts_math
996 << "\n\\font_default_family " << fonts_default_family
997 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
998 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
999 << "\n\\font_osf " << convert<string>(fonts_old_figures)
1000 << "\n\\font_sf_scale " << fonts_sans_scale
1001 << "\n\\font_tt_scale " << fonts_typewriter_scale
1003 if (!fonts_cjk.empty()) {
1004 os << "\\font_cjk " << fonts_cjk << '\n';
1006 os << "\\graphics " << graphics_driver << '\n';
1007 os << "\\default_output_format " << default_output_format << '\n';
1008 os << "\\output_sync " << output_sync << '\n';
1009 if (!output_sync_macro.empty())
1010 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1011 os << "\\bibtex_command " << bibtex_command << '\n';
1012 os << "\\index_command " << index_command << '\n';
1014 if (!float_placement.empty()) {
1015 os << "\\float_placement " << float_placement << '\n';
1017 os << "\\paperfontsize " << fontsize << '\n';
1019 spacing().writeFile(os);
1020 pdfoptions().writeFile(os);
1022 os << "\\papersize " << string_papersize[papersize]
1023 << "\n\\use_geometry " << convert<string>(use_geometry);
1024 vector<string> const & packages = auto_packages();
1025 for (size_t i = 0; i < packages.size(); ++i)
1026 os << "\n\\use_package " << packages[i] << ' '
1027 << use_package(packages[i]);
1029 os << "\n\\cite_engine ";
1031 if (!cite_engine_.empty()) {
1032 LayoutModuleList::const_iterator be = cite_engine_.begin();
1033 LayoutModuleList::const_iterator en = cite_engine_.end();
1034 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1043 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1044 << "\n\\biblio_style " << biblio_style
1045 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1046 << "\n\\use_indices " << convert<string>(use_indices)
1047 << "\n\\paperorientation " << string_orientation[orientation]
1048 << "\n\\suppress_date " << convert<string>(suppress_date)
1049 << "\n\\justification " << convert<string>(justification)
1050 << "\n\\use_refstyle " << use_refstyle
1052 if (isbackgroundcolor == true)
1053 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1054 if (isfontcolor == true)
1055 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1056 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1057 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1058 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1059 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1061 BranchList::const_iterator it = branchlist().begin();
1062 BranchList::const_iterator end = branchlist().end();
1063 for (; it != end; ++it) {
1064 os << "\\branch " << to_utf8(it->branch())
1065 << "\n\\selected " << it->isSelected()
1066 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1067 << "\n\\color " << lyx::X11hexname(it->color())
1072 IndicesList::const_iterator iit = indiceslist().begin();
1073 IndicesList::const_iterator iend = indiceslist().end();
1074 for (; iit != iend; ++iit) {
1075 os << "\\index " << to_utf8(iit->index())
1076 << "\n\\shortcut " << to_utf8(iit->shortcut())
1077 << "\n\\color " << lyx::X11hexname(iit->color())
1082 if (!paperwidth.empty())
1083 os << "\\paperwidth "
1084 << VSpace(paperwidth).asLyXCommand() << '\n';
1085 if (!paperheight.empty())
1086 os << "\\paperheight "
1087 << VSpace(paperheight).asLyXCommand() << '\n';
1088 if (!leftmargin.empty())
1089 os << "\\leftmargin "
1090 << VSpace(leftmargin).asLyXCommand() << '\n';
1091 if (!topmargin.empty())
1092 os << "\\topmargin "
1093 << VSpace(topmargin).asLyXCommand() << '\n';
1094 if (!rightmargin.empty())
1095 os << "\\rightmargin "
1096 << VSpace(rightmargin).asLyXCommand() << '\n';
1097 if (!bottommargin.empty())
1098 os << "\\bottommargin "
1099 << VSpace(bottommargin).asLyXCommand() << '\n';
1100 if (!headheight.empty())
1101 os << "\\headheight "
1102 << VSpace(headheight).asLyXCommand() << '\n';
1103 if (!headsep.empty())
1105 << VSpace(headsep).asLyXCommand() << '\n';
1106 if (!footskip.empty())
1108 << VSpace(footskip).asLyXCommand() << '\n';
1109 if (!columnsep.empty())
1110 os << "\\columnsep "
1111 << VSpace(columnsep).asLyXCommand() << '\n';
1112 os << "\\secnumdepth " << secnumdepth
1113 << "\n\\tocdepth " << tocdepth
1114 << "\n\\paragraph_separation "
1115 << string_paragraph_separation[paragraph_separation];
1116 if (!paragraph_separation)
1117 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1119 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1120 os << "\n\\quotes_language "
1121 << string_quotes_language[quotes_language]
1122 << "\n\\papercolumns " << columns
1123 << "\n\\papersides " << sides
1124 << "\n\\paperpagestyle " << pagestyle << '\n';
1125 if (!listings_params.empty())
1126 os << "\\listings_params \"" <<
1127 InsetListingsParams(listings_params).encodedString() << "\"\n";
1128 for (int i = 0; i < 4; ++i) {
1129 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1130 if (user_defined_bullet(i).getFont() != -1) {
1131 os << "\\bullet " << i << " "
1132 << user_defined_bullet(i).getFont() << " "
1133 << user_defined_bullet(i).getCharacter() << " "
1134 << user_defined_bullet(i).getSize() << "\n";
1138 os << "\\bulletLaTeX " << i << " \""
1139 << lyx::to_ascii(user_defined_bullet(i).getText())
1145 os << "\\tracking_changes " << convert<string>(trackChanges) << '\n'
1146 << "\\output_changes " << convert<string>(outputChanges) << '\n'
1147 << "\\html_math_output " << html_math_output << '\n'
1148 << "\\html_css_as_file " << html_css_as_file << '\n'
1149 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1151 if (html_math_img_scale != 1.0)
1152 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1153 if (!html_latex_start.empty())
1154 os << "\\html_latex_start " << html_latex_start << '\n';
1155 if (!html_latex_end.empty())
1156 os << "\\html_latex_end " << html_latex_end << '\n';
1158 os << pimpl_->authorlist;
1162 void BufferParams::validate(LaTeXFeatures & features) const
1164 features.require(documentClass().requires());
1166 if (columns > 1 && language->rightToLeft())
1167 features.require("rtloutputdblcol");
1169 if (outputChanges) {
1170 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1171 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1172 LaTeXFeatures::isAvailable("xcolor");
1174 switch (features.runparams().flavor) {
1175 case OutputParams::LATEX:
1176 case OutputParams::DVILUATEX:
1178 features.require("ct-dvipost");
1179 features.require("dvipost");
1180 } else if (xcolorulem) {
1181 features.require("ct-xcolor-ulem");
1182 features.require("ulem");
1183 features.require("xcolor");
1185 features.require("ct-none");
1188 case OutputParams::LUATEX:
1189 case OutputParams::PDFLATEX:
1190 case OutputParams::XETEX:
1192 features.require("ct-xcolor-ulem");
1193 features.require("ulem");
1194 features.require("xcolor");
1195 // improves color handling in PDF output
1196 features.require("pdfcolmk");
1198 features.require("ct-none");
1206 // Floats with 'Here definitely' as default setting.
1207 if (float_placement.find('H') != string::npos)
1208 features.require("float");
1210 for (PackageMap::const_iterator it = use_packages.begin();
1211 it != use_packages.end(); ++it) {
1212 if (it->first == "amsmath") {
1213 // AMS Style is at document level
1214 if (it->second == package_on ||
1215 features.isProvided("amsmath"))
1216 features.require(it->first);
1217 } else if (it->second == package_on)
1218 features.require(it->first);
1221 // Document-level line spacing
1222 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1223 features.require("setspace");
1225 // the bullet shapes are buffer level not paragraph level
1226 // so they are tested here
1227 for (int i = 0; i < 4; ++i) {
1228 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1230 int const font = user_defined_bullet(i).getFont();
1232 int const c = user_defined_bullet(i).getCharacter();
1238 features.require("latexsym");
1240 } else if (font == 1) {
1241 features.require("amssymb");
1242 } else if (font >= 2 && font <= 5) {
1243 features.require("pifont");
1247 if (pdfoptions().use_hyperref) {
1248 features.require("hyperref");
1249 // due to interferences with babel and hyperref, the color package has to
1250 // be loaded after hyperref when hyperref is used with the colorlinks
1251 // option, see http://www.lyx.org/trac/ticket/5291
1252 if (pdfoptions().colorlinks)
1253 features.require("color");
1256 // some languages are only available via polyglossia
1257 if (features.runparams().flavor == OutputParams::XETEX
1258 && (features.hasPolyglossiaExclusiveLanguages()
1260 features.require("polyglossia");
1262 if (useNonTeXFonts && fonts_math != "auto")
1263 features.require("unicode-math");
1265 if (!language->requires().empty())
1266 features.require(language->requires());
1270 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1271 FileName const & filepath) const
1273 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1274 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1275 // \RequirePackage to do so, rather than the normal \usepackage
1276 // Do not try to load any other package before the document class, unless you
1277 // have a thorough understanding of the LATEX internals and know exactly what you
1279 if (features.mustProvide("fix-cm"))
1280 os << "\\RequirePackage{fix-cm}\n";
1282 os << "\\documentclass";
1284 DocumentClass const & tclass = documentClass();
1286 ostringstream clsoptions; // the document class options.
1288 if (tokenPos(tclass.opt_fontsize(),
1289 '|', fontsize) >= 0) {
1290 // only write if existing in list (and not default)
1291 clsoptions << fontsize << "pt,";
1294 // all paper sizes except of A4, A5, B5 and the US sizes need the
1296 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1297 && papersize != PAPER_USLETTER
1298 && papersize != PAPER_USLEGAL
1299 && papersize != PAPER_USEXECUTIVE
1300 && papersize != PAPER_A4
1301 && papersize != PAPER_A5
1302 && papersize != PAPER_B5;
1304 if (!use_geometry) {
1305 switch (papersize) {
1307 clsoptions << "a4paper,";
1309 case PAPER_USLETTER:
1310 clsoptions << "letterpaper,";
1313 clsoptions << "a5paper,";
1316 clsoptions << "b5paper,";
1318 case PAPER_USEXECUTIVE:
1319 clsoptions << "executivepaper,";
1322 clsoptions << "legalpaper,";
1356 if (sides != tclass.sides()) {
1359 clsoptions << "oneside,";
1362 clsoptions << "twoside,";
1368 if (columns != tclass.columns()) {
1370 clsoptions << "twocolumn,";
1372 clsoptions << "onecolumn,";
1376 && orientation == ORIENTATION_LANDSCAPE)
1377 clsoptions << "landscape,";
1379 // language should be a parameter to \documentclass
1380 if (language->babel() == "hebrew"
1381 && default_language->babel() != "hebrew")
1382 // This seems necessary
1383 features.useLanguage(default_language);
1385 ostringstream language_options;
1386 bool const use_babel = features.useBabel() && !features.isProvided("babel");
1387 bool const use_polyglossia = features.usePolyglossia();
1388 bool const global = lyxrc.language_global_options;
1389 if (use_babel || (use_polyglossia && global)) {
1390 language_options << features.getBabelLanguages();
1391 if (!language->babel().empty()) {
1392 if (!language_options.str().empty())
1393 language_options << ',';
1394 language_options << language->babel();
1396 if (global && !features.needBabelLangOptions()
1397 && !language_options.str().empty())
1398 clsoptions << language_options.str() << ',';
1401 // the predefined options from the layout
1402 if (use_default_options && !tclass.options().empty())
1403 clsoptions << tclass.options() << ',';
1405 // the user-defined options
1406 if (!options.empty()) {
1407 clsoptions << options << ',';
1410 string strOptions(clsoptions.str());
1411 if (!strOptions.empty()) {
1412 strOptions = rtrim(strOptions, ",");
1414 os << '[' << from_utf8(strOptions) << ']';
1417 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1418 // end of \documentclass defs
1420 // if we use fontspec, we have to load the AMS packages here
1421 string const ams = features.loadAMSPackages();
1422 if (useNonTeXFonts && !ams.empty())
1423 os << from_ascii(ams);
1425 if (useNonTeXFonts) {
1426 os << "\\usepackage{fontspec}\n";
1427 if (features.mustProvide("unicode-math")
1428 && features.isAvailable("unicode-math"))
1429 os << "\\usepackage{unicode-math}\n";
1432 // font selection must be done before loading fontenc.sty
1433 string const fonts = loadFonts(features);
1435 os << from_utf8(fonts);
1437 if (fonts_default_family != "default")
1438 os << "\\renewcommand{\\familydefault}{\\"
1439 << from_ascii(fonts_default_family) << "}\n";
1441 // set font encoding
1442 // for arabic_arabi and farsi we also need to load the LAE and
1444 // XeTeX and LuaTeX (with OS fonts) work without fontenc
1445 if (font_encoding() != "default" && language->lang() != "japanese"
1446 && !useNonTeXFonts && !features.isProvided("fontenc")) {
1447 size_t fars = language_options.str().find("farsi");
1448 size_t arab = language_options.str().find("arabic");
1449 if (language->lang() == "arabic_arabi"
1450 || language->lang() == "farsi" || fars != string::npos
1451 || arab != string::npos) {
1452 os << "\\usepackage[" << from_ascii(font_encoding())
1453 << ",LFE,LAE]{fontenc}\n";
1455 os << "\\usepackage[" << from_ascii(font_encoding())
1460 // handle inputenc etc.
1461 writeEncodingPreamble(os, features);
1464 if (!features.runparams().includeall && !included_children_.empty()) {
1465 os << "\\includeonly{";
1466 list<string>::const_iterator it = included_children_.begin();
1467 list<string>::const_iterator en = included_children_.end();
1469 for (; it != en; ++it) {
1470 string incfile = *it;
1471 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1472 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1474 if (!features.runparams().nice)
1476 // \includeonly doesn't want an extension
1477 incfile = changeExtension(incfile, string());
1478 incfile = support::latex_path(incfile);
1479 if (!incfile.empty()) {
1482 os << from_utf8(incfile);
1489 if (!listings_params.empty() || features.isRequired("listings"))
1490 os << "\\usepackage{listings}\n";
1492 if (!listings_params.empty()) {
1494 // do not test validity because listings_params is
1495 // supposed to be valid
1497 InsetListingsParams(listings_params).separatedParams(true);
1498 // we can't support all packages, but we should load the color package
1499 if (par.find("\\color", 0) != string::npos)
1500 features.require("color");
1501 os << from_utf8(par)
1504 if (!features.isProvided("geometry")
1505 && (use_geometry || nonstandard_papersize)) {
1506 odocstringstream ods;
1507 if (!getGraphicsDriver("geometry").empty())
1508 ods << getGraphicsDriver("geometry");
1509 if (orientation == ORIENTATION_LANDSCAPE)
1510 ods << ",landscape";
1511 switch (papersize) {
1513 if (!paperwidth.empty())
1514 ods << ",paperwidth="
1515 << from_ascii(paperwidth);
1516 if (!paperheight.empty())
1517 ods << ",paperheight="
1518 << from_ascii(paperheight);
1520 case PAPER_USLETTER:
1521 ods << ",letterpaper";
1524 ods << ",legalpaper";
1526 case PAPER_USEXECUTIVE:
1527 ods << ",executivepaper";
1616 docstring const g_options = trim(ods.str(), ",");
1617 os << "\\usepackage";
1618 if (!g_options.empty())
1619 os << '[' << g_options << ']';
1620 os << "{geometry}\n";
1621 // output this only if use_geometry is true
1623 os << "\\geometry{verbose";
1624 if (!topmargin.empty())
1625 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1626 if (!bottommargin.empty())
1627 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1628 if (!leftmargin.empty())
1629 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1630 if (!rightmargin.empty())
1631 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1632 if (!headheight.empty())
1633 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1634 if (!headsep.empty())
1635 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1636 if (!footskip.empty())
1637 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1638 if (!columnsep.empty())
1639 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1642 } else if (orientation == ORIENTATION_LANDSCAPE
1643 || papersize != PAPER_DEFAULT) {
1644 features.require("papersize");
1647 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1648 if (pagestyle == "fancy")
1649 os << "\\usepackage{fancyhdr}\n";
1650 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1653 // only output when the background color is not default
1654 if (isbackgroundcolor == true) {
1655 // only require color here, the background color will be defined
1656 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1658 features.require("color");
1659 features.require("pagecolor");
1662 // only output when the font color is not default
1663 if (isfontcolor == true) {
1664 // only require color here, the font color will be defined
1665 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1667 features.require("color");
1668 features.require("fontcolor");
1671 // Only if class has a ToC hierarchy
1672 if (tclass.hasTocLevels()) {
1673 if (secnumdepth != tclass.secnumdepth()) {
1674 os << "\\setcounter{secnumdepth}{"
1678 if (tocdepth != tclass.tocdepth()) {
1679 os << "\\setcounter{tocdepth}{"
1685 if (paragraph_separation) {
1686 // when skip separation
1687 switch (getDefSkip().kind()) {
1688 case VSpace::SMALLSKIP:
1689 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1691 case VSpace::MEDSKIP:
1692 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1694 case VSpace::BIGSKIP:
1695 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1697 case VSpace::LENGTH:
1698 os << "\\setlength{\\parskip}{"
1699 << from_utf8(getDefSkip().length().asLatexString())
1702 default: // should never happen // Then delete it.
1703 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1706 os << "\\setlength{\\parindent}{0pt}\n";
1708 // when separation by indentation
1709 // only output something when a width is given
1710 if (getIndentation().asLyXCommand() != "default") {
1711 os << "\\setlength{\\parindent}{"
1712 << from_utf8(getIndentation().asLatexCommand())
1717 // Now insert the LyX specific LaTeX commands...
1718 docstring lyxpreamble;
1719 features.resolveAlternatives();
1722 if (!output_sync_macro.empty())
1723 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1724 else if (features.runparams().flavor == OutputParams::LATEX)
1725 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1726 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1727 lyxpreamble += "\\synctex=-1\n";
1730 // due to interferences with babel and hyperref, the color package has to
1731 // be loaded (when it is not already loaded) before babel when hyperref
1732 // is used with the colorlinks option, see
1733 // http://www.lyx.org/trac/ticket/5291
1734 // we decided therefore to load color always before babel, see
1735 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1736 lyxpreamble += from_ascii(features.getColorOptions());
1738 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1740 && (features.isRequired("jurabib")
1741 || features.isRequired("hyperref")
1742 || features.isRequired("vietnamese")
1743 || features.isRequired("japanese"))) {
1745 lyxpreamble += from_utf8(features.getBabelPresettings());
1746 lyxpreamble += from_utf8(babelCall(language_options.str(),
1747 features.needBabelLangOptions())) + '\n';
1748 lyxpreamble += from_utf8(features.getBabelPostsettings());
1751 // The optional packages;
1752 lyxpreamble += from_ascii(features.getPackages());
1754 // Additional Indices
1755 if (features.isRequired("splitidx")) {
1756 IndicesList::const_iterator iit = indiceslist().begin();
1757 IndicesList::const_iterator iend = indiceslist().end();
1758 for (; iit != iend; ++iit) {
1759 pair<docstring, docstring> indexname_latex =
1760 features.runparams().encoding->latexString(iit->index(),
1761 features.runparams().dryrun);
1762 if (!indexname_latex.second.empty()) {
1763 // issue a warning about omitted characters
1764 // FIXME: should be passed to the error dialog
1765 frontend::Alert::warning(_("Uncodable characters"),
1766 bformat(_("The following characters that are used in an index name are not\n"
1767 "representable in the current encoding and therefore have been omitted:\n%1$s."),
1768 indexname_latex.second));
1770 lyxpreamble += "\\newindex[";
1771 lyxpreamble += indexname_latex.first;
1772 lyxpreamble += "]{";
1773 lyxpreamble += escape(iit->shortcut());
1774 lyxpreamble += "}\n";
1779 lyxpreamble += from_utf8(spacing().writePreamble(features.isProvided("SetSpace")));
1782 // * Hyperref manual: "Make sure it comes last of your loaded
1783 // packages, to give it a fighting chance of not being over-written,
1784 // since its job is to redefine many LaTeX commands."
1785 // * Email from Heiko Oberdiek: "It is usually better to load babel
1786 // before hyperref. Then hyperref has a chance to detect babel.
1787 // * Has to be loaded before the "LyX specific LaTeX commands" to
1788 // avoid errors with algorithm floats.
1789 // use hyperref explicitly if it is required
1790 if (features.isRequired("hyperref")) {
1791 // pass what we have to stream here, since we need
1792 // to access the stream itself in PDFOptions.
1795 OutputParams tmp_params = features.runparams();
1796 pdfoptions().writeLaTeX(tmp_params, os,
1797 features.isProvided("hyperref"));
1798 // set back for the rest
1799 lyxpreamble.clear();
1800 // correctly break URLs with hyperref and dvi output
1801 if (features.runparams().flavor == OutputParams::LATEX
1802 && features.isAvailable("breakurl"))
1803 lyxpreamble += "\\usepackage{breakurl}\n";
1804 } else if (features.isRequired("nameref"))
1805 // hyperref loads this automatically
1806 lyxpreamble += "\\usepackage{nameref}\n";
1808 // bibtopic needs to be loaded after hyperref.
1809 // the dot provides the aux file naming which LyX can detect.
1810 if (features.mustProvide("bibtopic"))
1811 lyxpreamble += "\\usepackage[dot]{bibtopic}\n";
1813 // Will be surrounded by \makeatletter and \makeatother when not empty
1814 docstring atlyxpreamble;
1816 // Some macros LyX will need
1817 docstring tmppreamble(features.getMacros());
1819 if (!tmppreamble.empty())
1820 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1821 "LyX specific LaTeX commands.\n"
1822 + tmppreamble + '\n';
1824 // the text class specific preamble
1825 tmppreamble = features.getTClassPreamble();
1826 if (!tmppreamble.empty())
1827 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1828 "Textclass specific LaTeX commands.\n"
1829 + tmppreamble + '\n';
1831 // suppress date if selected
1832 // use \@ifundefined because we cannot be sure that every document class
1833 // has a \date command
1835 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1837 /* the user-defined preamble */
1838 if (!containsOnly(preamble, " \n\t"))
1840 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1841 "User specified LaTeX commands.\n"
1842 + from_utf8(preamble) + '\n';
1844 // subfig loads internally the LaTeX package "caption". As
1845 // caption is a very popular package, users will load it in
1846 // the preamble. Therefore we must load subfig behind the
1847 // user-defined preamble and check if the caption package was
1848 // loaded or not. For the case that caption is loaded before
1849 // subfig, there is the subfig option "caption=false". This
1850 // option also works when a koma-script class is used and
1851 // koma's own caption commands are used instead of caption. We
1852 // use \PassOptionsToPackage here because the user could have
1853 // already loaded subfig in the preamble.
1854 if (features.isRequired("subfig")) {
1855 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1856 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1857 "\\usepackage{subfig}\n";
1860 // Itemize bullet settings need to be last in case the user
1861 // defines their own bullets that use a package included
1862 // in the user-defined preamble -- ARRae
1863 // Actually it has to be done much later than that
1864 // since some packages like frenchb make modifications
1865 // at \begin{document} time -- JMarc
1866 docstring bullets_def;
1867 for (int i = 0; i < 4; ++i) {
1868 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1869 if (bullets_def.empty())
1870 bullets_def += "\\AtBeginDocument{\n";
1871 bullets_def += " \\def\\labelitemi";
1873 // `i' is one less than the item to modify
1880 bullets_def += "ii";
1886 bullets_def += '{' +
1887 user_defined_bullet(i).getText()
1892 if (!bullets_def.empty())
1893 atlyxpreamble += bullets_def + "}\n\n";
1895 if (!atlyxpreamble.empty())
1896 lyxpreamble += "\n\\makeatletter\n"
1897 + atlyxpreamble + "\\makeatother\n\n";
1899 // We try to load babel late, in case it interferes with other packages.
1900 // Jurabib and Hyperref have to be called after babel, though.
1901 if (use_babel && !features.isRequired("jurabib")
1902 && !features.isRequired("hyperref")
1903 && !features.isRequired("vietnamese")
1904 && !features.isRequired("japanese")) {
1906 lyxpreamble += from_utf8(features.getBabelPresettings());
1907 lyxpreamble += from_utf8(babelCall(language_options.str(),
1908 features.needBabelLangOptions())) + '\n';
1909 lyxpreamble += from_utf8(features.getBabelPostsettings());
1912 // xunicode needs to be loaded at least after amsmath, amssymb,
1913 // esint and the other packages that provide special glyphs
1914 if (features.runparams().flavor == OutputParams::XETEX)
1915 lyxpreamble += "\\usepackage{xunicode}\n";
1917 // Polyglossia must be loaded last
1918 if (use_polyglossia) {
1920 lyxpreamble += "\\usepackage{polyglossia}\n";
1921 // set the main language
1922 lyxpreamble += "\\setdefaultlanguage";
1923 if (!language->polyglossiaOpts().empty())
1924 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
1925 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
1926 // now setup the other languages
1927 std::map<std::string, std::string> const polylangs =
1928 features.getPolyglossiaLanguages();
1929 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
1930 mit != polylangs.end() ; ++mit) {
1931 lyxpreamble += "\\setotherlanguage";
1932 if (!mit->second.empty())
1933 lyxpreamble += "[" + from_ascii(mit->second) + "]";
1934 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
1938 // Load custom language package here
1939 if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
1940 if (lang_package == "default")
1941 lyxpreamble += from_utf8(lyxrc.language_custom_package);
1943 lyxpreamble += from_utf8(lang_package);
1944 lyxpreamble += '\n';
1947 docstring const i18npreamble =
1948 features.getTClassI18nPreamble(use_babel, use_polyglossia);
1949 if (!i18npreamble.empty())
1950 lyxpreamble += i18npreamble + '\n';
1958 void BufferParams::useClassDefaults()
1960 DocumentClass const & tclass = documentClass();
1962 sides = tclass.sides();
1963 columns = tclass.columns();
1964 pagestyle = tclass.pagestyle();
1965 use_default_options = true;
1966 // Only if class has a ToC hierarchy
1967 if (tclass.hasTocLevels()) {
1968 secnumdepth = tclass.secnumdepth();
1969 tocdepth = tclass.tocdepth();
1974 bool BufferParams::hasClassDefaults() const
1976 DocumentClass const & tclass = documentClass();
1978 return sides == tclass.sides()
1979 && columns == tclass.columns()
1980 && pagestyle == tclass.pagestyle()
1981 && use_default_options
1982 && secnumdepth == tclass.secnumdepth()
1983 && tocdepth == tclass.tocdepth();
1987 DocumentClass const & BufferParams::documentClass() const
1989 return *doc_class_.get();
1993 DocumentClassConstPtr BufferParams::documentClassPtr() const
1999 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
2001 // evil, but this function is evil
2002 doc_class_ = const_pointer_cast<DocumentClass>(tc);
2006 bool BufferParams::setBaseClass(string const & classname)
2008 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
2009 LayoutFileList & bcl = LayoutFileList::get();
2010 if (!bcl.haveClass(classname)) {
2012 bformat(_("The layout file:\n"
2014 "could not be found. A default textclass with default\n"
2015 "layouts will be used. LyX will not be able to produce\n"
2017 from_utf8(classname));
2018 frontend::Alert::error(_("Document class not found"), s);
2019 bcl.addEmptyClass(classname);
2022 bool const success = bcl[classname].load();
2025 bformat(_("Due to some error in it, the layout file:\n"
2027 "could not be loaded. A default textclass with default\n"
2028 "layouts will be used. LyX will not be able to produce\n"
2030 from_utf8(classname));
2031 frontend::Alert::error(_("Could not load class"), s);
2032 bcl.addEmptyClass(classname);
2035 pimpl_->baseClass_ = classname;
2036 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2041 LayoutFile const * BufferParams::baseClass() const
2043 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2044 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2050 LayoutFileIndex const & BufferParams::baseClassID() const
2052 return pimpl_->baseClass_;
2056 void BufferParams::makeDocumentClass()
2061 LayoutModuleList mods;
2062 LayoutModuleList::iterator it;
2063 LayoutModuleList::iterator en;
2065 it = layout_modules_.begin();
2066 en = layout_modules_.end();
2067 for (; it != en; ++it)
2068 mods.push_back(*it);
2069 it = cite_engine_.begin();
2070 en = cite_engine_.end();
2071 for (; it != en; ++it)
2072 mods.push_back(*it);
2073 doc_class_ = getDocumentClass(*baseClass(), mods);
2075 if (!local_layout.empty()) {
2076 TextClass::ReturnValues success =
2077 doc_class_->read(local_layout, TextClass::MODULE);
2078 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2079 docstring const msg = _("Error reading internal layout information");
2080 frontend::Alert::warning(_("Read Error"), msg);
2086 bool BufferParams::moduleCanBeAdded(string const & modName) const
2088 return cite_engine_.moduleCanBeAdded(modName, baseClass()) &&
2089 layout_modules_.moduleCanBeAdded(modName, baseClass());
2093 bool BufferParams::addLayoutModule(string const & modName)
2095 LayoutModuleList::const_iterator it = layout_modules_.begin();
2096 LayoutModuleList::const_iterator end = layout_modules_.end();
2097 for (; it != end; ++it)
2100 layout_modules_.push_back(modName);
2105 string BufferParams::bufferFormat() const
2107 string format = documentClass().outputFormat();
2108 if (format == "latex") {
2111 if (encoding().package() == Encoding::japanese)
2118 bool BufferParams::isExportable(string const & format) const
2120 vector<string> backs = backends();
2121 for (vector<string>::const_iterator it = backs.begin();
2122 it != backs.end(); ++it)
2123 if (theConverters().isReachable(*it, format))
2130 bool formatSorter(Format const * lhs, Format const * rhs) {
2131 return _(lhs->prettyname()) < _(rhs->prettyname());
2136 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2138 vector<string> const backs = backends();
2139 set<string> excludes;
2140 if (useNonTeXFonts) {
2141 excludes.insert("latex");
2142 excludes.insert("pdflatex");
2144 vector<Format const *> result =
2145 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2146 for (vector<string>::const_iterator it = backs.begin() + 1;
2147 it != backs.end(); ++it) {
2148 vector<Format const *> r =
2149 theConverters().getReachable(*it, only_viewable, false, excludes);
2150 result.insert(result.end(), r.begin(), r.end());
2152 sort(result.begin(), result.end(), formatSorter);
2157 bool BufferParams::isExportableFormat(string const & format) const
2159 typedef vector<Format const *> Formats;
2161 formats = exportableFormats(true);
2162 Formats::const_iterator fit = formats.begin();
2163 Formats::const_iterator end = formats.end();
2164 for (; fit != end ; ++fit) {
2165 if ((*fit)->name() == format)
2172 vector<string> BufferParams::backends() const
2175 string const buffmt = bufferFormat();
2177 // FIXME: Don't hardcode format names here, but use a flag
2178 if (buffmt == "latex") {
2179 if (!useNonTeXFonts) {
2180 v.push_back("pdflatex");
2181 v.push_back("latex");
2183 v.push_back("luatex");
2184 v.push_back("dviluatex");
2185 v.push_back("xetex");
2186 } else if (buffmt == "xetex") {
2187 v.push_back("xetex");
2188 v.push_back("luatex");
2189 v.push_back("dviluatex");
2191 v.push_back(buffmt);
2193 v.push_back("xhtml");
2194 v.push_back("text");
2200 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
2202 string const dformat = (format.empty() || format == "default") ?
2203 getDefaultOutputFormat() : format;
2204 DefaultFlavorCache::const_iterator it =
2205 default_flavors_.find(dformat);
2207 if (it != default_flavors_.end())
2210 OutputParams::FLAVOR result = OutputParams::LATEX;
2212 // FIXME It'd be better not to hardcode this, but to do
2213 // something with formats.
2214 if (dformat == "xhtml")
2215 result = OutputParams::HTML;
2216 else if (dformat == "text")
2217 result = OutputParams::TEXT;
2218 else if (dformat == "lyx")
2219 result = OutputParams::LYX;
2220 else if (dformat == "pdflatex")
2221 result = OutputParams::PDFLATEX;
2222 else if (dformat == "xetex")
2223 result = OutputParams::XETEX;
2224 else if (dformat == "luatex")
2225 result = OutputParams::LUATEX;
2226 else if (dformat == "dviluatex")
2227 result = OutputParams::DVILUATEX;
2229 // Try to determine flavor of default output format
2230 vector<string> backs = backends();
2231 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2232 // Get shortest path to format
2233 Graph::EdgePath path;
2234 for (vector<string>::const_iterator it = backs.begin();
2235 it != backs.end(); ++it) {
2236 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2237 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2242 result = theConverters().getFlavor(path);
2245 // cache this flavor
2246 default_flavors_[dformat] = result;
2251 string BufferParams::getDefaultOutputFormat() const
2253 if (!default_output_format.empty()
2254 && default_output_format != "default")
2255 return default_output_format;
2258 || encoding().package() == Encoding::japanese) {
2259 vector<Format const *> const formats = exportableFormats(true);
2260 if (formats.empty())
2262 // return the first we find
2263 return formats.front()->name();
2265 return lyxrc.default_view_format;
2268 Font const BufferParams::getFont() const
2270 FontInfo f = documentClass().defaultfont();
2271 if (fonts_default_family == "rmdefault")
2272 f.setFamily(ROMAN_FAMILY);
2273 else if (fonts_default_family == "sfdefault")
2274 f.setFamily(SANS_FAMILY);
2275 else if (fonts_default_family == "ttdefault")
2276 f.setFamily(TYPEWRITER_FAMILY);
2277 return Font(f, language);
2281 InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const qs) const
2283 return quoteslangtranslator().find(qs);
2287 bool BufferParams::isLatex() const
2289 return documentClass().outputType() == LATEX;
2293 bool BufferParams::isLiterate() const
2295 return documentClass().outputType() == LITERATE;
2299 bool BufferParams::isDocBook() const
2301 return documentClass().outputType() == DOCBOOK;
2305 void BufferParams::readPreamble(Lexer & lex)
2307 if (lex.getString() != "\\begin_preamble")
2308 lyxerr << "Error (BufferParams::readPreamble):"
2309 "consistency check failed." << endl;
2311 preamble = lex.getLongString("\\end_preamble");
2315 void BufferParams::readLocalLayout(Lexer & lex)
2317 if (lex.getString() != "\\begin_local_layout")
2318 lyxerr << "Error (BufferParams::readLocalLayout):"
2319 "consistency check failed." << endl;
2321 local_layout = lex.getLongString("\\end_local_layout");
2325 bool BufferParams::setLanguage(string const & lang)
2327 Language const *new_language = languages.getLanguage(lang);
2328 if (!new_language) {
2329 // Language lang was not found
2332 language = new_language;
2337 void BufferParams::readLanguage(Lexer & lex)
2339 if (!lex.next()) return;
2341 string const tmptok = lex.getString();
2343 // check if tmptok is part of tex_babel in tex-defs.h
2344 if (!setLanguage(tmptok)) {
2345 // Language tmptok was not found
2346 language = default_language;
2347 lyxerr << "Warning: Setting language `"
2348 << tmptok << "' to `" << language->lang()
2354 void BufferParams::readGraphicsDriver(Lexer & lex)
2359 string const tmptok = lex.getString();
2360 // check if tmptok is part of tex_graphics in tex_defs.h
2363 string const test = tex_graphics[n++];
2365 if (test == tmptok) {
2366 graphics_driver = tmptok;
2371 "Warning: graphics driver `$$Token' not recognized!\n"
2372 " Setting graphics driver to `default'.\n");
2373 graphics_driver = "default";
2380 void BufferParams::readBullets(Lexer & lex)
2385 int const index = lex.getInteger();
2387 int temp_int = lex.getInteger();
2388 user_defined_bullet(index).setFont(temp_int);
2389 temp_bullet(index).setFont(temp_int);
2391 user_defined_bullet(index).setCharacter(temp_int);
2392 temp_bullet(index).setCharacter(temp_int);
2394 user_defined_bullet(index).setSize(temp_int);
2395 temp_bullet(index).setSize(temp_int);
2399 void BufferParams::readBulletsLaTeX(Lexer & lex)
2401 // The bullet class should be able to read this.
2404 int const index = lex.getInteger();
2406 docstring const temp_str = lex.getDocString();
2408 user_defined_bullet(index).setText(temp_str);
2409 temp_bullet(index).setText(temp_str);
2413 void BufferParams::readModules(Lexer & lex)
2415 if (!lex.eatLine()) {
2416 lyxerr << "Error (BufferParams::readModules):"
2417 "Unexpected end of input." << endl;
2421 string mod = lex.getString();
2422 if (mod == "\\end_modules")
2424 addLayoutModule(mod);
2430 void BufferParams::readRemovedModules(Lexer & lex)
2432 if (!lex.eatLine()) {
2433 lyxerr << "Error (BufferParams::readRemovedModules):"
2434 "Unexpected end of input." << endl;
2438 string mod = lex.getString();
2439 if (mod == "\\end_removed_modules")
2441 removed_modules_.push_back(mod);
2444 // now we want to remove any removed modules that were previously
2445 // added. normally, that will be because default modules were added in
2446 // setBaseClass(), which gets called when \textclass is read at the
2447 // start of the read.
2448 list<string>::const_iterator rit = removed_modules_.begin();
2449 list<string>::const_iterator const ren = removed_modules_.end();
2450 for (; rit != ren; ++rit) {
2451 LayoutModuleList::iterator const mit = layout_modules_.begin();
2452 LayoutModuleList::iterator const men = layout_modules_.end();
2453 LayoutModuleList::iterator found = find(mit, men, *rit);
2456 layout_modules_.erase(found);
2461 void BufferParams::readIncludeonly(Lexer & lex)
2463 if (!lex.eatLine()) {
2464 lyxerr << "Error (BufferParams::readIncludeonly):"
2465 "Unexpected end of input." << endl;
2469 string child = lex.getString();
2470 if (child == "\\end_includeonly")
2472 included_children_.push_back(child);
2478 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2480 switch (papersize) {
2482 // could be anything, so don't guess
2484 case PAPER_CUSTOM: {
2485 if (purpose == XDVI && !paperwidth.empty() &&
2486 !paperheight.empty()) {
2487 // heightxwidth<unit>
2488 string first = paperwidth;
2489 string second = paperheight;
2490 if (orientation == ORIENTATION_LANDSCAPE)
2493 return first.erase(first.length() - 2)
2499 // dvips and dvipdfm do not know this
2500 if (purpose == DVIPS || purpose == DVIPDFM)
2504 if (purpose == DVIPS || purpose == DVIPDFM)
2508 if (purpose == DVIPS || purpose == DVIPDFM)
2518 if (purpose == DVIPS || purpose == DVIPDFM)
2522 if (purpose == DVIPS || purpose == DVIPDFM)
2526 if (purpose == DVIPS || purpose == DVIPDFM)
2530 if (purpose == DVIPS || purpose == DVIPDFM)
2534 if (purpose == DVIPS || purpose == DVIPDFM)
2538 // dvipdfm does not know this
2539 if (purpose == DVIPDFM)
2543 if (purpose == DVIPDFM)
2547 if (purpose == DVIPS || purpose == DVIPDFM)
2551 if (purpose == DVIPS || purpose == DVIPDFM)
2555 if (purpose == DVIPS || purpose == DVIPDFM)
2559 if (purpose == DVIPS || purpose == DVIPDFM)
2563 if (purpose == DVIPS || purpose == DVIPDFM)
2567 if (purpose == DVIPS || purpose == DVIPDFM)
2571 if (purpose == DVIPS || purpose == DVIPDFM)
2575 if (purpose == DVIPS || purpose == DVIPDFM)
2579 if (purpose == DVIPS || purpose == DVIPDFM)
2583 if (purpose == DVIPS || purpose == DVIPDFM)
2587 if (purpose == DVIPS || purpose == DVIPDFM)
2591 if (purpose == DVIPS || purpose == DVIPDFM)
2595 if (purpose == DVIPS || purpose == DVIPDFM)
2599 if (purpose == DVIPS || purpose == DVIPDFM)
2603 if (purpose == DVIPS || purpose == DVIPDFM)
2606 case PAPER_USEXECUTIVE:
2607 // dvipdfm does not know this
2608 if (purpose == DVIPDFM)
2613 case PAPER_USLETTER:
2615 if (purpose == XDVI)
2622 string const BufferParams::dvips_options() const
2626 // If the class loads the geometry package, we do not know which
2627 // paper size is used, since we do not set it (bug 7013).
2628 // Therefore we must not specify any argument here.
2629 // dvips gets the correct paper size via DVI specials in this case
2630 // (if the class uses the geometry package correctly).
2631 if (documentClass().provides("geometry"))
2635 && papersize == PAPER_CUSTOM
2636 && !lyxrc.print_paper_dimension_flag.empty()
2637 && !paperwidth.empty()
2638 && !paperheight.empty()) {
2639 // using a custom papersize
2640 result = lyxrc.print_paper_dimension_flag;
2641 result += ' ' + paperwidth;
2642 result += ',' + paperheight;
2644 string const paper_option = paperSizeName(DVIPS);
2645 if (!paper_option.empty() && (paper_option != "letter" ||
2646 orientation != ORIENTATION_LANDSCAPE)) {
2647 // dvips won't accept -t letter -t landscape.
2648 // In all other cases, include the paper size
2650 result = lyxrc.print_paper_flag;
2651 result += ' ' + paper_option;
2654 if (orientation == ORIENTATION_LANDSCAPE &&
2655 papersize != PAPER_CUSTOM)
2656 result += ' ' + lyxrc.print_landscape_flag;
2661 string const BufferParams::font_encoding() const
2663 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2667 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2669 // suppress the babel call if there is no BabelName defined
2670 // for the document language in the lib/languages file and if no
2671 // other languages are used (lang_opts is then empty)
2672 if (lang_opts.empty())
2674 // either a specific language (AsBabelOptions setting in
2675 // lib/languages) or the prefs require the languages to
2676 // be submitted to babel itself (not the class).
2678 return "\\usepackage[" + lang_opts + "]{babel}";
2679 return "\\usepackage{babel}";
2683 docstring BufferParams::getGraphicsDriver(string const & package) const
2687 if (package == "geometry") {
2688 if (graphics_driver == "dvips"
2689 || graphics_driver == "dvipdfm"
2690 || graphics_driver == "pdftex"
2691 || graphics_driver == "vtex")
2692 result = from_ascii(graphics_driver);
2693 else if (graphics_driver == "dvipdfmx")
2694 result = from_ascii("dvipdfm");
2701 void BufferParams::writeEncodingPreamble(otexstream & os,
2702 LaTeXFeatures & features) const
2704 // XeTeX does not need this
2705 if (features.runparams().flavor == OutputParams::XETEX)
2707 // LuaTeX neither, but with tex fonts, we need to load
2708 // the luainputenc package.
2709 if (features.runparams().flavor == OutputParams::LUATEX
2710 || features.runparams().flavor == OutputParams::DVILUATEX) {
2711 if (!useNonTeXFonts && inputenc != "default"
2712 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2713 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2714 os << "\\usepackage[utf8]{luainputenc}\n";
2718 if (inputenc == "auto") {
2719 string const doc_encoding =
2720 language->encoding()->latexName();
2721 Encoding::Package const package =
2722 language->encoding()->package();
2724 // Create a list with all the input encodings used
2726 set<string> encodings =
2727 features.getEncodingSet(doc_encoding);
2729 // If the "japanese" package (i.e. pLaTeX) is used,
2730 // inputenc must be omitted.
2731 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2732 if ((!encodings.empty() || package == Encoding::inputenc)
2733 && !features.isRequired("japanese")) {
2734 os << "\\usepackage[";
2735 set<string>::const_iterator it = encodings.begin();
2736 set<string>::const_iterator const end = encodings.end();
2738 os << from_ascii(*it);
2741 for (; it != end; ++it)
2742 os << ',' << from_ascii(*it);
2743 if (package == Encoding::inputenc) {
2744 if (!encodings.empty())
2746 os << from_ascii(doc_encoding);
2748 os << "]{inputenc}\n";
2750 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2751 if (language->encoding()->name() == "utf8-cjk"
2752 && LaTeXFeatures::isAvailable("CJKutf8"))
2753 os << "\\usepackage{CJKutf8}\n";
2755 os << "\\usepackage{CJK}\n";
2757 } else if (inputenc != "default") {
2758 switch (encoding().package()) {
2759 case Encoding::none:
2760 case Encoding::japanese:
2762 case Encoding::inputenc:
2763 // do not load inputenc if japanese is used
2764 if (features.isRequired("japanese"))
2766 os << "\\usepackage[" << from_ascii(inputenc)
2770 if (encoding().name() == "utf8-cjk"
2771 && LaTeXFeatures::isAvailable("CJKutf8"))
2772 os << "\\usepackage{CJKutf8}\n";
2774 os << "\\usepackage{CJK}\n";
2781 string const BufferParams::parseFontName(string const & name) const
2783 string mangled = name;
2784 size_t const idx = mangled.find('[');
2785 if (idx == string::npos || idx == 0)
2788 return mangled.substr(0, idx - 1);
2792 string const BufferParams::loadFonts(LaTeXFeatures & features) const
2794 if (fonts_roman == "default" && fonts_sans == "default"
2795 && fonts_typewriter == "default"
2796 && (fonts_math == "default" || fonts_math == "auto"))
2802 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
2803 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
2804 * Mapping=tex-text option assures TeX ligatures (such as "--")
2805 * are resolved. Note that tt does not use these ligatures.
2807 * -- add more GUI options?
2808 * -- add more fonts (fonts for other scripts)
2809 * -- if there's a way to find out if a font really supports
2810 * OldStyle, enable/disable the widget accordingly.
2812 if (useNonTeXFonts && features.isAvailable("fontspec")) {
2813 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
2814 // However, until v.2 (2010/07/11) fontspec only knew
2815 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
2816 // was introduced for both XeTeX and LuaTeX (LuaTeX
2817 // didn't understand "Mapping=tex-text", while XeTeX
2818 // understood both. With most recent versions, both
2819 // variants are understood by both engines. However,
2820 // we want to provide support for at least TeXLive 2009
2821 // (for XeTeX; LuaTeX is only supported as of v.2)
2822 string const texmapping =
2823 (features.runparams().flavor == OutputParams::XETEX) ?
2824 "Mapping=tex-text" : "Ligatures=TeX";
2825 if (fonts_roman != "default") {
2826 os << "\\setmainfont[" << texmapping;
2827 if (fonts_old_figures)
2828 os << ",Numbers=OldStyle";
2829 os << "]{" << parseFontName(fonts_roman) << "}\n";
2831 if (fonts_sans != "default") {
2832 string const sans = parseFontName(fonts_sans);
2833 if (fonts_sans_scale != 100)
2834 os << "\\setsansfont[Scale="
2835 << float(fonts_sans_scale) / 100
2836 << "," << texmapping << "]{"
2839 os << "\\setsansfont[" << texmapping << "]{"
2842 if (fonts_typewriter != "default") {
2843 string const mono = parseFontName(fonts_typewriter);
2844 if (fonts_typewriter_scale != 100)
2845 os << "\\setmonofont[Scale="
2846 << float(fonts_typewriter_scale) / 100
2850 os << "\\setmonofont{"
2857 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
2858 bool const dryrun = features.runparams().dryrun;
2859 bool const complete = (fonts_sans == "default" && fonts_typewriter == "default");
2860 bool const nomath = (fonts_math == "default");
2863 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_roman)).getLaTeXCode(
2864 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2868 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_sans)).getLaTeXCode(
2869 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2870 nomath, fonts_sans_scale);
2872 // MONOSPACED/TYPEWRITER
2873 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_typewriter)).getLaTeXCode(
2874 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2875 nomath, fonts_typewriter_scale);
2878 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getLaTeXCode(
2879 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2886 Encoding const & BufferParams::encoding() const
2888 // FIXME: actually, we should check for the flavor
2889 // or runparams.isFullyUnicode() here:
2890 // This check will not work with XeTeX/LuaTeX and tex fonts.
2891 // Thus we have to reset the encoding in Buffer::makeLaTeXFile.
2893 return *(encodings.fromLaTeXName("utf8-plain"));
2894 if (inputenc == "auto" || inputenc == "default")
2895 return *language->encoding();
2896 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2899 LYXERR0("Unknown inputenc value `" << inputenc
2900 << "'. Using `auto' instead.");
2901 return *language->encoding();
2905 bool BufferParams::addCiteEngine(string const & engine)
2907 LayoutModuleList::const_iterator it = cite_engine_.begin();
2908 LayoutModuleList::const_iterator en = cite_engine_.end();
2909 for (; it != en; ++it)
2912 cite_engine_.push_back(engine);
2917 bool BufferParams::addCiteEngine(vector<string> const & engine)
2919 vector<string>::const_iterator it = engine.begin();
2920 vector<string>::const_iterator en = engine.end();
2922 for (; it != en; ++it)
2923 if (!addCiteEngine(*it))
2929 string const & BufferParams::defaultBiblioStyle() const
2931 return documentClass().defaultBiblioStyle();
2935 bool const & BufferParams::fullAuthorList() const
2937 return documentClass().fullAuthorList();
2941 void BufferParams::setCiteEngine(string const & engine)
2944 addCiteEngine(engine);
2948 void BufferParams::setCiteEngine(vector<string> const & engine)
2951 addCiteEngine(engine);
2955 vector<string> BufferParams::citeCommands() const
2957 static CitationStyle const default_style;
2958 vector<string> commands =
2959 documentClass().citeCommands(citeEngineType());
2960 if (commands.empty())
2961 commands.push_back(default_style.cmd);
2966 vector<CitationStyle> BufferParams::citeStyles() const
2968 static CitationStyle const default_style;
2969 vector<CitationStyle> styles =
2970 documentClass().citeStyles(citeEngineType());
2972 styles.push_back(default_style);