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"
24 #include "buffer_funcs.h"
26 #include "CiteEnginesList.h"
29 #include "Converter.h"
31 #include "IndicesList.h"
33 #include "LaTeXFeatures.h"
34 #include "LaTeXFonts.h"
36 #include "ModuleList.h"
40 #include "OutputParams.h"
42 #include "texstream.h"
45 #include "PDFOptions.h"
47 #include "frontends/alert.h"
49 #include "insets/InsetListingsParams.h"
51 #include "support/convert.h"
52 #include "support/debug.h"
53 #include "support/docstream.h"
54 #include "support/FileName.h"
55 #include "support/filetools.h"
56 #include "support/gettext.h"
57 #include "support/Messages.h"
58 #include "support/mutex.h"
59 #include "support/Package.h"
60 #include "support/Translator.h"
61 #include "support/lstrings.h"
67 using namespace lyx::support;
70 static char const * const string_paragraph_separation[] = {
75 static char const * const string_quotes_style[] = {
76 "english", "swedish", "german", "polish", "swiss", "danish", "plain",
77 "british", "swedishg", "french", "frenchin", "russian", "cjk", "cjkangle", ""
81 static char const * const string_papersize[] = {
82 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
83 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
84 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
85 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
86 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
91 static char const * const string_orientation[] = {
92 "portrait", "landscape", ""
96 static char const * const tex_graphics[] = {
97 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
98 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
99 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
100 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
107 // XeTeX with TeX fonts:
108 // run in 8-bit emulation mode and trick `inputenc` into working with XeTeX
109 static docstring const xetex_pre_inputenc = from_ascii(
110 "\\XeTeXinputencoding \"bytes\" % current file\n"
111 "\\XeTeXdefaultencoding \"bytes\" % included files\n"
113 "\\let\\origUmathchar\\Umathchar\n"
114 "\\let\\Umathchar\\@undefined\n");
115 static docstring const xetex_post_inputenc = from_ascii(
116 "\\let\\Umathchar\\origUmathchar\n"
122 // Paragraph separation
123 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
126 ParSepTranslator const init_parseptranslator()
128 ParSepTranslator translator
129 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
130 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
135 ParSepTranslator const & parseptranslator()
137 static ParSepTranslator const translator =
138 init_parseptranslator();
144 typedef Translator<string, InsetQuotesParams::QuoteStyle> QuotesStyleTranslator;
147 QuotesStyleTranslator const init_quotesstyletranslator()
149 QuotesStyleTranslator translator
150 (string_quotes_style[0], InsetQuotesParams::EnglishQuotes);
151 translator.addPair(string_quotes_style[1], InsetQuotesParams::SwedishQuotes);
152 translator.addPair(string_quotes_style[2], InsetQuotesParams::GermanQuotes);
153 translator.addPair(string_quotes_style[3], InsetQuotesParams::PolishQuotes);
154 translator.addPair(string_quotes_style[4], InsetQuotesParams::SwissQuotes);
155 translator.addPair(string_quotes_style[5], InsetQuotesParams::DanishQuotes);
156 translator.addPair(string_quotes_style[6], InsetQuotesParams::PlainQuotes);
157 translator.addPair(string_quotes_style[7], InsetQuotesParams::BritishQuotes);
158 translator.addPair(string_quotes_style[8], InsetQuotesParams::SwedishGQuotes);
159 translator.addPair(string_quotes_style[9], InsetQuotesParams::FrenchQuotes);
160 translator.addPair(string_quotes_style[10], InsetQuotesParams::FrenchINQuotes);
161 translator.addPair(string_quotes_style[11], InsetQuotesParams::RussianQuotes);
162 translator.addPair(string_quotes_style[12], InsetQuotesParams::CJKQuotes);
163 translator.addPair(string_quotes_style[13], InsetQuotesParams::CJKAngleQuotes);
168 QuotesStyleTranslator const & quotesstyletranslator()
170 static QuotesStyleTranslator const translator =
171 init_quotesstyletranslator();
177 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
180 static PaperSizeTranslator initPaperSizeTranslator()
182 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
183 translator.addPair(string_papersize[1], PAPER_CUSTOM);
184 translator.addPair(string_papersize[2], PAPER_USLETTER);
185 translator.addPair(string_papersize[3], PAPER_USLEGAL);
186 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
187 translator.addPair(string_papersize[5], PAPER_A0);
188 translator.addPair(string_papersize[6], PAPER_A1);
189 translator.addPair(string_papersize[7], PAPER_A2);
190 translator.addPair(string_papersize[8], PAPER_A3);
191 translator.addPair(string_papersize[9], PAPER_A4);
192 translator.addPair(string_papersize[10], PAPER_A5);
193 translator.addPair(string_papersize[11], PAPER_A6);
194 translator.addPair(string_papersize[12], PAPER_B0);
195 translator.addPair(string_papersize[13], PAPER_B1);
196 translator.addPair(string_papersize[14], PAPER_B2);
197 translator.addPair(string_papersize[15], PAPER_B3);
198 translator.addPair(string_papersize[16], PAPER_B4);
199 translator.addPair(string_papersize[17], PAPER_B5);
200 translator.addPair(string_papersize[18], PAPER_B6);
201 translator.addPair(string_papersize[19], PAPER_C0);
202 translator.addPair(string_papersize[20], PAPER_C1);
203 translator.addPair(string_papersize[21], PAPER_C2);
204 translator.addPair(string_papersize[22], PAPER_C3);
205 translator.addPair(string_papersize[23], PAPER_C4);
206 translator.addPair(string_papersize[24], PAPER_C5);
207 translator.addPair(string_papersize[25], PAPER_C6);
208 translator.addPair(string_papersize[26], PAPER_JISB0);
209 translator.addPair(string_papersize[27], PAPER_JISB1);
210 translator.addPair(string_papersize[28], PAPER_JISB2);
211 translator.addPair(string_papersize[29], PAPER_JISB3);
212 translator.addPair(string_papersize[30], PAPER_JISB4);
213 translator.addPair(string_papersize[31], PAPER_JISB5);
214 translator.addPair(string_papersize[32], PAPER_JISB6);
219 PaperSizeTranslator const & papersizetranslator()
221 static PaperSizeTranslator const translator =
222 initPaperSizeTranslator();
228 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
231 PaperOrientationTranslator const init_paperorientationtranslator()
233 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
234 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
239 PaperOrientationTranslator const & paperorientationtranslator()
241 static PaperOrientationTranslator const translator =
242 init_paperorientationtranslator();
248 typedef Translator<int, PageSides> SidesTranslator;
251 SidesTranslator const init_sidestranslator()
253 SidesTranslator translator(1, OneSide);
254 translator.addPair(2, TwoSides);
259 SidesTranslator const & sidestranslator()
261 static SidesTranslator const translator = init_sidestranslator();
267 typedef Translator<int, BufferParams::Package> PackageTranslator;
270 PackageTranslator const init_packagetranslator()
272 PackageTranslator translator(0, BufferParams::package_off);
273 translator.addPair(1, BufferParams::package_auto);
274 translator.addPair(2, BufferParams::package_on);
279 PackageTranslator const & packagetranslator()
281 static PackageTranslator const translator =
282 init_packagetranslator();
288 typedef Translator<string, Spacing::Space> SpaceTranslator;
291 SpaceTranslator const init_spacetranslator()
293 SpaceTranslator translator("default", Spacing::Default);
294 translator.addPair("single", Spacing::Single);
295 translator.addPair("onehalf", Spacing::Onehalf);
296 translator.addPair("double", Spacing::Double);
297 translator.addPair("other", Spacing::Other);
302 SpaceTranslator const & spacetranslator()
304 static SpaceTranslator const translator = init_spacetranslator();
309 bool inSystemDir(FileName const & document_dir, string & system_dir)
311 // A document is assumed to be in a system LyX directory (not
312 // necessarily the system directory of the running instance)
313 // if both "configure.py" and "chkconfig.ltx" are found in
314 // either document_dir/../ or document_dir/../../.
315 // If true, the system directory path is returned in system_dir
316 // with a trailing path separator.
318 string const msg = "Checking whether document is in a system dir...";
320 string dir = document_dir.absFileName();
322 for (int i = 0; i < 3; ++i) {
323 dir = addPath(dir, "..");
324 if (!fileSearch(dir, "configure.py").empty() &&
325 !fileSearch(dir, "chkconfig.ltx").empty()) {
326 LYXERR(Debug::FILES, msg << " yes");
327 system_dir = addPath(FileName(dir).realPath(), "");
332 LYXERR(Debug::FILES, msg << " no");
333 system_dir = string();
340 class BufferParams::Impl
345 AuthorList authorlist;
346 BranchList branchlist;
347 Bullet temp_bullets[4];
348 Bullet user_defined_bullets[4];
349 IndicesList indiceslist;
353 /** This is the amount of space used for paragraph_separation "skip",
354 * and for detached paragraphs in "indented" documents.
357 PDFOptions pdfoptions;
358 LayoutFileIndex baseClass_;
359 FormatList exportableFormatList;
360 FormatList viewableFormatList;
361 bool isViewCacheValid;
362 bool isExportCacheValid;
366 BufferParams::Impl::Impl()
367 : defskip(VSpace::MEDSKIP), baseClass_(string("")),
368 isViewCacheValid(false), isExportCacheValid(false)
370 // set initial author
372 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
377 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
380 return new BufferParams::Impl(*ptr);
384 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
390 BufferParams::BufferParams()
393 setBaseClass(defaultBaseclass());
394 cite_engine_ = "basic";
395 cite_engine_type_ = ENGINE_TYPE_DEFAULT;
397 paragraph_separation = ParagraphIndentSeparation;
398 is_math_indent = false;
399 math_numbering_side = DEFAULT;
400 quotes_style = InsetQuotesParams::EnglishQuotes;
401 dynamic_quotes = false;
402 fontsize = "default";
405 papersize = PAPER_DEFAULT;
406 orientation = ORIENTATION_PORTRAIT;
407 use_geometry = false;
408 biblio_style = string();
409 use_bibtopic = false;
412 save_transient_properties = true;
413 track_changes = false;
414 output_changes = false;
415 use_default_options = true;
416 maintain_unincluded_children = false;
419 language = default_language;
421 fonts_roman[0] = "default";
422 fonts_roman[1] = "default";
423 fonts_sans[0] = "default";
424 fonts_sans[1] = "default";
425 fonts_typewriter[0] = "default";
426 fonts_typewriter[1] = "default";
427 fonts_math[0] = "auto";
428 fonts_math[1] = "auto";
429 fonts_default_family = "default";
430 useNonTeXFonts = false;
431 use_microtype = false;
432 use_dash_ligatures = true;
433 fonts_expert_sc = false;
434 fonts_old_figures = false;
435 fonts_sans_scale[0] = 100;
436 fonts_sans_scale[1] = 100;
437 fonts_typewriter_scale[0] = 100;
438 fonts_typewriter_scale[1] = 100;
440 lang_package = "default";
441 graphics_driver = "default";
442 default_output_format = "default";
443 bibtex_command = "default";
444 index_command = "default";
447 listings_params = string();
448 pagestyle = "default";
449 tablestyle = "default";
450 suppress_date = false;
451 justification = true;
452 // no color is the default (white)
453 backgroundcolor = lyx::rgbFromHexName("#ffffff");
454 isbackgroundcolor = false;
455 // no color is the default (black)
456 fontcolor = lyx::rgbFromHexName("#000000");
458 // light gray is the default font color for greyed-out notes
459 notefontcolor = lyx::rgbFromHexName("#cccccc");
460 boxbgcolor = lyx::rgbFromHexName("#ff0000");
461 compressed = lyxrc.save_compressed;
462 for (int iter = 0; iter < 4; ++iter) {
463 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
464 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
467 indiceslist().addDefault(B_("Index"));
468 html_be_strict = false;
469 html_math_output = MathML;
470 html_math_img_scale = 1.0;
471 html_css_as_file = false;
472 display_pixel_ratio = 1.0;
474 shell_escape = false;
480 // map current author
481 author_map_[pimpl_->authorlist.get(0).bufferId()] = 0;
485 docstring BufferParams::B_(string const & l10n) const
487 LASSERT(language, return from_utf8(l10n));
488 return getMessages(language->code()).get(l10n);
492 BufferParams::Package BufferParams::use_package(std::string const & p) const
494 PackageMap::const_iterator it = use_packages.find(p);
495 if (it == use_packages.end())
501 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
507 map<string, string> const & BufferParams::auto_packages()
509 static map<string, string> packages;
510 if (packages.empty()) {
511 // We could have a race condition here that two threads
512 // discover an empty map at the same time and want to fill
513 // it, but that is no problem, since the same contents is
514 // filled in twice then. Having the locker inside the
515 // packages.empty() condition has the advantage that we
516 // don't need the mutex overhead for simple reading.
518 Mutex::Locker locker(&mutex);
519 // adding a package here implies a file format change!
520 packages["amsmath"] =
521 N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas");
522 packages["amssymb"] =
523 N_("The LaTeX package amssymb is only used if symbols from the AMS math toolbars are inserted into formulas");
525 N_("The LaTeX package cancel is only used if \\cancel commands are used in formulas");
527 N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas");
528 packages["mathdots"] =
529 N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas");
530 packages["mathtools"] =
531 N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas");
533 N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas");
534 packages["stackrel"] =
535 N_("The LaTeX package stackrel is only used if the command \\stackrel with subscript is inserted into formulas");
536 packages["stmaryrd"] =
537 N_("The LaTeX package stmaryrd is only used if symbols from the St Mary's Road symbol font for theoretical computer science are inserted into formulas");
538 packages["undertilde"] =
539 N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'");
545 bool BufferParams::useBibtopic() const
549 return (use_bibtopic || (!multibib.empty() && multibib != "child"));
553 AuthorList & BufferParams::authors()
555 return pimpl_->authorlist;
559 AuthorList const & BufferParams::authors() const
561 return pimpl_->authorlist;
565 void BufferParams::addAuthor(Author a)
567 author_map_[a.bufferId()] = pimpl_->authorlist.record(a);
571 BranchList & BufferParams::branchlist()
573 return pimpl_->branchlist;
577 BranchList const & BufferParams::branchlist() const
579 return pimpl_->branchlist;
583 IndicesList & BufferParams::indiceslist()
585 return pimpl_->indiceslist;
589 IndicesList const & BufferParams::indiceslist() const
591 return pimpl_->indiceslist;
595 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
597 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
598 return pimpl_->temp_bullets[index];
602 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
604 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
605 return pimpl_->temp_bullets[index];
609 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
611 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
612 return pimpl_->user_defined_bullets[index];
616 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
618 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
619 return pimpl_->user_defined_bullets[index];
623 Spacing & BufferParams::spacing()
625 return pimpl_->spacing;
629 Spacing const & BufferParams::spacing() const
631 return pimpl_->spacing;
635 PDFOptions & BufferParams::pdfoptions()
637 return pimpl_->pdfoptions;
641 PDFOptions const & BufferParams::pdfoptions() const
643 return pimpl_->pdfoptions;
647 Length const & BufferParams::getMathIndent() const
649 return pimpl_->mathindent;
653 void BufferParams::setMathIndent(Length const & indent)
655 pimpl_->mathindent = indent;
659 Length const & BufferParams::getParIndent() const
661 return pimpl_->parindent;
665 void BufferParams::setParIndent(Length const & indent)
667 pimpl_->parindent = indent;
671 VSpace const & BufferParams::getDefSkip() const
673 return pimpl_->defskip;
677 void BufferParams::setDefSkip(VSpace const & vs)
679 // DEFSKIP will cause an infinite loop
680 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
681 pimpl_->defskip = vs;
685 BufferParams::MathNumber BufferParams::getMathNumber() const
687 if (math_numbering_side != DEFAULT)
688 return math_numbering_side;
689 // FIXME: do not hardcode language here
690 else if (language->lang() == "arabic_arabi"
691 || documentClass().provides("leqno"))
698 string BufferParams::readToken(Lexer & lex, string const & token,
699 FileName const & filepath)
703 if (token == "\\textclass") {
705 string const classname = lex.getString();
706 // if there exists a local layout file, ignore the system one
707 // NOTE: in this case, the textclass (.cls file) is assumed to
710 LayoutFileList & bcl = LayoutFileList::get();
711 if (!filepath.empty()) {
712 // If classname is an absolute path, the document is
713 // using a local layout file which could not be accessed
714 // by a relative path. In this case the path is correct
715 // even if the document was moved to a different
716 // location. However, we will have a problem if the
717 // document was generated on a different platform.
718 bool isabsolute = FileName::isAbsolute(classname);
719 string const classpath = onlyPath(classname);
720 string const path = isabsolute ? classpath
721 : FileName(addPath(filepath.absFileName(),
722 classpath)).realPath();
723 string const oldpath = isabsolute ? string()
724 : FileName(addPath(origin, classpath)).realPath();
725 tcp = bcl.addLocalLayout(onlyFileName(classname), path, oldpath);
727 // that returns non-empty if a "local" layout file is found.
729 result = to_utf8(makeRelPath(from_utf8(onlyPath(tcp)),
730 from_utf8(filepath.absFileName())));
733 setBaseClass(onlyFileName(tcp));
735 setBaseClass(onlyFileName(classname));
736 // We assume that a tex class exists for local or unknown
737 // layouts so this warning, will only be given for system layouts.
738 if (!baseClass()->isTeXClassAvailable()) {
739 docstring const desc =
740 translateIfPossible(from_utf8(baseClass()->description()));
741 docstring const prereqs =
742 from_utf8(baseClass()->prerequisites());
743 docstring const msg =
744 bformat(_("The selected document class\n"
746 "requires external files that are not available.\n"
747 "The document class can still be used, but the\n"
748 "document cannot be compiled until the following\n"
749 "prerequisites are installed:\n"
751 "See section 3.1.2.2 (Class Availability) of the\n"
752 "User's Guide for more information."), desc, prereqs);
753 frontend::Alert::warning(_("Document class not available"),
756 } else if (token == "\\save_transient_properties") {
757 lex >> save_transient_properties;
758 } else if (token == "\\origin") {
760 origin = lex.getString();
761 string const sysdirprefix = "/systemlyxdir/";
762 if (prefixIs(origin, sysdirprefix)) {
764 if (inSystemDir(filepath, docsys))
765 origin.replace(0, sysdirprefix.length() - 1, docsys);
767 origin.replace(0, sysdirprefix.length() - 1,
768 package().system_support().absFileName());
770 } else if (token == "\\begin_preamble") {
772 } else if (token == "\\begin_local_layout") {
773 readLocalLayout(lex, false);
774 } else if (token == "\\begin_forced_local_layout") {
775 readLocalLayout(lex, true);
776 } else if (token == "\\begin_modules") {
778 } else if (token == "\\begin_removed_modules") {
779 readRemovedModules(lex);
780 } else if (token == "\\begin_includeonly") {
781 readIncludeonly(lex);
782 } else if (token == "\\maintain_unincluded_children") {
783 lex >> maintain_unincluded_children;
784 } else if (token == "\\options") {
786 options = lex.getString();
787 } else if (token == "\\use_default_options") {
788 lex >> use_default_options;
789 } else if (token == "\\master") {
791 master = lex.getString();
792 if (!filepath.empty() && FileName::isAbsolute(origin)) {
793 bool const isabs = FileName::isAbsolute(master);
794 FileName const abspath(isabs ? master : origin + master);
795 bool const moved = filepath != FileName(origin);
796 if (moved && abspath.exists()) {
797 docstring const path = isabs
799 : from_utf8(abspath.realPath());
800 docstring const refpath =
801 from_utf8(filepath.absFileName());
802 master = to_utf8(makeRelPath(path, refpath));
805 } else if (token == "\\suppress_date") {
806 lex >> suppress_date;
807 } else if (token == "\\justification") {
808 lex >> justification;
809 } else if (token == "\\language") {
811 } else if (token == "\\language_package") {
813 lang_package = lex.getString();
814 } else if (token == "\\inputencoding") {
816 } else if (token == "\\graphics") {
817 readGraphicsDriver(lex);
818 } else if (token == "\\default_output_format") {
819 lex >> default_output_format;
820 } else if (token == "\\bibtex_command") {
822 bibtex_command = lex.getString();
823 } else if (token == "\\index_command") {
825 index_command = lex.getString();
826 } else if (token == "\\fontencoding") {
828 fontenc = lex.getString();
829 } else if (token == "\\font_roman") {
830 lex >> fonts_roman[0];
831 lex >> fonts_roman[1];
832 } else if (token == "\\font_sans") {
833 lex >> fonts_sans[0];
834 lex >> fonts_sans[1];
835 } else if (token == "\\font_typewriter") {
836 lex >> fonts_typewriter[0];
837 lex >> fonts_typewriter[1];
838 } else if (token == "\\font_math") {
839 lex >> fonts_math[0];
840 lex >> fonts_math[1];
841 } else if (token == "\\font_default_family") {
842 lex >> fonts_default_family;
843 } else if (token == "\\use_non_tex_fonts") {
844 lex >> useNonTeXFonts;
845 } else if (token == "\\font_sc") {
846 lex >> fonts_expert_sc;
847 } else if (token == "\\font_osf") {
848 lex >> fonts_old_figures;
849 } else if (token == "\\font_sf_scale") {
850 lex >> fonts_sans_scale[0];
851 lex >> fonts_sans_scale[1];
852 } else if (token == "\\font_tt_scale") {
853 lex >> fonts_typewriter_scale[0];
854 lex >> fonts_typewriter_scale[1];
855 } else if (token == "\\font_cjk") {
857 } else if (token == "\\use_microtype") {
858 lex >> use_microtype;
859 } else if (token == "\\use_dash_ligatures") {
860 lex >> use_dash_ligatures;
861 } else if (token == "\\paragraph_separation") {
864 paragraph_separation = parseptranslator().find(parsep);
865 } else if (token == "\\paragraph_indentation") {
867 string parindent = lex.getString();
868 if (parindent == "default")
869 pimpl_->parindent = Length();
871 pimpl_->parindent = Length(parindent);
872 } else if (token == "\\defskip") {
874 string const defskip = lex.getString();
875 pimpl_->defskip = VSpace(defskip);
876 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
878 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
879 } else if (token == "\\is_math_indent") {
880 lex >> is_math_indent;
881 } else if (token == "\\math_indentation") {
883 string mathindent = lex.getString();
884 if (mathindent == "default")
885 pimpl_->mathindent = Length();
887 pimpl_->mathindent = Length(mathindent);
888 } else if (token == "\\math_numbering_side") {
892 math_numbering_side = LEFT;
893 else if (tmp == "right")
894 math_numbering_side = RIGHT;
896 math_numbering_side = DEFAULT;
897 } else if (token == "\\quotes_style") {
900 quotes_style = quotesstyletranslator().find(qstyle);
901 } else if (token == "\\dynamic_quotes") {
902 lex >> dynamic_quotes;
903 } else if (token == "\\papersize") {
906 papersize = papersizetranslator().find(ppsize);
907 } else if (token == "\\use_geometry") {
909 } else if (token == "\\use_package") {
914 use_package(package, packagetranslator().find(use));
915 } else if (token == "\\cite_engine") {
917 cite_engine_ = lex.getString();
918 } else if (token == "\\cite_engine_type") {
921 cite_engine_type_ = theCiteEnginesList.getType(engine_type);
922 } else if (token == "\\biblio_style") {
924 biblio_style = lex.getString();
925 } else if (token == "\\biblio_options") {
927 biblio_opts = trim(lex.getString());
928 } else if (token == "\\biblatex_bibstyle") {
930 biblatex_bibstyle = trim(lex.getString());
931 } else if (token == "\\biblatex_citestyle") {
933 biblatex_citestyle = trim(lex.getString());
934 } else if (token == "\\use_bibtopic") {
936 } else if (token == "\\multibib") {
938 } else if (token == "\\use_indices") {
940 } else if (token == "\\tracking_changes") {
941 lex >> track_changes;
942 } else if (token == "\\output_changes") {
943 lex >> output_changes;
944 } else if (token == "\\branch") {
946 docstring branch = lex.getDocString();
947 branchlist().add(branch);
950 string const tok = lex.getString();
951 if (tok == "\\end_branch")
953 Branch * branch_ptr = branchlist().find(branch);
954 if (tok == "\\selected") {
957 branch_ptr->setSelected(lex.getInteger());
959 if (tok == "\\filename_suffix") {
962 branch_ptr->setFileNameSuffix(lex.getInteger());
964 if (tok == "\\color") {
966 string color = lex.getString();
968 branch_ptr->setColor(color);
969 // Update also the Color table:
971 color = lcolor.getX11Name(Color_background);
973 lcolor.setColor(to_utf8(branch), color);
976 } else if (token == "\\index") {
978 docstring index = lex.getDocString();
980 indiceslist().add(index);
983 string const tok = lex.getString();
984 if (tok == "\\end_index")
986 Index * index_ptr = indiceslist().find(index);
987 if (tok == "\\shortcut") {
989 shortcut = lex.getDocString();
991 index_ptr->setShortcut(shortcut);
993 if (tok == "\\color") {
995 string color = lex.getString();
997 index_ptr->setColor(color);
998 // Update also the Color table:
1000 color = lcolor.getX11Name(Color_background);
1002 if (!shortcut.empty())
1003 lcolor.setColor(to_utf8(shortcut), color);
1006 } else if (token == "\\author") {
1008 istringstream ss(lex.getString());
1012 } else if (token == "\\paperorientation") {
1015 orientation = paperorientationtranslator().find(orient);
1016 } else if (token == "\\backgroundcolor") {
1018 backgroundcolor = lyx::rgbFromHexName(lex.getString());
1019 isbackgroundcolor = true;
1020 } else if (token == "\\fontcolor") {
1022 fontcolor = lyx::rgbFromHexName(lex.getString());
1024 } else if (token == "\\notefontcolor") {
1026 string color = lex.getString();
1027 notefontcolor = lyx::rgbFromHexName(color);
1028 lcolor.setColor("notefontcolor", color);
1029 } else if (token == "\\boxbgcolor") {
1031 string color = lex.getString();
1032 boxbgcolor = lyx::rgbFromHexName(color);
1033 lcolor.setColor("boxbgcolor", color);
1034 } else if (token == "\\paperwidth") {
1036 } else if (token == "\\paperheight") {
1038 } else if (token == "\\leftmargin") {
1040 } else if (token == "\\topmargin") {
1042 } else if (token == "\\rightmargin") {
1044 } else if (token == "\\bottommargin") {
1045 lex >> bottommargin;
1046 } else if (token == "\\headheight") {
1048 } else if (token == "\\headsep") {
1050 } else if (token == "\\footskip") {
1052 } else if (token == "\\columnsep") {
1054 } else if (token == "\\paperfontsize") {
1056 } else if (token == "\\papercolumns") {
1058 } else if (token == "\\listings_params") {
1061 listings_params = InsetListingsParams(par).params();
1062 } else if (token == "\\papersides") {
1065 sides = sidestranslator().find(psides);
1066 } else if (token == "\\paperpagestyle") {
1068 } else if (token == "\\tablestyle") {
1070 } else if (token == "\\bullet") {
1072 } else if (token == "\\bulletLaTeX") {
1073 readBulletsLaTeX(lex);
1074 } else if (token == "\\secnumdepth") {
1076 } else if (token == "\\tocdepth") {
1078 } else if (token == "\\spacing") {
1082 if (nspacing == "other") {
1085 spacing().set(spacetranslator().find(nspacing), tmp_val);
1086 } else if (token == "\\float_placement") {
1087 lex >> float_placement;
1088 } else if (token == "\\float_alignment") {
1089 lex >> float_alignment;
1091 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
1092 string toktmp = pdfoptions().readToken(lex, token);
1093 if (!toktmp.empty()) {
1094 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
1098 } else if (token == "\\html_math_output") {
1101 html_math_output = static_cast<MathOutput>(temp);
1102 } else if (token == "\\html_be_strict") {
1103 lex >> html_be_strict;
1104 } else if (token == "\\html_css_as_file") {
1105 lex >> html_css_as_file;
1106 } else if (token == "\\html_math_img_scale") {
1107 lex >> html_math_img_scale;
1108 } else if (token == "\\html_latex_start") {
1110 html_latex_start = lex.getString();
1111 } else if (token == "\\html_latex_end") {
1113 html_latex_end = lex.getString();
1114 } else if (token == "\\output_sync") {
1116 } else if (token == "\\output_sync_macro") {
1117 lex >> output_sync_macro;
1118 } else if (token == "\\use_refstyle") {
1119 lex >> use_refstyle;
1120 } else if (token == "\\use_minted") {
1122 } else if (token == "\\use_lineno") {
1124 } else if (token == "\\lineno_options") {
1126 lineno_opts = trim(lex.getString());
1128 lyxerr << "BufferParams::readToken(): Unknown token: " <<
1138 // Quote argument if it contains spaces
1139 string quoteIfNeeded(string const & str) {
1140 if (contains(str, ' '))
1141 return "\"" + str + "\"";
1147 void BufferParams::writeFile(ostream & os, Buffer const * buf) const
1149 // The top of the file is written by the buffer.
1150 // Prints out the buffer info into the .lyx file given by file
1152 os << "\\save_transient_properties "
1153 << convert<string>(save_transient_properties) << '\n';
1155 // the document directory (must end with a path separator)
1156 // realPath() is used to resolve symlinks, while addPath(..., "")
1157 // ensures a trailing path separator.
1159 string filepath = addPath(buf->fileName().onlyPath().realPath(), "");
1160 string const sysdir = inSystemDir(FileName(filepath), docsys) ? docsys
1161 : addPath(package().system_support().realPath(), "");
1162 string const relpath =
1163 to_utf8(makeRelPath(from_utf8(filepath), from_utf8(sysdir)));
1164 if (!prefixIs(relpath, "../") && !FileName::isAbsolute(relpath))
1165 filepath = addPath("/systemlyxdir", relpath);
1166 else if (!save_transient_properties || !lyxrc.save_origin)
1167 filepath = "unavailable";
1168 os << "\\origin " << quoteIfNeeded(filepath) << '\n';
1171 os << "\\textclass "
1172 << quoteIfNeeded(buf->includedFilePath(addName(buf->layoutPos(),
1173 baseClass()->name()), "layout"))
1176 // then the preamble
1177 if (!preamble.empty()) {
1178 // remove '\n' from the end of preamble
1179 docstring const tmppreamble = rtrim(preamble, "\n");
1180 os << "\\begin_preamble\n"
1181 << to_utf8(tmppreamble)
1182 << "\n\\end_preamble\n";
1186 if (!options.empty()) {
1187 os << "\\options " << options << '\n';
1190 // use the class options defined in the layout?
1191 os << "\\use_default_options "
1192 << convert<string>(use_default_options) << "\n";
1194 // the master document
1195 if (!master.empty()) {
1196 os << "\\master " << master << '\n';
1200 if (!removed_modules_.empty()) {
1201 os << "\\begin_removed_modules" << '\n';
1202 list<string>::const_iterator it = removed_modules_.begin();
1203 list<string>::const_iterator en = removed_modules_.end();
1204 for (; it != en; ++it)
1206 os << "\\end_removed_modules" << '\n';
1210 if (!layout_modules_.empty()) {
1211 os << "\\begin_modules" << '\n';
1212 LayoutModuleList::const_iterator it = layout_modules_.begin();
1213 LayoutModuleList::const_iterator en = layout_modules_.end();
1214 for (; it != en; ++it)
1216 os << "\\end_modules" << '\n';
1220 if (!included_children_.empty()) {
1221 os << "\\begin_includeonly" << '\n';
1222 list<string>::const_iterator it = included_children_.begin();
1223 list<string>::const_iterator en = included_children_.end();
1224 for (; it != en; ++it)
1226 os << "\\end_includeonly" << '\n';
1228 os << "\\maintain_unincluded_children "
1229 << convert<string>(maintain_unincluded_children) << '\n';
1231 // local layout information
1232 docstring const local_layout = getLocalLayout(false);
1233 if (!local_layout.empty()) {
1234 // remove '\n' from the end
1235 docstring const tmplocal = rtrim(local_layout, "\n");
1236 os << "\\begin_local_layout\n"
1237 << to_utf8(tmplocal)
1238 << "\n\\end_local_layout\n";
1240 docstring const forced_local_layout = getLocalLayout(true);
1241 if (!forced_local_layout.empty()) {
1242 // remove '\n' from the end
1243 docstring const tmplocal = rtrim(forced_local_layout, "\n");
1244 os << "\\begin_forced_local_layout\n"
1245 << to_utf8(tmplocal)
1246 << "\n\\end_forced_local_layout\n";
1249 // then the text parameters
1250 if (language != ignore_language)
1251 os << "\\language " << language->lang() << '\n';
1252 os << "\\language_package " << lang_package
1253 << "\n\\inputencoding " << inputenc
1254 << "\n\\fontencoding " << fontenc
1255 << "\n\\font_roman \"" << fonts_roman[0]
1256 << "\" \"" << fonts_roman[1] << '"'
1257 << "\n\\font_sans \"" << fonts_sans[0]
1258 << "\" \"" << fonts_sans[1] << '"'
1259 << "\n\\font_typewriter \"" << fonts_typewriter[0]
1260 << "\" \"" << fonts_typewriter[1] << '"'
1261 << "\n\\font_math \"" << fonts_math[0]
1262 << "\" \"" << fonts_math[1] << '"'
1263 << "\n\\font_default_family " << fonts_default_family
1264 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
1265 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
1266 << "\n\\font_osf " << convert<string>(fonts_old_figures)
1267 << "\n\\font_sf_scale " << fonts_sans_scale[0]
1268 << ' ' << fonts_sans_scale[1]
1269 << "\n\\font_tt_scale " << fonts_typewriter_scale[0]
1270 << ' ' << fonts_typewriter_scale[1]
1272 if (!fonts_cjk.empty()) {
1273 os << "\\font_cjk " << fonts_cjk << '\n';
1275 os << "\\use_microtype " << convert<string>(use_microtype) << '\n';
1276 os << "\\use_dash_ligatures " << convert<string>(use_dash_ligatures) << '\n';
1277 os << "\\graphics " << graphics_driver << '\n';
1278 os << "\\default_output_format " << default_output_format << '\n';
1279 os << "\\output_sync " << output_sync << '\n';
1280 if (!output_sync_macro.empty())
1281 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1282 os << "\\bibtex_command " << bibtex_command << '\n';
1283 os << "\\index_command " << index_command << '\n';
1285 if (!float_placement.empty())
1286 os << "\\float_placement " << float_placement << '\n';
1287 if (!float_alignment.empty())
1288 os << "\\float_alignment " << float_alignment << '\n';
1289 os << "\\paperfontsize " << fontsize << '\n';
1291 spacing().writeFile(os);
1292 pdfoptions().writeFile(os);
1294 os << "\\papersize " << string_papersize[papersize]
1295 << "\n\\use_geometry " << convert<string>(use_geometry);
1296 map<string, string> const & packages = auto_packages();
1297 for (map<string, string>::const_iterator it = packages.begin();
1298 it != packages.end(); ++it)
1299 os << "\n\\use_package " << it->first << ' '
1300 << use_package(it->first);
1302 os << "\n\\cite_engine ";
1304 if (!cite_engine_.empty())
1309 os << "\n\\cite_engine_type " << theCiteEnginesList.getTypeAsString(cite_engine_type_);
1311 if (!biblio_style.empty())
1312 os << "\n\\biblio_style " << biblio_style;
1313 if (!biblio_opts.empty())
1314 os << "\n\\biblio_options " << biblio_opts;
1315 if (!biblatex_bibstyle.empty())
1316 os << "\n\\biblatex_bibstyle " << biblatex_bibstyle;
1317 if (!biblatex_citestyle.empty())
1318 os << "\n\\biblatex_citestyle " << biblatex_citestyle;
1319 if (!multibib.empty())
1320 os << "\n\\multibib " << multibib;
1322 os << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1323 << "\n\\use_indices " << convert<string>(use_indices)
1324 << "\n\\paperorientation " << string_orientation[orientation]
1325 << "\n\\suppress_date " << convert<string>(suppress_date)
1326 << "\n\\justification " << convert<string>(justification)
1327 << "\n\\use_refstyle " << use_refstyle
1328 << "\n\\use_minted " << use_minted
1329 << "\n\\use_lineno " << use_lineno
1332 os << "\\lineno_options " << lineno_opts << '\n';
1334 if (isbackgroundcolor == true)
1335 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1336 if (isfontcolor == true)
1337 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1338 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1339 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1340 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1341 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1343 BranchList::const_iterator it = branchlist().begin();
1344 BranchList::const_iterator end = branchlist().end();
1345 for (; it != end; ++it) {
1346 os << "\\branch " << to_utf8(it->branch())
1347 << "\n\\selected " << it->isSelected()
1348 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1349 << "\n\\color " << lyx::X11hexname(it->color())
1354 IndicesList::const_iterator iit = indiceslist().begin();
1355 IndicesList::const_iterator iend = indiceslist().end();
1356 for (; iit != iend; ++iit) {
1357 os << "\\index " << to_utf8(iit->index())
1358 << "\n\\shortcut " << to_utf8(iit->shortcut())
1359 << "\n\\color " << lyx::X11hexname(iit->color())
1364 if (!paperwidth.empty())
1365 os << "\\paperwidth "
1366 << VSpace(paperwidth).asLyXCommand() << '\n';
1367 if (!paperheight.empty())
1368 os << "\\paperheight "
1369 << VSpace(paperheight).asLyXCommand() << '\n';
1370 if (!leftmargin.empty())
1371 os << "\\leftmargin "
1372 << VSpace(leftmargin).asLyXCommand() << '\n';
1373 if (!topmargin.empty())
1374 os << "\\topmargin "
1375 << VSpace(topmargin).asLyXCommand() << '\n';
1376 if (!rightmargin.empty())
1377 os << "\\rightmargin "
1378 << VSpace(rightmargin).asLyXCommand() << '\n';
1379 if (!bottommargin.empty())
1380 os << "\\bottommargin "
1381 << VSpace(bottommargin).asLyXCommand() << '\n';
1382 if (!headheight.empty())
1383 os << "\\headheight "
1384 << VSpace(headheight).asLyXCommand() << '\n';
1385 if (!headsep.empty())
1387 << VSpace(headsep).asLyXCommand() << '\n';
1388 if (!footskip.empty())
1390 << VSpace(footskip).asLyXCommand() << '\n';
1391 if (!columnsep.empty())
1392 os << "\\columnsep "
1393 << VSpace(columnsep).asLyXCommand() << '\n';
1394 os << "\\secnumdepth " << secnumdepth
1395 << "\n\\tocdepth " << tocdepth
1396 << "\n\\paragraph_separation "
1397 << string_paragraph_separation[paragraph_separation];
1398 if (!paragraph_separation)
1399 os << "\n\\paragraph_indentation "
1400 << (getParIndent().empty() ? "default" : getParIndent().asString());
1402 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1403 os << "\n\\is_math_indent " << is_math_indent;
1405 os << "\n\\math_indentation "
1406 << (getMathIndent().empty() ? "default" : getMathIndent().asString());
1407 os << "\n\\math_numbering_side ";
1408 switch(math_numbering_side) {
1418 os << "\n\\quotes_style "
1419 << string_quotes_style[quotes_style]
1420 << "\n\\dynamic_quotes " << dynamic_quotes
1421 << "\n\\papercolumns " << columns
1422 << "\n\\papersides " << sides
1423 << "\n\\paperpagestyle " << pagestyle
1424 << "\n\\tablestyle " << tablestyle << '\n';
1425 if (!listings_params.empty())
1426 os << "\\listings_params \"" <<
1427 InsetListingsParams(listings_params).encodedString() << "\"\n";
1428 for (int i = 0; i < 4; ++i) {
1429 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1430 if (user_defined_bullet(i).getFont() != -1) {
1431 os << "\\bullet " << i << " "
1432 << user_defined_bullet(i).getFont() << " "
1433 << user_defined_bullet(i).getCharacter() << " "
1434 << user_defined_bullet(i).getSize() << "\n";
1438 os << "\\bulletLaTeX " << i << " \""
1439 << lyx::to_ascii(user_defined_bullet(i).getText())
1445 os << "\\tracking_changes "
1446 << (save_transient_properties ? convert<string>(track_changes) : "false")
1449 os << "\\output_changes "
1450 << (save_transient_properties ? convert<string>(output_changes) : "false")
1453 os << "\\html_math_output " << html_math_output << '\n'
1454 << "\\html_css_as_file " << html_css_as_file << '\n'
1455 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1457 if (html_math_img_scale != 1.0)
1458 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1459 if (!html_latex_start.empty())
1460 os << "\\html_latex_start " << html_latex_start << '\n';
1461 if (!html_latex_end.empty())
1462 os << "\\html_latex_end " << html_latex_end << '\n';
1464 os << pimpl_->authorlist;
1468 void BufferParams::validate(LaTeXFeatures & features) const
1470 features.require(documentClass().requires());
1472 if (columns > 1 && language->rightToLeft())
1473 features.require("rtloutputdblcol");
1475 if (output_changes) {
1476 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1477 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1478 LaTeXFeatures::isAvailable("xcolor");
1480 switch (features.runparams().flavor) {
1481 case OutputParams::LATEX:
1482 case OutputParams::DVILUATEX:
1484 features.require("ct-dvipost");
1485 features.require("dvipost");
1486 } else if (xcolorulem) {
1487 features.require("ct-xcolor-ulem");
1488 features.require("ulem");
1489 features.require("xcolor");
1491 features.require("ct-none");
1494 case OutputParams::LUATEX:
1495 case OutputParams::PDFLATEX:
1496 case OutputParams::XETEX:
1498 features.require("ct-xcolor-ulem");
1499 features.require("ulem");
1500 features.require("xcolor");
1501 // improves color handling in PDF output
1502 features.require("pdfcolmk");
1504 features.require("ct-none");
1512 // Floats with 'Here definitely' as default setting.
1513 if (float_placement.find('H') != string::npos)
1514 features.require("float");
1516 for (PackageMap::const_iterator it = use_packages.begin();
1517 it != use_packages.end(); ++it) {
1518 if (it->first == "amsmath") {
1519 // AMS Style is at document level
1520 if (it->second == package_on ||
1521 features.isProvided("amsmath"))
1522 features.require(it->first);
1523 } else if (it->second == package_on)
1524 features.require(it->first);
1527 // Document-level line spacing
1528 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1529 features.require("setspace");
1531 // the bullet shapes are buffer level not paragraph level
1532 // so they are tested here
1533 for (int i = 0; i < 4; ++i) {
1534 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1536 int const font = user_defined_bullet(i).getFont();
1538 int const c = user_defined_bullet(i).getCharacter();
1544 features.require("latexsym");
1546 } else if (font == 1) {
1547 features.require("amssymb");
1548 } else if (font >= 2 && font <= 5) {
1549 features.require("pifont");
1553 if (pdfoptions().use_hyperref) {
1554 features.require("hyperref");
1555 // due to interferences with babel and hyperref, the color package has to
1556 // be loaded after hyperref when hyperref is used with the colorlinks
1557 // option, see http://www.lyx.org/trac/ticket/5291
1558 if (pdfoptions().colorlinks)
1559 features.require("color");
1561 if (!listings_params.empty()) {
1562 // do not test validity because listings_params is
1563 // supposed to be valid
1565 InsetListingsParams(listings_params).separatedParams(true);
1566 // we can't support all packages, but we should load the color package
1567 if (par.find("\\color", 0) != string::npos)
1568 features.require("color");
1571 // some languages are only available via polyglossia
1572 if (features.hasPolyglossiaExclusiveLanguages())
1573 features.require("polyglossia");
1575 if (useNonTeXFonts && fontsMath() != "auto")
1576 features.require("unicode-math");
1579 features.require("microtype");
1581 if (!language->requires().empty())
1582 features.require(language->requires());
1586 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1587 FileName const & filepath) const
1589 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1590 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1591 // \RequirePackage to do so, rather than the normal \usepackage
1592 // Do not try to load any other package before the document class, unless you
1593 // have a thorough understanding of the LATEX internals and know exactly what you
1595 if (features.mustProvide("fix-cm"))
1596 os << "\\RequirePackage{fix-cm}\n";
1597 // Likewise for fixltx2e. If other packages conflict with this policy,
1598 // treat it as a package bug (and report it!)
1599 // See http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/4407
1600 if (features.mustProvide("fixltx2e"))
1601 os << "\\RequirePackage{fixltx2e}\n";
1603 os << "\\documentclass";
1605 DocumentClass const & tclass = documentClass();
1607 ostringstream clsoptions; // the document class options.
1609 if (tokenPos(tclass.opt_fontsize(),
1610 '|', fontsize) >= 0) {
1611 // only write if existing in list (and not default)
1612 clsoptions << fontsize << "pt,";
1615 // all paper sizes except of A4, A5, B5 and the US sizes need the
1617 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1618 && papersize != PAPER_USLETTER
1619 && papersize != PAPER_USLEGAL
1620 && papersize != PAPER_USEXECUTIVE
1621 && papersize != PAPER_A4
1622 && papersize != PAPER_A5
1623 && papersize != PAPER_B5;
1625 if (!use_geometry) {
1626 switch (papersize) {
1628 clsoptions << "a4paper,";
1630 case PAPER_USLETTER:
1631 clsoptions << "letterpaper,";
1634 clsoptions << "a5paper,";
1637 clsoptions << "b5paper,";
1639 case PAPER_USEXECUTIVE:
1640 clsoptions << "executivepaper,";
1643 clsoptions << "legalpaper,";
1677 if (sides != tclass.sides()) {
1680 clsoptions << "oneside,";
1683 clsoptions << "twoside,";
1689 if (columns != tclass.columns()) {
1691 clsoptions << "twocolumn,";
1693 clsoptions << "onecolumn,";
1697 && orientation == ORIENTATION_LANDSCAPE)
1698 clsoptions << "landscape,";
1701 clsoptions << "fleqn,";
1703 switch(math_numbering_side) {
1705 clsoptions << "leqno,";
1708 clsoptions << "reqno,";
1709 features.require("amsmath");
1715 // language should be a parameter to \documentclass
1716 if (language->babel() == "hebrew"
1717 && default_language->babel() != "hebrew")
1718 // This seems necessary
1719 features.useLanguage(default_language);
1721 ostringstream language_options;
1722 bool const use_babel = features.useBabel() && !features.isProvided("babel");
1723 bool const use_polyglossia = features.usePolyglossia();
1724 bool const global = lyxrc.language_global_options;
1725 if (features.useBabel() || (use_polyglossia && global)) {
1726 language_options << features.getBabelLanguages();
1727 if (!language->babel().empty()) {
1728 if (!language_options.str().empty())
1729 language_options << ',';
1730 language_options << language->babel();
1732 if (global && !language_options.str().empty())
1733 clsoptions << language_options.str() << ',';
1736 // the predefined options from the layout
1737 if (use_default_options && !tclass.options().empty())
1738 clsoptions << tclass.options() << ',';
1740 // the user-defined options
1741 if (!options.empty()) {
1742 clsoptions << options << ',';
1745 string strOptions(clsoptions.str());
1746 if (!strOptions.empty()) {
1747 strOptions = rtrim(strOptions, ",");
1749 os << '[' << from_utf8(strOptions) << ']';
1752 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1753 // end of \documentclass defs
1755 // if we use fontspec or newtxmath, we have to load the AMS packages here
1756 string const ams = features.loadAMSPackages();
1757 bool const ot1 = (main_font_encoding() == "default" || main_font_encoding() == "OT1");
1758 bool const use_newtxmath =
1759 theLaTeXFonts().getLaTeXFont(from_ascii(fontsMath())).getUsedPackage(
1760 ot1, false, false) == "newtxmath";
1761 if ((useNonTeXFonts || use_newtxmath) && !ams.empty())
1762 os << from_ascii(ams);
1764 if (useNonTeXFonts) {
1765 if (!features.isProvided("fontspec"))
1766 os << "\\usepackage{fontspec}\n";
1767 if (features.mustProvide("unicode-math")
1768 && features.isAvailable("unicode-math"))
1769 os << "\\usepackage{unicode-math}\n";
1772 // load CJK support package before font selection
1773 // (see autotests/export/latex/CJK/micro-sign_utf8-cjk-libertine.lyx)
1774 if (!useNonTeXFonts && encoding().package() != Encoding::none && inputenc != "utf8x"
1775 && (encoding().package() == Encoding::CJK || features.mustProvide("CJK"))) {
1776 if (inputenc == "utf8-cjk" || inputenc == "utf8")
1777 os << "\\usepackage{CJKutf8}\n";
1779 os << "\\usepackage[encapsulated]{CJK}\n";
1782 // font selection must be done before loading fontenc.sty
1783 string const fonts = loadFonts(features);
1785 os << from_utf8(fonts);
1787 if (fonts_default_family != "default")
1788 os << "\\renewcommand{\\familydefault}{\\"
1789 << from_ascii(fonts_default_family) << "}\n";
1791 // set font encoding
1792 // non-TeX fonts use font encoding TU (set by fontspec)
1793 if (!useNonTeXFonts && !features.isProvided("fontenc")
1794 && main_font_encoding() != "default") {
1795 // get main font encodings
1796 vector<string> fontencs = font_encodings();
1797 // get font encodings of secondary languages
1798 // FIXME: some languages (hebrew, ...) assume a standard font encoding as last
1799 // option (for text in other languages).
1800 features.getFontEncodings(fontencs);
1801 if (!fontencs.empty()) {
1802 os << "\\usepackage["
1803 << from_ascii(getStringFromVector(fontencs))
1808 // Load textcomp and pmboxdraw before (lua)inputenc (#11454)
1809 if (features.mustProvide("textcomp"))
1810 os << "\\usepackage{textcomp}\n";
1811 if (features.mustProvide("pmboxdraw"))
1812 os << "\\usepackage{pmboxdraw}\n";
1814 // handle inputenc etc.
1815 // (In documents containing text in Thai language,
1816 // we must load inputenc after babel, see lib/languages).
1817 if (!contains(features.getBabelPostsettings(), from_ascii("thai.ldf")))
1818 writeEncodingPreamble(os, features);
1821 if (!features.runparams().includeall && !included_children_.empty()) {
1822 os << "\\includeonly{";
1823 list<string>::const_iterator it = included_children_.begin();
1824 list<string>::const_iterator en = included_children_.end();
1826 for (; it != en; ++it) {
1827 string incfile = *it;
1828 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1829 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1831 if (!features.runparams().nice)
1833 // \includeonly doesn't want an extension
1834 incfile = changeExtension(incfile, string());
1835 incfile = support::latex_path(incfile);
1836 if (!incfile.empty()) {
1839 os << from_utf8(incfile);
1846 if (!features.isProvided("geometry")
1847 && (use_geometry || nonstandard_papersize)) {
1848 odocstringstream ods;
1849 if (!getGraphicsDriver("geometry").empty())
1850 ods << getGraphicsDriver("geometry");
1851 if (orientation == ORIENTATION_LANDSCAPE)
1852 ods << ",landscape";
1853 switch (papersize) {
1855 if (!paperwidth.empty())
1856 ods << ",paperwidth="
1857 << from_ascii(paperwidth);
1858 if (!paperheight.empty())
1859 ods << ",paperheight="
1860 << from_ascii(paperheight);
1862 case PAPER_USLETTER:
1863 ods << ",letterpaper";
1866 ods << ",legalpaper";
1868 case PAPER_USEXECUTIVE:
1869 ods << ",executivepaper";
1958 docstring const g_options = trim(ods.str(), ",");
1959 os << "\\usepackage";
1960 if (!g_options.empty())
1961 os << '[' << g_options << ']';
1962 os << "{geometry}\n";
1963 // output this only if use_geometry is true
1965 os << "\\geometry{verbose";
1966 if (!topmargin.empty())
1967 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1968 if (!bottommargin.empty())
1969 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1970 if (!leftmargin.empty())
1971 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1972 if (!rightmargin.empty())
1973 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1974 if (!headheight.empty())
1975 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1976 if (!headsep.empty())
1977 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1978 if (!footskip.empty())
1979 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1980 if (!columnsep.empty())
1981 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1984 } else if (orientation == ORIENTATION_LANDSCAPE
1985 || papersize != PAPER_DEFAULT) {
1986 features.require("papersize");
1989 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1990 if (pagestyle == "fancy")
1991 os << "\\usepackage{fancyhdr}\n";
1992 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1995 // only output when the background color is not default
1996 if (isbackgroundcolor == true) {
1997 // only require color here, the background color will be defined
1998 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
2000 features.require("color");
2001 features.require("pagecolor");
2004 // only output when the font color is not default
2005 if (isfontcolor == true) {
2006 // only require color here, the font color will be defined
2007 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
2009 features.require("color");
2010 features.require("fontcolor");
2013 // Only if class has a ToC hierarchy
2014 if (tclass.hasTocLevels()) {
2015 if (secnumdepth != tclass.secnumdepth()) {
2016 os << "\\setcounter{secnumdepth}{"
2020 if (tocdepth != tclass.tocdepth()) {
2021 os << "\\setcounter{tocdepth}{"
2027 if (paragraph_separation) {
2028 // when skip separation
2029 switch (getDefSkip().kind()) {
2030 case VSpace::SMALLSKIP:
2031 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
2033 case VSpace::MEDSKIP:
2034 os << "\\setlength{\\parskip}{\\medskipamount}\n";
2036 case VSpace::BIGSKIP:
2037 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
2039 case VSpace::LENGTH:
2040 os << "\\setlength{\\parskip}{"
2041 << from_utf8(getDefSkip().length().asLatexString())
2044 default: // should never happen // Then delete it.
2045 os << "\\setlength{\\parskip}{\\medskipamount}\n";
2048 os << "\\setlength{\\parindent}{0pt}\n";
2050 // when separation by indentation
2051 // only output something when a width is given
2052 if (!getParIndent().empty()) {
2053 os << "\\setlength{\\parindent}{"
2054 << from_utf8(getParIndent().asLatexString())
2059 if (is_math_indent) {
2060 // when formula indentation
2061 // only output something when it is not the default
2062 if (!getMathIndent().empty()) {
2063 os << "\\setlength{\\mathindent}{"
2064 << from_utf8(getMathIndent().asString())
2069 // Now insert the LyX specific LaTeX commands...
2070 features.resolveAlternatives();
2071 features.expandMultiples();
2074 if (!output_sync_macro.empty())
2075 os << from_utf8(output_sync_macro) +"\n";
2076 else if (features.runparams().flavor == OutputParams::LATEX)
2077 os << "\\usepackage[active]{srcltx}\n";
2078 else if (features.runparams().flavor == OutputParams::PDFLATEX)
2079 os << "\\synctex=-1\n";
2082 // The package options (via \PassOptionsToPackage)
2083 os << from_ascii(features.getPackageOptions());
2085 // due to interferences with babel and hyperref, the color package has to
2086 // be loaded (when it is not already loaded) before babel when hyperref
2087 // is used with the colorlinks option, see
2088 // http://www.lyx.org/trac/ticket/5291
2089 // we decided therefore to load color always before babel, see
2090 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
2091 os << from_ascii(features.getColorOptions());
2093 // If we use hyperref, jurabib, japanese or varioref,
2094 // we have to call babel before
2096 && (features.isRequired("jurabib")
2097 || features.isRequired("hyperref")
2098 || features.isRequired("varioref")
2099 || features.isRequired("japanese"))) {
2100 os << features.getBabelPresettings();
2102 os << from_utf8(babelCall(language_options.str(),
2103 !lyxrc.language_global_options)) + '\n';
2104 os << features.getBabelPostsettings();
2107 // The optional packages;
2108 os << from_ascii(features.getPackages());
2110 // Additional Indices
2111 if (features.isRequired("splitidx")) {
2112 IndicesList::const_iterator iit = indiceslist().begin();
2113 IndicesList::const_iterator iend = indiceslist().end();
2114 for (; iit != iend; ++iit) {
2115 os << "\\newindex{";
2116 os << escape(iit->shortcut());
2122 os << from_utf8(spacing().writePreamble(features.isProvided("SetSpace")));
2125 // * Hyperref manual: "Make sure it comes last of your loaded
2126 // packages, to give it a fighting chance of not being over-written,
2127 // since its job is to redefine many LaTeX commands."
2128 // * Email from Heiko Oberdiek: "It is usually better to load babel
2129 // before hyperref. Then hyperref has a chance to detect babel.
2130 // * Has to be loaded before the "LyX specific LaTeX commands" to
2131 // avoid errors with algorithm floats.
2132 // use hyperref explicitly if it is required
2133 if (features.isRequired("hyperref")) {
2134 OutputParams tmp_params = features.runparams();
2135 pdfoptions().writeLaTeX(tmp_params, os,
2136 features.isProvided("hyperref"));
2137 // correctly break URLs with hyperref and dvi/ps output
2138 if (features.runparams().hyperref_driver == "dvips"
2139 && features.isAvailable("breakurl"))
2140 os << "\\usepackage{breakurl}\n";
2141 } else if (features.isRequired("nameref"))
2142 // hyperref loads this automatically
2143 os << "\\usepackage{nameref}\n";
2146 os << "\\usepackage";
2147 if (!lineno_opts.empty())
2148 os << "[" << lineno_opts << "]";
2150 os << "\\linenumbers\n";
2153 // bibtopic needs to be loaded after hyperref.
2154 // the dot provides the aux file naming which LyX can detect.
2155 if (features.mustProvide("bibtopic"))
2156 os << "\\usepackage[dot]{bibtopic}\n";
2158 // Will be surrounded by \makeatletter and \makeatother when not empty
2159 otexstringstream atlyxpreamble;
2161 // Some macros LyX will need
2163 TexString tmppreamble = features.getMacros();
2164 if (!tmppreamble.str.empty())
2165 atlyxpreamble << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2166 "LyX specific LaTeX commands.\n"
2167 << move(tmppreamble)
2170 // the text class specific preamble
2172 docstring tmppreamble = features.getTClassPreamble();
2173 if (!tmppreamble.empty())
2174 atlyxpreamble << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2175 "Textclass specific LaTeX commands.\n"
2179 // suppress date if selected
2180 // use \@ifundefined because we cannot be sure that every document class
2181 // has a \date command
2183 atlyxpreamble << "\\@ifundefined{date}{}{\\date{}}\n";
2185 /* the user-defined preamble */
2186 if (!containsOnly(preamble, " \n\t")) {
2188 atlyxpreamble << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2189 "User specified LaTeX commands.\n";
2191 // Check if the user preamble contains uncodable glyphs
2192 odocstringstream user_preamble;
2193 docstring uncodable_glyphs;
2194 Encoding const * const enc = features.runparams().encoding;
2196 for (size_t n = 0; n < preamble.size(); ++n) {
2197 char_type c = preamble[n];
2198 if (!enc->encodable(c)) {
2199 docstring const glyph(1, c);
2200 LYXERR0("Uncodable character '"
2202 << "' in user preamble!");
2203 uncodable_glyphs += glyph;
2204 if (features.runparams().dryrun) {
2205 user_preamble << "<" << _("LyX Warning: ")
2206 << _("uncodable character") << " '";
2207 user_preamble.put(c);
2208 user_preamble << "'>";
2211 user_preamble.put(c);
2214 user_preamble << preamble;
2216 // On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs
2217 if (!features.runparams().dryrun && !uncodable_glyphs.empty()) {
2218 frontend::Alert::warning(
2219 _("Uncodable character in user preamble"),
2221 _("The user preamble of your document contains glyphs "
2222 "that are unknown in the current document encoding "
2223 "(namely %1$s).\nThese glyphs are omitted "
2224 " from the output, which may result in "
2225 "incomplete output."
2226 "\n\nPlease select an appropriate "
2227 "document encoding\n"
2228 "(such as utf8) or change the "
2229 "preamble code accordingly."),
2232 atlyxpreamble << user_preamble.str() << '\n';
2235 // footmisc must be loaded after setspace
2236 // Load it here to avoid clashes with footmisc loaded in the user
2237 // preamble. For that reason we also pass the options via
2238 // \PassOptionsToPackage in getPreamble() and not here.
2239 if (features.mustProvide("footmisc"))
2240 atlyxpreamble << "\\usepackage{footmisc}\n";
2242 // subfig loads internally the LaTeX package "caption". As
2243 // caption is a very popular package, users will load it in
2244 // the preamble. Therefore we must load subfig behind the
2245 // user-defined preamble and check if the caption package was
2246 // loaded or not. For the case that caption is loaded before
2247 // subfig, there is the subfig option "caption=false". This
2248 // option also works when a koma-script class is used and
2249 // koma's own caption commands are used instead of caption. We
2250 // use \PassOptionsToPackage here because the user could have
2251 // already loaded subfig in the preamble.
2252 if (features.mustProvide("subfig"))
2253 atlyxpreamble << "\\@ifundefined{showcaptionsetup}{}{%\n"
2254 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
2255 "\\usepackage{subfig}\n";
2257 // Itemize bullet settings need to be last in case the user
2258 // defines their own bullets that use a package included
2259 // in the user-defined preamble -- ARRae
2260 // Actually it has to be done much later than that
2261 // since some packages like frenchb make modifications
2262 // at \begin{document} time -- JMarc
2263 docstring bullets_def;
2264 for (int i = 0; i < 4; ++i) {
2265 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
2266 if (bullets_def.empty())
2267 bullets_def += "\\AtBeginDocument{\n";
2268 bullets_def += " \\def\\labelitemi";
2270 // `i' is one less than the item to modify
2277 bullets_def += "ii";
2283 bullets_def += '{' +
2284 user_defined_bullet(i).getText()
2289 if (!bullets_def.empty())
2290 atlyxpreamble << bullets_def << "}\n\n";
2292 if (!atlyxpreamble.empty())
2293 os << "\n\\makeatletter\n"
2294 << atlyxpreamble.release()
2295 << "\\makeatother\n\n";
2297 // We try to load babel late, in case it interferes with other packages.
2298 // Jurabib, hyperref, varioref, bicaption, menukeys and listings (bug 8995)
2299 // have to be called after babel, though.
2300 if (use_babel && !features.isRequired("jurabib")
2301 && !features.isRequired("hyperref")
2302 && !features.isRequired("varioref")
2303 && !features.isRequired("japanese")) {
2304 os << features.getBabelPresettings();
2306 os << from_utf8(babelCall(language_options.str(),
2307 !lyxrc.language_global_options)) + '\n';
2308 os << features.getBabelPostsettings();
2310 // In documents containing text in Thai language,
2311 // we must load inputenc after babel (see lib/languages).
2312 if (contains(features.getBabelPostsettings(), from_ascii("thai.ldf")))
2313 writeEncodingPreamble(os, features);
2315 if (features.isRequired("bicaption"))
2316 os << "\\usepackage{bicaption}\n";
2317 if (!listings_params.empty()
2318 || features.mustProvide("listings")
2319 || features.mustProvide("minted")) {
2321 os << "\\usepackage{minted}\n";
2323 os << "\\usepackage{listings}\n";
2325 string lst_params = listings_params;
2326 // If minted, do not output the language option (bug 11203)
2327 if (use_minted && contains(lst_params, "language=")) {
2328 vector<string> opts =
2329 getVectorFromString(lst_params, ",", false);
2330 for (size_t i = 0; i < opts.size(); ++i) {
2331 if (prefixIs(opts[i], "language="))
2332 opts.erase(opts.begin() + i--);
2334 lst_params = getStringFromVector(opts, ",");
2336 if (!lst_params.empty()) {
2338 os << "\\setminted{";
2341 // do not test validity because listings_params is
2342 // supposed to be valid
2344 InsetListingsParams(lst_params).separatedParams(true);
2345 os << from_utf8(par);
2349 // xunicode only needs to be loaded if tipa is used
2350 // (the rest is obsoleted by the new TU encoding).
2351 // It needs to be loaded at least after amsmath, amssymb,
2352 // esint and the other packages that provide special glyphs
2353 if (features.mustProvide("tipa") && useNonTeXFonts
2354 && !features.isProvided("xunicode")) {
2355 // The `xunicode` package officially only supports XeTeX,
2356 // but also works with LuaTeX. We work around its XeTeX test.
2357 if (features.runparams().flavor != OutputParams::XETEX) {
2358 os << "% Pretend to xunicode that we are XeTeX\n"
2359 << "\\def\\XeTeXpicfile{}\n";
2361 os << "\\usepackage{xunicode}\n";
2364 // covington must be loaded after beamerarticle
2365 if (features.isRequired("covington"))
2366 os << "\\usepackage{covington}\n";
2368 // Polyglossia must be loaded last ...
2369 if (use_polyglossia) {
2371 os << "\\usepackage{polyglossia}\n";
2372 // set the main language
2373 os << "\\setdefaultlanguage";
2374 if (!language->polyglossiaOpts().empty())
2375 os << "[" << from_ascii(language->polyglossiaOpts()) << "]";
2376 os << "{" << from_ascii(language->polyglossia()) << "}\n";
2377 // now setup the other languages
2378 set<string> const polylangs =
2379 features.getPolyglossiaLanguages();
2380 for (set<string>::const_iterator mit = polylangs.begin();
2381 mit != polylangs.end() ; ++mit) {
2382 // We do not output the options here; they are output in
2383 // the language switch commands. This is safer if multiple
2384 // varieties are used.
2385 if (*mit == language->polyglossia())
2387 os << "\\setotherlanguage";
2388 os << "{" << from_ascii(*mit) << "}\n";
2392 // ... but before biblatex (see #7065)
2393 if ((features.mustProvide("biblatex")
2394 || features.isRequired("biblatex-chicago"))
2395 && !features.isProvided("biblatex-chicago")
2396 && !features.isProvided("biblatex-natbib")
2397 && !features.isProvided("natbib-internal")
2398 && !features.isProvided("natbib")
2399 && !features.isProvided("jurabib")) {
2400 // The biblatex-chicago package has a differing interface
2401 // it uses a wrapper package and loads styles via fixed options
2402 bool const chicago = features.isRequired("biblatex-chicago");
2405 os << "\\usepackage";
2406 if (!biblatex_bibstyle.empty()
2407 && (biblatex_bibstyle == biblatex_citestyle)
2409 opts = "style=" + biblatex_bibstyle;
2411 } else if (!chicago) {
2412 if (!biblatex_bibstyle.empty()) {
2413 opts = "bibstyle=" + biblatex_bibstyle;
2416 if (!biblatex_citestyle.empty()) {
2417 opts += delim + "citestyle=" + biblatex_citestyle;
2421 if (!multibib.empty() && multibib != "child") {
2422 opts += delim + "refsection=" + multibib;
2425 if (bibtexCommand() == "bibtex8"
2426 || prefixIs(bibtexCommand(), "bibtex8 ")) {
2427 opts += delim + "backend=bibtex8";
2429 } else if (bibtexCommand() == "bibtex"
2430 || prefixIs(bibtexCommand(), "bibtex ")) {
2431 opts += delim + "backend=bibtex";
2434 if (!bib_encoding.empty() && encodings.fromLyXName(bib_encoding)) {
2435 opts += delim + "bibencoding="
2436 + encodings.fromLyXName(bib_encoding)->latexName();
2439 if (!biblio_opts.empty())
2440 opts += delim + biblio_opts;
2442 os << "[" << opts << "]";
2444 os << "{biblatex-chicago}\n";
2446 os << "{biblatex}\n";
2450 // Load custom language package here
2451 if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
2452 if (lang_package == "default")
2453 os << from_utf8(lyxrc.language_custom_package);
2455 os << from_utf8(lang_package);
2459 // Since menukeys uses catoptions, which does some heavy changes on key-value options,
2460 // it is recommended to load menukeys as the last package (even after hyperref)
2461 if (features.isRequired("menukeys"))
2462 os << "\\usepackage{menukeys}\n";
2464 docstring const i18npreamble =
2465 features.getTClassI18nPreamble(use_babel, use_polyglossia,
2467 if (!i18npreamble.empty())
2468 os << i18npreamble + '\n';
2474 void BufferParams::useClassDefaults()
2476 DocumentClass const & tclass = documentClass();
2478 sides = tclass.sides();
2479 columns = tclass.columns();
2480 pagestyle = tclass.pagestyle();
2481 tablestyle = tclass.tablestyle();
2482 use_default_options = true;
2483 // Only if class has a ToC hierarchy
2484 if (tclass.hasTocLevels()) {
2485 secnumdepth = tclass.secnumdepth();
2486 tocdepth = tclass.tocdepth();
2491 bool BufferParams::hasClassDefaults() const
2493 DocumentClass const & tclass = documentClass();
2495 return sides == tclass.sides()
2496 && columns == tclass.columns()
2497 && pagestyle == tclass.pagestyle()
2498 && tablestyle == tclass.tablestyle()
2499 && use_default_options
2500 && secnumdepth == tclass.secnumdepth()
2501 && tocdepth == tclass.tocdepth();
2505 DocumentClass const & BufferParams::documentClass() const
2511 DocumentClassConstPtr BufferParams::documentClassPtr() const
2517 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
2519 // evil, but this function is evil
2520 doc_class_ = const_pointer_cast<DocumentClass>(tc);
2521 invalidateConverterCache();
2525 bool BufferParams::setBaseClass(string const & classname, string const & path)
2527 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
2528 LayoutFileList & bcl = LayoutFileList::get();
2529 if (!bcl.haveClass(classname)) {
2531 bformat(_("The layout file:\n"
2533 "could not be found. A default textclass with default\n"
2534 "layouts will be used. LyX will not be able to produce\n"
2536 from_utf8(classname));
2537 frontend::Alert::error(_("Document class not found"), s);
2538 bcl.addEmptyClass(classname);
2541 bool const success = bcl[classname].load(path);
2544 bformat(_("Due to some error in it, the layout file:\n"
2546 "could not be loaded. A default textclass with default\n"
2547 "layouts will be used. LyX will not be able to produce\n"
2549 from_utf8(classname));
2550 frontend::Alert::error(_("Could not load class"), s);
2551 bcl.addEmptyClass(classname);
2554 pimpl_->baseClass_ = classname;
2555 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2560 LayoutFile const * BufferParams::baseClass() const
2562 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2563 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2569 LayoutFileIndex const & BufferParams::baseClassID() const
2571 return pimpl_->baseClass_;
2575 void BufferParams::makeDocumentClass(bool const clone)
2580 invalidateConverterCache();
2581 LayoutModuleList mods;
2582 LayoutModuleList::iterator it = layout_modules_.begin();
2583 LayoutModuleList::iterator en = layout_modules_.end();
2584 for (; it != en; ++it)
2585 mods.push_back(*it);
2587 doc_class_ = getDocumentClass(*baseClass(), mods, cite_engine_, clone);
2589 TextClass::ReturnValues success = TextClass::OK;
2590 if (!forced_local_layout_.empty())
2591 success = doc_class_->read(to_utf8(forced_local_layout_),
2593 if (!local_layout_.empty() &&
2594 (success == TextClass::OK || success == TextClass::OK_OLDFORMAT))
2595 success = doc_class_->read(to_utf8(local_layout_), TextClass::MODULE);
2596 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2597 docstring const msg = _("Error reading internal layout information");
2598 frontend::Alert::warning(_("Read Error"), msg);
2603 bool BufferParams::layoutModuleCanBeAdded(string const & modName) const
2605 return layout_modules_.moduleCanBeAdded(modName, baseClass());
2609 docstring BufferParams::getLocalLayout(bool forced) const
2612 return from_utf8(doc_class_->forcedLayouts());
2614 return local_layout_;
2618 void BufferParams::setLocalLayout(docstring const & layout, bool forced)
2621 forced_local_layout_ = layout;
2623 local_layout_ = layout;
2627 bool BufferParams::addLayoutModule(string const & modName)
2629 LayoutModuleList::const_iterator it = layout_modules_.begin();
2630 LayoutModuleList::const_iterator end = layout_modules_.end();
2631 for (; it != end; ++it)
2634 layout_modules_.push_back(modName);
2639 string BufferParams::bufferFormat() const
2641 return documentClass().outputFormat();
2645 bool BufferParams::isExportable(string const & format, bool need_viewable) const
2647 FormatList const & formats = exportableFormats(need_viewable);
2648 FormatList::const_iterator fit = formats.begin();
2649 FormatList::const_iterator end = formats.end();
2650 for (; fit != end ; ++fit) {
2651 if ((*fit)->name() == format)
2658 FormatList const & BufferParams::exportableFormats(bool only_viewable) const
2660 FormatList & cached = only_viewable ?
2661 pimpl_->viewableFormatList : pimpl_->exportableFormatList;
2662 bool & valid = only_viewable ?
2663 pimpl_->isViewCacheValid : pimpl_->isExportCacheValid;
2667 vector<string> const backs = backends();
2668 set<string> excludes;
2669 if (useNonTeXFonts) {
2670 excludes.insert("latex");
2671 excludes.insert("pdflatex");
2672 } else if (inputenc != "ascii" && inputenc != "utf8"
2673 && inputenc != "utf8x" && inputenc != "utf8-plain")
2674 // XeTeX with TeX fonts requires input encoding ascii or utf8
2675 // (https://www.tug.org/pipermail/xetex/2010-April/016452.html).
2676 excludes.insert("xetex");
2677 FormatList result = theConverters().getReachable(backs[0], only_viewable,
2679 for (vector<string>::const_iterator it = backs.begin() + 1;
2680 it != backs.end(); ++it) {
2681 FormatList r = theConverters().getReachable(*it, only_viewable,
2683 result.insert(result.end(), r.begin(), r.end());
2685 sort(result.begin(), result.end(), Format::formatSorter);
2692 vector<string> BufferParams::backends() const
2695 string const buffmt = bufferFormat();
2697 // FIXME: Don't hardcode format names here, but use a flag
2698 if (buffmt == "latex") {
2699 if (encoding().package() == Encoding::japanese)
2700 v.push_back("platex");
2702 if (!useNonTeXFonts) {
2703 v.push_back("pdflatex");
2704 v.push_back("latex");
2706 if (useNonTeXFonts || inputenc == "ascii" || inputenc == "utf8"
2707 || inputenc == "utf8x" || inputenc == "utf8-plain")
2708 v.push_back("xetex");
2709 v.push_back("luatex");
2710 v.push_back("dviluatex");
2713 string rbuffmt = buffmt;
2714 // If we use an OutputFormat in Japanese docs,
2715 // we need special format in order to get the path
2716 // via pLaTeX (#8823)
2717 if (documentClass().hasOutputFormat()
2718 && encoding().package() == Encoding::japanese)
2720 v.push_back(rbuffmt);
2723 v.push_back("xhtml");
2724 v.push_back("text");
2730 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const
2732 string const dformat = (format.empty() || format == "default") ?
2733 getDefaultOutputFormat() : format;
2734 DefaultFlavorCache::const_iterator it =
2735 default_flavors_.find(dformat);
2737 if (it != default_flavors_.end())
2740 OutputParams::FLAVOR result = OutputParams::LATEX;
2742 // FIXME It'd be better not to hardcode this, but to do
2743 // something with formats.
2744 if (dformat == "xhtml")
2745 result = OutputParams::HTML;
2746 else if (dformat == "text")
2747 result = OutputParams::TEXT;
2748 else if (dformat == "lyx")
2749 result = OutputParams::LYX;
2750 else if (dformat == "pdflatex")
2751 result = OutputParams::PDFLATEX;
2752 else if (dformat == "xetex")
2753 result = OutputParams::XETEX;
2754 else if (dformat == "luatex")
2755 result = OutputParams::LUATEX;
2756 else if (dformat == "dviluatex")
2757 result = OutputParams::DVILUATEX;
2759 // Try to determine flavor of default output format
2760 vector<string> backs = backends();
2761 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2762 // Get shortest path to format
2763 Graph::EdgePath path;
2764 for (auto const & bvar : backs) {
2765 Graph::EdgePath p = theConverters().getPath(bvar, dformat);
2766 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2771 result = theConverters().getFlavor(path);
2774 // cache this flavor
2775 default_flavors_[dformat] = result;
2780 string BufferParams::getDefaultOutputFormat() const
2782 if (!default_output_format.empty()
2783 && default_output_format != "default")
2784 return default_output_format;
2786 FormatList const & formats = exportableFormats(true);
2787 if (formats.empty())
2789 // return the first we find
2790 return formats.front()->name();
2792 if (encoding().package() == Encoding::japanese)
2793 return lyxrc.default_platex_view_format;
2795 return lyxrc.default_otf_view_format;
2796 return lyxrc.default_view_format;
2799 Font const BufferParams::getFont() const
2801 FontInfo f = documentClass().defaultfont();
2802 if (fonts_default_family == "rmdefault")
2803 f.setFamily(ROMAN_FAMILY);
2804 else if (fonts_default_family == "sfdefault")
2805 f.setFamily(SANS_FAMILY);
2806 else if (fonts_default_family == "ttdefault")
2807 f.setFamily(TYPEWRITER_FAMILY);
2808 return Font(f, language);
2812 InsetQuotesParams::QuoteStyle BufferParams::getQuoteStyle(string const & qs) const
2814 return quotesstyletranslator().find(qs);
2818 bool BufferParams::isLatex() const
2820 return documentClass().outputType() == LATEX;
2824 bool BufferParams::isLiterate() const
2826 return documentClass().outputType() == LITERATE;
2830 bool BufferParams::isDocBook() const
2832 return documentClass().outputType() == DOCBOOK;
2836 void BufferParams::readPreamble(Lexer & lex)
2838 if (lex.getString() != "\\begin_preamble")
2839 lyxerr << "Error (BufferParams::readPreamble):"
2840 "consistency check failed." << endl;
2842 preamble = lex.getLongString(from_ascii("\\end_preamble"));
2846 void BufferParams::readLocalLayout(Lexer & lex, bool forced)
2848 string const expected = forced ? "\\begin_forced_local_layout" :
2849 "\\begin_local_layout";
2850 if (lex.getString() != expected)
2851 lyxerr << "Error (BufferParams::readLocalLayout):"
2852 "consistency check failed." << endl;
2855 forced_local_layout_ =
2856 lex.getLongString(from_ascii("\\end_forced_local_layout"));
2858 local_layout_ = lex.getLongString(from_ascii("\\end_local_layout"));
2862 bool BufferParams::setLanguage(string const & lang)
2864 Language const *new_language = languages.getLanguage(lang);
2865 if (!new_language) {
2866 // Language lang was not found
2869 language = new_language;
2874 void BufferParams::readLanguage(Lexer & lex)
2876 if (!lex.next()) return;
2878 string const tmptok = lex.getString();
2880 // check if tmptok is part of tex_babel in tex-defs.h
2881 if (!setLanguage(tmptok)) {
2882 // Language tmptok was not found
2883 language = default_language;
2884 lyxerr << "Warning: Setting language `"
2885 << tmptok << "' to `" << language->lang()
2891 void BufferParams::readGraphicsDriver(Lexer & lex)
2896 string const tmptok = lex.getString();
2897 // check if tmptok is part of tex_graphics in tex_defs.h
2900 string const test = tex_graphics[n++];
2902 if (test == tmptok) {
2903 graphics_driver = tmptok;
2908 "Warning: graphics driver `$$Token' not recognized!\n"
2909 " Setting graphics driver to `default'.\n");
2910 graphics_driver = "default";
2917 void BufferParams::readBullets(Lexer & lex)
2922 int const index = lex.getInteger();
2924 int temp_int = lex.getInteger();
2925 user_defined_bullet(index).setFont(temp_int);
2926 temp_bullet(index).setFont(temp_int);
2928 user_defined_bullet(index).setCharacter(temp_int);
2929 temp_bullet(index).setCharacter(temp_int);
2931 user_defined_bullet(index).setSize(temp_int);
2932 temp_bullet(index).setSize(temp_int);
2936 void BufferParams::readBulletsLaTeX(Lexer & lex)
2938 // The bullet class should be able to read this.
2941 int const index = lex.getInteger();
2943 docstring const temp_str = lex.getDocString();
2945 user_defined_bullet(index).setText(temp_str);
2946 temp_bullet(index).setText(temp_str);
2950 void BufferParams::readModules(Lexer & lex)
2952 if (!lex.eatLine()) {
2953 lyxerr << "Error (BufferParams::readModules):"
2954 "Unexpected end of input." << endl;
2958 string mod = lex.getString();
2959 if (mod == "\\end_modules")
2961 addLayoutModule(mod);
2967 void BufferParams::readRemovedModules(Lexer & lex)
2969 if (!lex.eatLine()) {
2970 lyxerr << "Error (BufferParams::readRemovedModules):"
2971 "Unexpected end of input." << endl;
2975 string mod = lex.getString();
2976 if (mod == "\\end_removed_modules")
2978 removed_modules_.push_back(mod);
2981 // now we want to remove any removed modules that were previously
2982 // added. normally, that will be because default modules were added in
2983 // setBaseClass(), which gets called when \textclass is read at the
2984 // start of the read.
2985 list<string>::const_iterator rit = removed_modules_.begin();
2986 list<string>::const_iterator const ren = removed_modules_.end();
2987 for (; rit != ren; ++rit) {
2988 LayoutModuleList::iterator const mit = layout_modules_.begin();
2989 LayoutModuleList::iterator const men = layout_modules_.end();
2990 LayoutModuleList::iterator found = find(mit, men, *rit);
2993 layout_modules_.erase(found);
2998 void BufferParams::readIncludeonly(Lexer & lex)
3000 if (!lex.eatLine()) {
3001 lyxerr << "Error (BufferParams::readIncludeonly):"
3002 "Unexpected end of input." << endl;
3006 string child = lex.getString();
3007 if (child == "\\end_includeonly")
3009 included_children_.push_back(child);
3015 string BufferParams::paperSizeName(PapersizePurpose purpose) const
3017 switch (papersize) {
3019 // could be anything, so don't guess
3021 case PAPER_CUSTOM: {
3022 if (purpose == XDVI && !paperwidth.empty() &&
3023 !paperheight.empty()) {
3024 // heightxwidth<unit>
3025 string first = paperwidth;
3026 string second = paperheight;
3027 if (orientation == ORIENTATION_LANDSCAPE)
3030 return first.erase(first.length() - 2)
3036 // dvips and dvipdfm do not know this
3037 if (purpose == DVIPS || purpose == DVIPDFM)
3041 if (purpose == DVIPS || purpose == DVIPDFM)
3045 if (purpose == DVIPS || purpose == DVIPDFM)
3055 if (purpose == DVIPS || purpose == DVIPDFM)
3059 if (purpose == DVIPS || purpose == DVIPDFM)
3063 if (purpose == DVIPS || purpose == DVIPDFM)
3067 if (purpose == DVIPS || purpose == DVIPDFM)
3071 if (purpose == DVIPS || purpose == DVIPDFM)
3075 // dvipdfm does not know this
3076 if (purpose == DVIPDFM)
3080 if (purpose == DVIPDFM)
3084 if (purpose == DVIPS || purpose == DVIPDFM)
3088 if (purpose == DVIPS || purpose == DVIPDFM)
3092 if (purpose == DVIPS || purpose == DVIPDFM)
3096 if (purpose == DVIPS || purpose == DVIPDFM)
3100 if (purpose == DVIPS || purpose == DVIPDFM)
3104 if (purpose == DVIPS || purpose == DVIPDFM)
3108 if (purpose == DVIPS || purpose == DVIPDFM)
3112 if (purpose == DVIPS || purpose == DVIPDFM)
3116 if (purpose == DVIPS || purpose == DVIPDFM)
3120 if (purpose == DVIPS || purpose == DVIPDFM)
3124 if (purpose == DVIPS || purpose == DVIPDFM)
3128 if (purpose == DVIPS || purpose == DVIPDFM)
3132 if (purpose == DVIPS || purpose == DVIPDFM)
3136 if (purpose == DVIPS || purpose == DVIPDFM)
3140 if (purpose == DVIPS || purpose == DVIPDFM)
3143 case PAPER_USEXECUTIVE:
3144 // dvipdfm does not know this
3145 if (purpose == DVIPDFM)
3150 case PAPER_USLETTER:
3152 if (purpose == XDVI)
3159 string const BufferParams::dvips_options() const
3163 // If the class loads the geometry package, we do not know which
3164 // paper size is used, since we do not set it (bug 7013).
3165 // Therefore we must not specify any argument here.
3166 // dvips gets the correct paper size via DVI specials in this case
3167 // (if the class uses the geometry package correctly).
3168 if (documentClass().provides("geometry"))
3172 && papersize == PAPER_CUSTOM
3173 && !lyxrc.print_paper_dimension_flag.empty()
3174 && !paperwidth.empty()
3175 && !paperheight.empty()) {
3176 // using a custom papersize
3177 result = lyxrc.print_paper_dimension_flag;
3178 result += ' ' + paperwidth;
3179 result += ',' + paperheight;
3181 string const paper_option = paperSizeName(DVIPS);
3182 if (!paper_option.empty() && (paper_option != "letter" ||
3183 orientation != ORIENTATION_LANDSCAPE)) {
3184 // dvips won't accept -t letter -t landscape.
3185 // In all other cases, include the paper size
3187 result = lyxrc.print_paper_flag;
3188 result += ' ' + paper_option;
3191 if (orientation == ORIENTATION_LANDSCAPE &&
3192 papersize != PAPER_CUSTOM)
3193 result += ' ' + lyxrc.print_landscape_flag;
3198 string const BufferParams::main_font_encoding() const
3200 if (font_encodings().empty()) {
3201 if (ascii_lowercase(language->fontenc(*this)) == "none")
3205 return font_encodings().back();
3209 vector<string> const BufferParams::font_encodings() const
3211 string doc_fontenc = (fontenc == "auto") ? string() : fontenc;
3213 vector<string> fontencs;
3215 // "default" means "no explicit font encoding"
3216 if (doc_fontenc != "default") {
3217 if (!doc_fontenc.empty())
3218 // If we have a custom setting, we use only that!
3219 return getVectorFromString(doc_fontenc);
3220 if (!language->fontenc(*this).empty()
3221 && ascii_lowercase(language->fontenc(*this)) != "none") {
3222 vector<string> fencs = getVectorFromString(language->fontenc(*this));
3223 for (auto & fe : fencs) {
3224 if (find(fontencs.begin(), fontencs.end(), fe) == fontencs.end())
3225 fontencs.push_back(fe);
3234 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
3236 // suppress the babel call if there is no BabelName defined
3237 // for the document language in the lib/languages file and if no
3238 // other languages are used (lang_opts is then empty)
3239 if (lang_opts.empty())
3241 // The prefs may require the languages to
3242 // be submitted to babel itself (not the class).
3244 return "\\usepackage[" + lang_opts + "]{babel}";
3245 return "\\usepackage{babel}";
3249 docstring BufferParams::getGraphicsDriver(string const & package) const
3253 if (package == "geometry") {
3254 if (graphics_driver == "dvips"
3255 || graphics_driver == "dvipdfm"
3256 || graphics_driver == "pdftex"
3257 || graphics_driver == "vtex")
3258 result = from_ascii(graphics_driver);
3259 else if (graphics_driver == "dvipdfmx")
3260 result = from_ascii("dvipdfm");
3267 void BufferParams::writeEncodingPreamble(otexstream & os,
3268 LaTeXFeatures & features) const
3270 // With no-TeX fonts we use utf8-plain without encoding package.
3274 if (inputenc == "auto-legacy") {
3275 string const doc_encoding =
3276 language->encoding()->latexName();
3277 Encoding::Package const package =
3278 language->encoding()->package();
3280 // Create list of inputenc options:
3281 set<string> encoding_set;
3282 // luainputenc fails with more than one encoding
3283 if (features.runparams().flavor != OutputParams::LUATEX
3284 && features.runparams().flavor != OutputParams::DVILUATEX)
3285 // list all input encodings used in the document
3286 encoding_set = features.getEncodingSet(doc_encoding);
3288 // The "japanese" babel-language requires the pLaTeX engine
3289 // which conflicts with "inputenc".
3290 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
3291 if ((!encoding_set.empty() || package == Encoding::inputenc)
3292 && !features.isRequired("japanese")
3293 && !features.isProvided("inputenc")) {
3294 os << "\\usepackage[";
3295 set<string>::const_iterator it = encoding_set.begin();
3296 set<string>::const_iterator const end = encoding_set.end();
3298 os << from_ascii(*it);
3301 for (; it != end; ++it)
3302 os << ',' << from_ascii(*it);
3303 if (package == Encoding::inputenc) {
3304 if (!encoding_set.empty())
3306 os << from_ascii(doc_encoding);
3308 if (features.runparams().flavor == OutputParams::LUATEX
3309 || features.runparams().flavor == OutputParams::DVILUATEX)
3310 os << "]{luainputenc}\n";
3312 os << "]{inputenc}\n";
3314 } else if (inputenc != "auto-legacy-plain") {
3315 switch (encoding().package()) {
3316 case Encoding::none:
3318 case Encoding::japanese:
3319 if (encoding().iconvName() != "UTF-8"
3320 && !features.runparams().isFullUnicode())
3321 // don't default to [utf8]{inputenc} with TeXLive >= 18
3322 os << "\\ifdefined\\UseRawInputEncoding\n"
3323 << " \\UseRawInputEncoding\\fi\n";
3325 case Encoding::inputenc:
3326 // do not load inputenc if japanese is used
3327 // or if the class provides inputenc
3328 if (features.isRequired("japanese")
3329 || features.isProvided("inputenc"))
3331 if (features.runparams().flavor == OutputParams::XETEX)
3332 os << xetex_pre_inputenc;
3333 os << "\\usepackage[" << from_ascii(encoding().latexName());
3334 if (features.runparams().flavor == OutputParams::LUATEX
3335 || features.runparams().flavor == OutputParams::DVILUATEX)
3336 os << "]{luainputenc}\n";
3338 os << "]{inputenc}\n";
3339 if (features.runparams().flavor == OutputParams::XETEX)
3340 os << xetex_post_inputenc;
3344 if (inputenc == "auto-legacy-plain" || features.isRequired("japanese")) {
3345 // don't default to [utf8]{inputenc} with TeXLive >= 18
3346 os << "\\ifdefined\\UseRawInputEncoding\n";
3347 os << " \\UseRawInputEncoding\\fi\n";
3352 string const BufferParams::parseFontName(string const & name) const
3354 string mangled = name;
3355 size_t const idx = mangled.find('[');
3356 if (idx == string::npos || idx == 0)
3359 return mangled.substr(0, idx - 1);
3363 string const BufferParams::loadFonts(LaTeXFeatures & features) const
3365 if (fontsRoman() == "default" && fontsSans() == "default"
3366 && fontsTypewriter() == "default"
3367 && (fontsMath() == "default" || fontsMath() == "auto"))
3373 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
3374 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
3375 * Mapping=tex-text option assures TeX ligatures (such as "--")
3376 * are resolved. Note that tt does not use these ligatures.
3378 * -- add more GUI options?
3379 * -- add more fonts (fonts for other scripts)
3380 * -- if there's a way to find out if a font really supports
3381 * OldStyle, enable/disable the widget accordingly.
3383 if (useNonTeXFonts && features.isAvailable("fontspec")) {
3384 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
3385 // However, until v.2 (2010/07/11) fontspec only knew
3386 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
3387 // was introduced for both XeTeX and LuaTeX (LuaTeX
3388 // didn't understand "Mapping=tex-text", while XeTeX
3389 // understood both. With most recent versions, both
3390 // variants are understood by both engines. However,
3391 // we want to provide support for at least TeXLive 2009
3392 // (for XeTeX; LuaTeX is only supported as of v.2)
3393 string const texmapping =
3394 (features.runparams().flavor == OutputParams::XETEX) ?
3395 "Mapping=tex-text" : "Ligatures=TeX";
3396 if (fontsRoman() != "default") {
3397 os << "\\setmainfont[" << texmapping;
3398 if (fonts_old_figures)
3399 os << ",Numbers=OldStyle";
3400 os << "]{" << parseFontName(fontsRoman()) << "}\n";
3402 if (fontsSans() != "default") {
3403 string const sans = parseFontName(fontsSans());
3404 if (fontsSansScale() != 100)
3405 os << "\\setsansfont[Scale="
3406 << float(fontsSansScale()) / 100
3407 << "," << texmapping << "]{"
3410 os << "\\setsansfont[" << texmapping << "]{"
3413 if (fontsTypewriter() != "default") {
3414 string const mono = parseFontName(fontsTypewriter());
3415 if (fontsTypewriterScale() != 100)
3416 os << "\\setmonofont[Scale="
3417 << float(fontsTypewriterScale()) / 100
3421 os << "\\setmonofont{"
3428 bool const ot1 = (main_font_encoding() == "default" || main_font_encoding() == "OT1");
3429 bool const dryrun = features.runparams().dryrun;
3430 bool const complete = (fontsSans() == "default" && fontsTypewriter() == "default");
3431 bool const nomath = (fontsMath() == "default");
3434 os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsRoman())).getLaTeXCode(
3435 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3439 os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsSans())).getLaTeXCode(
3440 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3441 nomath, fontsSansScale());
3443 // MONOSPACED/TYPEWRITER
3444 os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsTypewriter())).getLaTeXCode(
3445 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3446 nomath, fontsTypewriterScale());
3449 os << theLaTeXFonts().getLaTeXFont(from_ascii(fontsMath())).getLaTeXCode(
3450 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3457 Encoding const & BufferParams::encoding() const
3459 // Main encoding for LaTeX output.
3461 return *(encodings.fromLyXName("utf8-plain"));
3462 if (inputenc == "auto-legacy" || inputenc == "auto-legacy-plain")
3463 return *language->encoding();
3464 if (inputenc == "utf8" && language->lang() == "japanese")
3465 return *(encodings.fromLyXName("utf8-platex"));
3466 Encoding const * const enc = encodings.fromLyXName(inputenc);
3469 LYXERR0("Unknown inputenc value `" << inputenc
3470 << "'. Using `auto' instead.");
3471 return *language->encoding();
3475 string const & BufferParams::defaultBiblioStyle() const
3477 if (!biblio_style.empty())
3478 return biblio_style;
3480 map<string, string> const & bs = documentClass().defaultBiblioStyle();
3481 auto cit = bs.find(theCiteEnginesList.getTypeAsString(citeEngineType()));
3482 if (cit != bs.end())
3485 return empty_string();
3489 bool const & BufferParams::fullAuthorList() const
3491 return documentClass().fullAuthorList();
3495 string BufferParams::getCiteAlias(string const & s) const
3497 vector<string> commands =
3498 documentClass().citeCommands(citeEngineType());
3499 // If it is a real command, don't treat it as an alias
3500 if (find(commands.begin(), commands.end(), s) != commands.end())
3502 map<string,string> aliases = documentClass().citeCommandAliases();
3503 if (aliases.find(s) != aliases.end())
3509 vector<string> BufferParams::citeCommands() const
3511 static CitationStyle const default_style;
3512 vector<string> commands =
3513 documentClass().citeCommands(citeEngineType());
3514 if (commands.empty())
3515 commands.push_back(default_style.name);
3520 vector<CitationStyle> BufferParams::citeStyles() const
3522 static CitationStyle const default_style;
3523 vector<CitationStyle> styles =
3524 documentClass().citeStyles(citeEngineType());
3526 styles.push_back(default_style);
3531 string const BufferParams::bibtexCommand() const
3533 // Return document-specific setting if available
3534 if (bibtex_command != "default")
3535 return bibtex_command;
3537 // If we have "default" in document settings, consult the prefs
3538 // 1. Japanese (uses a specific processor)
3539 if (encoding().package() == Encoding::japanese) {
3540 if (lyxrc.jbibtex_command != "automatic")
3541 // Return the specified program, if "automatic" is not set
3542 return lyxrc.jbibtex_command;
3543 else if (!useBiblatex()) {
3544 // With classic BibTeX, return pbibtex, jbibtex, bibtex
3545 if (lyxrc.jbibtex_alternatives.find("pbibtex") != lyxrc.jbibtex_alternatives.end())
3547 if (lyxrc.jbibtex_alternatives.find("jbibtex") != lyxrc.jbibtex_alternatives.end())
3552 // 2. All other languages
3553 else if (lyxrc.bibtex_command != "automatic")
3554 // Return the specified program, if "automatic" is not set
3555 return lyxrc.bibtex_command;
3557 // 3. Automatic: find the most suitable for the current cite framework
3558 if (useBiblatex()) {
3559 // For Biblatex, we prefer biber (also for Japanese)
3560 // and fall back to bibtex8 and, as last resort, bibtex
3561 if (lyxrc.bibtex_alternatives.find("biber") != lyxrc.bibtex_alternatives.end())
3563 else if (lyxrc.bibtex_alternatives.find("bibtex8") != lyxrc.bibtex_alternatives.end())
3570 bool BufferParams::useBiblatex() const
3572 return theCiteEnginesList[citeEngine()]->getCiteFramework() == "biblatex";
3576 void BufferParams::invalidateConverterCache() const
3578 pimpl_->isExportCacheValid = false;
3579 pimpl_->isViewCacheValid = false;
3583 // We shouldn't need to reset the params here, since anything
3584 // we need will be recopied.
3585 void BufferParams::copyForAdvFR(const BufferParams & bp)
3587 string const & lang = bp.language->lang();
3589 layout_modules_ = bp.layout_modules_;
3590 string const & doc_class = bp.documentClass().name();
3591 setBaseClass(doc_class);
3595 void BufferParams::setBibFileEncoding(string const & file, string const & enc)
3597 bib_encodings[file] = enc;
3601 string const BufferParams::bibFileEncoding(string const & file) const
3603 if (bib_encodings.find(file) == bib_encodings.end())
3605 return bib_encodings.find(file)->second;