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"
28 #include "Converter.h"
31 #include "IndicesList.h"
33 #include "LaTeXFeatures.h"
34 #include "LaTeXFonts.h"
35 #include "ModuleList.h"
39 #include "OutputParams.h"
43 #include "PDFOptions.h"
45 #include "frontends/alert.h"
47 #include "insets/InsetListingsParams.h"
49 #include "support/convert.h"
50 #include "support/debug.h"
51 #include "support/docstream.h"
52 #include "support/FileName.h"
53 #include "support/filetools.h"
54 #include "support/gettext.h"
55 #include "support/Messages.h"
56 #include "support/mutex.h"
57 #include "support/Package.h"
58 #include "support/Translator.h"
59 #include "support/lstrings.h"
65 using namespace lyx::support;
68 static char const * const string_paragraph_separation[] = {
73 static char const * const string_quotes_language[] = {
74 "english", "swedish", "german", "polish", "french", "danish", ""
78 static char const * const string_papersize[] = {
79 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
80 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
81 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
82 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
83 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
88 static char const * const string_orientation[] = {
89 "portrait", "landscape", ""
93 static char const * const tex_graphics[] = {
94 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
95 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
96 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
97 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
108 // Paragraph separation
109 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
112 ParSepTranslator const init_parseptranslator()
114 ParSepTranslator translator
115 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
116 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
121 ParSepTranslator const & parseptranslator()
123 static ParSepTranslator const translator =
124 init_parseptranslator();
130 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
133 QuotesLangTranslator const init_quoteslangtranslator()
135 QuotesLangTranslator translator
136 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
137 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
138 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
139 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
140 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
141 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
146 QuotesLangTranslator const & quoteslangtranslator()
148 static QuotesLangTranslator const translator =
149 init_quoteslangtranslator();
155 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
158 static PaperSizeTranslator initPaperSizeTranslator()
160 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
161 translator.addPair(string_papersize[1], PAPER_CUSTOM);
162 translator.addPair(string_papersize[2], PAPER_USLETTER);
163 translator.addPair(string_papersize[3], PAPER_USLEGAL);
164 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
165 translator.addPair(string_papersize[5], PAPER_A0);
166 translator.addPair(string_papersize[6], PAPER_A1);
167 translator.addPair(string_papersize[7], PAPER_A2);
168 translator.addPair(string_papersize[8], PAPER_A3);
169 translator.addPair(string_papersize[9], PAPER_A4);
170 translator.addPair(string_papersize[10], PAPER_A5);
171 translator.addPair(string_papersize[11], PAPER_A6);
172 translator.addPair(string_papersize[12], PAPER_B0);
173 translator.addPair(string_papersize[13], PAPER_B1);
174 translator.addPair(string_papersize[14], PAPER_B2);
175 translator.addPair(string_papersize[15], PAPER_B3);
176 translator.addPair(string_papersize[16], PAPER_B4);
177 translator.addPair(string_papersize[17], PAPER_B5);
178 translator.addPair(string_papersize[18], PAPER_B6);
179 translator.addPair(string_papersize[19], PAPER_C0);
180 translator.addPair(string_papersize[20], PAPER_C1);
181 translator.addPair(string_papersize[21], PAPER_C2);
182 translator.addPair(string_papersize[22], PAPER_C3);
183 translator.addPair(string_papersize[23], PAPER_C4);
184 translator.addPair(string_papersize[24], PAPER_C5);
185 translator.addPair(string_papersize[25], PAPER_C6);
186 translator.addPair(string_papersize[26], PAPER_JISB0);
187 translator.addPair(string_papersize[27], PAPER_JISB1);
188 translator.addPair(string_papersize[28], PAPER_JISB2);
189 translator.addPair(string_papersize[29], PAPER_JISB3);
190 translator.addPair(string_papersize[30], PAPER_JISB4);
191 translator.addPair(string_papersize[31], PAPER_JISB5);
192 translator.addPair(string_papersize[32], PAPER_JISB6);
197 PaperSizeTranslator const & papersizetranslator()
199 static PaperSizeTranslator const translator =
200 initPaperSizeTranslator();
206 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
209 PaperOrientationTranslator const init_paperorientationtranslator()
211 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
212 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
217 PaperOrientationTranslator const & paperorientationtranslator()
219 static PaperOrientationTranslator const translator =
220 init_paperorientationtranslator();
226 typedef Translator<int, PageSides> SidesTranslator;
229 SidesTranslator const init_sidestranslator()
231 SidesTranslator translator(1, OneSide);
232 translator.addPair(2, TwoSides);
237 SidesTranslator const & sidestranslator()
239 static SidesTranslator const translator = init_sidestranslator();
245 typedef Translator<int, BufferParams::Package> PackageTranslator;
248 PackageTranslator const init_packagetranslator()
250 PackageTranslator translator(0, BufferParams::package_off);
251 translator.addPair(1, BufferParams::package_auto);
252 translator.addPair(2, BufferParams::package_on);
257 PackageTranslator const & packagetranslator()
259 static PackageTranslator const translator =
260 init_packagetranslator();
266 typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
269 CiteEngineTypeTranslator const init_citeenginetypetranslator()
271 CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
272 translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
273 translator.addPair("default", ENGINE_TYPE_DEFAULT);
278 CiteEngineTypeTranslator const & citeenginetypetranslator()
280 static CiteEngineTypeTranslator const translator =
281 init_citeenginetypetranslator();
287 typedef Translator<string, Spacing::Space> SpaceTranslator;
290 SpaceTranslator const init_spacetranslator()
292 SpaceTranslator translator("default", Spacing::Default);
293 translator.addPair("single", Spacing::Single);
294 translator.addPair("onehalf", Spacing::Onehalf);
295 translator.addPair("double", Spacing::Double);
296 translator.addPair("other", Spacing::Other);
301 SpaceTranslator const & spacetranslator()
303 static SpaceTranslator const translator = init_spacetranslator();
310 class BufferParams::Impl
315 AuthorList authorlist;
316 BranchList branchlist;
317 Bullet temp_bullets[4];
318 Bullet user_defined_bullets[4];
319 IndicesList indiceslist;
321 /** This is the amount of space used for paragraph_separation "skip",
322 * and for detached paragraphs in "indented" documents.
326 PDFOptions pdfoptions;
327 LayoutFileIndex baseClass_;
331 BufferParams::Impl::Impl()
332 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
334 // set initial author
336 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
341 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
344 return new BufferParams::Impl(*ptr);
348 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
354 BufferParams::BufferParams()
357 setBaseClass(defaultBaseclass());
359 paragraph_separation = ParagraphIndentSeparation;
360 quotes_language = InsetQuotes::EnglishQuotes;
361 fontsize = "default";
364 papersize = PAPER_DEFAULT;
365 orientation = ORIENTATION_PORTRAIT;
366 use_geometry = false;
367 cite_engine_.push_back("basic");
368 cite_engine_type_ = ENGINE_TYPE_DEFAULT;
369 biblio_style = "plain";
370 use_bibtopic = false;
372 track_changes = false;
373 output_changes = false;
374 use_default_options = true;
375 maintain_unincluded_children = false;
378 language = default_language;
380 fonts_roman = "default";
381 fonts_sans = "default";
382 fonts_typewriter = "default";
384 fonts_default_family = "default";
385 useNonTeXFonts = false;
386 fonts_expert_sc = false;
387 fonts_old_figures = false;
388 fonts_sans_scale = 100;
389 fonts_typewriter_scale = 100;
391 lang_package = "default";
392 graphics_driver = "default";
393 default_output_format = "default";
394 bibtex_command = "default";
395 index_command = "default";
398 listings_params = string();
399 pagestyle = "default";
400 suppress_date = false;
401 justification = true;
402 // no color is the default (white)
403 backgroundcolor = lyx::rgbFromHexName("#ffffff");
404 isbackgroundcolor = false;
405 // no color is the default (black)
406 fontcolor = lyx::rgbFromHexName("#000000");
408 // light gray is the default font color for greyed-out notes
409 notefontcolor = lyx::rgbFromHexName("#cccccc");
410 boxbgcolor = lyx::rgbFromHexName("#ff0000");
411 compressed = lyxrc.save_compressed;
412 for (int iter = 0; iter < 4; ++iter) {
413 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
414 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
417 indiceslist().addDefault(B_("Index"));
418 html_be_strict = false;
419 html_math_output = MathML;
420 html_math_img_scale = 1.0;
421 html_css_as_file = false;
422 display_pixel_ratio = 1.0;
429 docstring BufferParams::B_(string const & l10n) const
431 LASSERT(language, return from_utf8(l10n));
432 return getMessages(language->code()).get(l10n);
436 BufferParams::Package BufferParams::use_package(std::string const & p) const
438 PackageMap::const_iterator it = use_packages.find(p);
439 if (it == use_packages.end())
445 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
451 map<string, string> const & BufferParams::auto_packages()
453 static map<string, string> packages;
454 if (packages.empty()) {
455 // We could have a race condition here that two threads
456 // discover an empty map at the same time and want to fill
457 // it, but that is no problem, since the same contents is
458 // filled in twice then. Having the locker inside the
459 // packages.empty() condition has the advantage that we
460 // don't need the mutex overhead for simple reading.
462 Mutex::Locker locker(&mutex);
463 // adding a package here implies a file format change!
464 packages["amsmath"] =
465 N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas");
466 packages["amssymb"] =
467 N_("The LaTeX package amssymb is only used if symbols from the AMS math toolbars are inserted into formulas");
469 N_("The LaTeX package cancel is only used if \\cancel commands are used in formulas");
471 N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas");
472 packages["mathdots"] =
473 N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas");
474 packages["mathtools"] =
475 N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas");
477 N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas");
478 packages["stackrel"] =
479 N_("The LaTeX package stackrel is only used if the command \\stackrel with subscript is inserted into formulas");
480 packages["stmaryrd"] =
481 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");
482 packages["undertilde"] =
483 N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'");
489 AuthorList & BufferParams::authors()
491 return pimpl_->authorlist;
495 AuthorList const & BufferParams::authors() const
497 return pimpl_->authorlist;
501 BranchList & BufferParams::branchlist()
503 return pimpl_->branchlist;
507 BranchList const & BufferParams::branchlist() const
509 return pimpl_->branchlist;
513 IndicesList & BufferParams::indiceslist()
515 return pimpl_->indiceslist;
519 IndicesList const & BufferParams::indiceslist() const
521 return pimpl_->indiceslist;
525 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
527 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
528 return pimpl_->temp_bullets[index];
532 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
534 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
535 return pimpl_->temp_bullets[index];
539 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
541 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
542 return pimpl_->user_defined_bullets[index];
546 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
548 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
549 return pimpl_->user_defined_bullets[index];
553 Spacing & BufferParams::spacing()
555 return pimpl_->spacing;
559 Spacing const & BufferParams::spacing() const
561 return pimpl_->spacing;
565 PDFOptions & BufferParams::pdfoptions()
567 return pimpl_->pdfoptions;
571 PDFOptions const & BufferParams::pdfoptions() const
573 return pimpl_->pdfoptions;
577 HSpace const & BufferParams::getIndentation() const
579 return pimpl_->indentation;
583 void BufferParams::setIndentation(HSpace const & indent)
585 pimpl_->indentation = indent;
589 VSpace const & BufferParams::getDefSkip() const
591 return pimpl_->defskip;
595 void BufferParams::setDefSkip(VSpace const & vs)
597 // DEFSKIP will cause an infinite loop
598 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
599 pimpl_->defskip = vs;
603 string BufferParams::readToken(Lexer & lex, string const & token,
604 FileName const & filepath)
608 if (token == "\\textclass") {
610 string const classname = lex.getString();
611 // if there exists a local layout file, ignore the system one
612 // NOTE: in this case, the textclass (.cls file) is assumed to
615 LayoutFileList & bcl = LayoutFileList::get();
616 if (!filepath.empty()) {
617 // If classname is an absolute path, the document is
618 // using a local layout file which could not be accessed
619 // by a relative path. In this case the path is correct
620 // even if the document was moved to a different
621 // location. However, we will have a problem if the
622 // document was generated on a different platform.
623 bool isabsolute = FileName::isAbsolute(classname);
624 string const classpath = onlyPath(classname);
625 string const path = isabsolute ? classpath
626 : FileName(addPath(filepath.absFileName(),
627 classpath)).realPath();
628 string const oldpath = isabsolute ? string()
629 : FileName(addPath(origin, classpath)).realPath();
630 tcp = bcl.addLocalLayout(onlyFileName(classname), path, oldpath);
632 // that returns non-empty if a "local" layout file is found.
634 result = to_utf8(makeRelPath(from_utf8(onlyPath(tcp)),
635 from_utf8(filepath.absFileName())));
638 setBaseClass(onlyFileName(tcp));
640 setBaseClass(onlyFileName(classname));
641 // We assume that a tex class exists for local or unknown
642 // layouts so this warning, will only be given for system layouts.
643 if (!baseClass()->isTeXClassAvailable()) {
644 docstring const desc =
645 translateIfPossible(from_utf8(baseClass()->description()));
646 docstring const prereqs =
647 from_utf8(baseClass()->prerequisites());
648 docstring const msg =
649 bformat(_("The selected document class\n"
651 "requires external files that are not available.\n"
652 "The document class can still be used, but the\n"
653 "document cannot be compiled until the following\n"
654 "prerequisites are installed:\n"
656 "See section 3.1.2.2 (Class Availability) of the\n"
657 "User's Guide for more information."), desc, prereqs);
658 frontend::Alert::warning(_("Document class not available"),
661 } else if (token == "\\origin") {
663 origin = lex.getString();
664 string const sysdirprefix = "/systemlyxdir/";
665 if (prefixIs(origin, sysdirprefix)) {
666 origin.replace(0, sysdirprefix.length() - 1,
667 package().system_support().absFileName());
669 } else if (token == "\\begin_preamble") {
671 } else if (token == "\\begin_local_layout") {
672 readLocalLayout(lex, false);
673 } else if (token == "\\begin_forced_local_layout") {
674 readLocalLayout(lex, true);
675 } else if (token == "\\begin_modules") {
677 } else if (token == "\\begin_removed_modules") {
678 readRemovedModules(lex);
679 } else if (token == "\\begin_includeonly") {
680 readIncludeonly(lex);
681 } else if (token == "\\maintain_unincluded_children") {
682 lex >> maintain_unincluded_children;
683 } else if (token == "\\options") {
685 options = lex.getString();
686 } else if (token == "\\use_default_options") {
687 lex >> use_default_options;
688 } else if (token == "\\master") {
690 master = lex.getString();
691 if (!filepath.empty() && FileName::isAbsolute(origin)) {
692 bool const isabs = FileName::isAbsolute(master);
693 FileName const abspath(isabs ? master : origin + master);
694 bool const moved = filepath != FileName(origin);
695 if (moved && abspath.exists()) {
696 docstring const path = isabs
698 : from_utf8(abspath.realPath());
699 docstring const refpath =
700 from_utf8(filepath.absFileName());
701 master = to_utf8(makeRelPath(path, refpath));
704 } else if (token == "\\suppress_date") {
705 lex >> suppress_date;
706 } else if (token == "\\justification") {
707 lex >> justification;
708 } else if (token == "\\language") {
710 } else if (token == "\\language_package") {
712 lang_package = lex.getString();
713 } else if (token == "\\inputencoding") {
715 } else if (token == "\\graphics") {
716 readGraphicsDriver(lex);
717 } else if (token == "\\default_output_format") {
718 lex >> default_output_format;
719 } else if (token == "\\bibtex_command") {
721 bibtex_command = lex.getString();
722 } else if (token == "\\index_command") {
724 index_command = lex.getString();
725 } else if (token == "\\fontencoding") {
727 fontenc = lex.getString();
728 } else if (token == "\\font_roman") {
730 fonts_roman = lex.getString();
731 } else if (token == "\\font_sans") {
733 fonts_sans = lex.getString();
734 } else if (token == "\\font_typewriter") {
736 fonts_typewriter = lex.getString();
737 } else if (token == "\\font_math") {
739 fonts_math = lex.getString();
740 } else if (token == "\\font_default_family") {
741 lex >> fonts_default_family;
742 } else if (token == "\\use_non_tex_fonts") {
743 lex >> useNonTeXFonts;
744 } else if (token == "\\font_sc") {
745 lex >> fonts_expert_sc;
746 } else if (token == "\\font_osf") {
747 lex >> fonts_old_figures;
748 } else if (token == "\\font_sf_scale") {
749 lex >> fonts_sans_scale;
750 } else if (token == "\\font_tt_scale") {
751 lex >> fonts_typewriter_scale;
752 } else if (token == "\\font_cjk") {
754 } else if (token == "\\paragraph_separation") {
757 paragraph_separation = parseptranslator().find(parsep);
758 } else if (token == "\\paragraph_indentation") {
760 string indentation = lex.getString();
761 pimpl_->indentation = HSpace(indentation);
762 } else if (token == "\\defskip") {
764 string const defskip = lex.getString();
765 pimpl_->defskip = VSpace(defskip);
766 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
768 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
769 } else if (token == "\\quotes_language") {
772 quotes_language = quoteslangtranslator().find(quotes_lang);
773 } else if (token == "\\papersize") {
776 papersize = papersizetranslator().find(ppsize);
777 } else if (token == "\\use_geometry") {
779 } else if (token == "\\use_package") {
784 use_package(package, packagetranslator().find(use));
785 } else if (token == "\\cite_engine") {
787 vector<string> engine = getVectorFromString(lex.getString());
788 setCiteEngine(engine);
789 } else if (token == "\\cite_engine_type") {
792 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
793 } else if (token == "\\biblio_style") {
795 biblio_style = lex.getString();
796 } else if (token == "\\use_bibtopic") {
798 } else if (token == "\\use_indices") {
800 } else if (token == "\\tracking_changes") {
801 lex >> track_changes;
802 } else if (token == "\\output_changes") {
803 lex >> output_changes;
804 } else if (token == "\\branch") {
806 docstring branch = lex.getDocString();
807 branchlist().add(branch);
810 string const tok = lex.getString();
811 if (tok == "\\end_branch")
813 Branch * branch_ptr = branchlist().find(branch);
814 if (tok == "\\selected") {
817 branch_ptr->setSelected(lex.getInteger());
819 if (tok == "\\filename_suffix") {
822 branch_ptr->setFileNameSuffix(lex.getInteger());
824 if (tok == "\\color") {
826 string color = lex.getString();
828 branch_ptr->setColor(color);
829 // Update also the Color table:
831 color = lcolor.getX11Name(Color_background);
833 lcolor.setColor(to_utf8(branch), color);
836 } else if (token == "\\index") {
838 docstring index = lex.getDocString();
840 indiceslist().add(index);
843 string const tok = lex.getString();
844 if (tok == "\\end_index")
846 Index * index_ptr = indiceslist().find(index);
847 if (tok == "\\shortcut") {
849 shortcut = lex.getDocString();
851 index_ptr->setShortcut(shortcut);
853 if (tok == "\\color") {
855 string color = lex.getString();
857 index_ptr->setColor(color);
858 // Update also the Color table:
860 color = lcolor.getX11Name(Color_background);
862 if (!shortcut.empty())
863 lcolor.setColor(to_utf8(shortcut), color);
866 } else if (token == "\\author") {
868 istringstream ss(lex.getString());
871 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
872 } else if (token == "\\paperorientation") {
875 orientation = paperorientationtranslator().find(orient);
876 } else if (token == "\\backgroundcolor") {
878 backgroundcolor = lyx::rgbFromHexName(lex.getString());
879 isbackgroundcolor = true;
880 } else if (token == "\\fontcolor") {
882 fontcolor = lyx::rgbFromHexName(lex.getString());
884 } else if (token == "\\notefontcolor") {
886 string color = lex.getString();
887 notefontcolor = lyx::rgbFromHexName(color);
888 lcolor.setColor("notefontcolor", color);
889 } else if (token == "\\boxbgcolor") {
891 string color = lex.getString();
892 boxbgcolor = lyx::rgbFromHexName(color);
893 lcolor.setColor("boxbgcolor", color);
894 } else if (token == "\\paperwidth") {
896 } else if (token == "\\paperheight") {
898 } else if (token == "\\leftmargin") {
900 } else if (token == "\\topmargin") {
902 } else if (token == "\\rightmargin") {
904 } else if (token == "\\bottommargin") {
906 } else if (token == "\\headheight") {
908 } else if (token == "\\headsep") {
910 } else if (token == "\\footskip") {
912 } else if (token == "\\columnsep") {
914 } else if (token == "\\paperfontsize") {
916 } else if (token == "\\papercolumns") {
918 } else if (token == "\\listings_params") {
921 listings_params = InsetListingsParams(par).params();
922 } else if (token == "\\papersides") {
925 sides = sidestranslator().find(psides);
926 } else if (token == "\\paperpagestyle") {
928 } else if (token == "\\bullet") {
930 } else if (token == "\\bulletLaTeX") {
931 readBulletsLaTeX(lex);
932 } else if (token == "\\secnumdepth") {
934 } else if (token == "\\tocdepth") {
936 } else if (token == "\\spacing") {
940 if (nspacing == "other") {
943 spacing().set(spacetranslator().find(nspacing), tmp_val);
944 } else if (token == "\\float_placement") {
945 lex >> float_placement;
947 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
948 string toktmp = pdfoptions().readToken(lex, token);
949 if (!toktmp.empty()) {
950 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
954 } else if (token == "\\html_math_output") {
957 html_math_output = static_cast<MathOutput>(temp);
958 } else if (token == "\\html_be_strict") {
959 lex >> html_be_strict;
960 } else if (token == "\\html_css_as_file") {
961 lex >> html_css_as_file;
962 } else if (token == "\\html_math_img_scale") {
963 lex >> html_math_img_scale;
964 } else if (token == "\\html_latex_start") {
966 html_latex_start = lex.getString();
967 } else if (token == "\\html_latex_end") {
969 html_latex_end = lex.getString();
970 } else if (token == "\\output_sync") {
972 } else if (token == "\\output_sync_macro") {
973 lex >> output_sync_macro;
974 } else if (token == "\\use_refstyle") {
977 lyxerr << "BufferParams::readToken(): Unknown token: " <<
986 void BufferParams::writeFile(ostream & os, Buffer const * buf) const
988 // The top of the file is written by the buffer.
989 // Prints out the buffer info into the .lyx file given by file
991 // the document directory
992 string filepath = buf->filePath();
993 string const sysdir = package().system_support().absFileName();
994 if (prefixIs(filepath, sysdir))
995 filepath.replace(0, sysdir.length(), "/systemlyxdir/");
996 else if (!lyxrc.save_origin)
997 filepath = "unavailable";
998 os << "\\origin " << filepath << '\n';
1001 os << "\\textclass " << buf->includedFilePath(addName(buf->layoutPos(),
1002 baseClass()->name()), "layout")
1005 // then the preamble
1006 if (!preamble.empty()) {
1007 // remove '\n' from the end of preamble
1008 string const tmppreamble = rtrim(preamble, "\n");
1009 os << "\\begin_preamble\n"
1011 << "\n\\end_preamble\n";
1015 if (!options.empty()) {
1016 os << "\\options " << options << '\n';
1019 // use the class options defined in the layout?
1020 os << "\\use_default_options "
1021 << convert<string>(use_default_options) << "\n";
1023 // the master document
1024 if (!master.empty()) {
1025 os << "\\master " << master << '\n';
1029 if (!removed_modules_.empty()) {
1030 os << "\\begin_removed_modules" << '\n';
1031 list<string>::const_iterator it = removed_modules_.begin();
1032 list<string>::const_iterator en = removed_modules_.end();
1033 for (; it != en; ++it)
1035 os << "\\end_removed_modules" << '\n';
1039 if (!layout_modules_.empty()) {
1040 os << "\\begin_modules" << '\n';
1041 LayoutModuleList::const_iterator it = layout_modules_.begin();
1042 LayoutModuleList::const_iterator en = layout_modules_.end();
1043 for (; it != en; ++it)
1045 os << "\\end_modules" << '\n';
1049 if (!included_children_.empty()) {
1050 os << "\\begin_includeonly" << '\n';
1051 list<string>::const_iterator it = included_children_.begin();
1052 list<string>::const_iterator en = included_children_.end();
1053 for (; it != en; ++it)
1055 os << "\\end_includeonly" << '\n';
1057 os << "\\maintain_unincluded_children "
1058 << convert<string>(maintain_unincluded_children) << '\n';
1060 // local layout information
1061 string const local_layout = getLocalLayout(false);
1062 if (!local_layout.empty()) {
1063 // remove '\n' from the end
1064 string const tmplocal = rtrim(local_layout, "\n");
1065 os << "\\begin_local_layout\n"
1067 << "\n\\end_local_layout\n";
1069 string const forced_local_layout = getLocalLayout(true);
1070 if (!forced_local_layout.empty()) {
1071 // remove '\n' from the end
1072 string const tmplocal = rtrim(forced_local_layout, "\n");
1073 os << "\\begin_forced_local_layout\n"
1075 << "\n\\end_forced_local_layout\n";
1078 // then the text parameters
1079 if (language != ignore_language)
1080 os << "\\language " << language->lang() << '\n';
1081 os << "\\language_package " << lang_package
1082 << "\n\\inputencoding " << inputenc
1083 << "\n\\fontencoding " << fontenc
1084 << "\n\\font_roman " << fonts_roman
1085 << "\n\\font_sans " << fonts_sans
1086 << "\n\\font_typewriter " << fonts_typewriter
1087 << "\n\\font_math " << fonts_math
1088 << "\n\\font_default_family " << fonts_default_family
1089 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
1090 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
1091 << "\n\\font_osf " << convert<string>(fonts_old_figures)
1092 << "\n\\font_sf_scale " << fonts_sans_scale
1093 << "\n\\font_tt_scale " << fonts_typewriter_scale
1095 if (!fonts_cjk.empty()) {
1096 os << "\\font_cjk " << fonts_cjk << '\n';
1098 os << "\\graphics " << graphics_driver << '\n';
1099 os << "\\default_output_format " << default_output_format << '\n';
1100 os << "\\output_sync " << output_sync << '\n';
1101 if (!output_sync_macro.empty())
1102 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1103 os << "\\bibtex_command " << bibtex_command << '\n';
1104 os << "\\index_command " << index_command << '\n';
1106 if (!float_placement.empty()) {
1107 os << "\\float_placement " << float_placement << '\n';
1109 os << "\\paperfontsize " << fontsize << '\n';
1111 spacing().writeFile(os);
1112 pdfoptions().writeFile(os);
1114 os << "\\papersize " << string_papersize[papersize]
1115 << "\n\\use_geometry " << convert<string>(use_geometry);
1116 map<string, string> const & packages = auto_packages();
1117 for (map<string, string>::const_iterator it = packages.begin();
1118 it != packages.end(); ++it)
1119 os << "\n\\use_package " << it->first << ' '
1120 << use_package(it->first);
1122 os << "\n\\cite_engine ";
1124 if (!cite_engine_.empty()) {
1125 LayoutModuleList::const_iterator be = cite_engine_.begin();
1126 LayoutModuleList::const_iterator en = cite_engine_.end();
1127 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1136 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1137 << "\n\\biblio_style " << biblio_style
1138 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1139 << "\n\\use_indices " << convert<string>(use_indices)
1140 << "\n\\paperorientation " << string_orientation[orientation]
1141 << "\n\\suppress_date " << convert<string>(suppress_date)
1142 << "\n\\justification " << convert<string>(justification)
1143 << "\n\\use_refstyle " << use_refstyle
1145 if (isbackgroundcolor == true)
1146 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1147 if (isfontcolor == true)
1148 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1149 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1150 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1151 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1152 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1154 BranchList::const_iterator it = branchlist().begin();
1155 BranchList::const_iterator end = branchlist().end();
1156 for (; it != end; ++it) {
1157 os << "\\branch " << to_utf8(it->branch())
1158 << "\n\\selected " << it->isSelected()
1159 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1160 << "\n\\color " << lyx::X11hexname(it->color())
1165 IndicesList::const_iterator iit = indiceslist().begin();
1166 IndicesList::const_iterator iend = indiceslist().end();
1167 for (; iit != iend; ++iit) {
1168 os << "\\index " << to_utf8(iit->index())
1169 << "\n\\shortcut " << to_utf8(iit->shortcut())
1170 << "\n\\color " << lyx::X11hexname(iit->color())
1175 if (!paperwidth.empty())
1176 os << "\\paperwidth "
1177 << VSpace(paperwidth).asLyXCommand() << '\n';
1178 if (!paperheight.empty())
1179 os << "\\paperheight "
1180 << VSpace(paperheight).asLyXCommand() << '\n';
1181 if (!leftmargin.empty())
1182 os << "\\leftmargin "
1183 << VSpace(leftmargin).asLyXCommand() << '\n';
1184 if (!topmargin.empty())
1185 os << "\\topmargin "
1186 << VSpace(topmargin).asLyXCommand() << '\n';
1187 if (!rightmargin.empty())
1188 os << "\\rightmargin "
1189 << VSpace(rightmargin).asLyXCommand() << '\n';
1190 if (!bottommargin.empty())
1191 os << "\\bottommargin "
1192 << VSpace(bottommargin).asLyXCommand() << '\n';
1193 if (!headheight.empty())
1194 os << "\\headheight "
1195 << VSpace(headheight).asLyXCommand() << '\n';
1196 if (!headsep.empty())
1198 << VSpace(headsep).asLyXCommand() << '\n';
1199 if (!footskip.empty())
1201 << VSpace(footskip).asLyXCommand() << '\n';
1202 if (!columnsep.empty())
1203 os << "\\columnsep "
1204 << VSpace(columnsep).asLyXCommand() << '\n';
1205 os << "\\secnumdepth " << secnumdepth
1206 << "\n\\tocdepth " << tocdepth
1207 << "\n\\paragraph_separation "
1208 << string_paragraph_separation[paragraph_separation];
1209 if (!paragraph_separation)
1210 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1212 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1213 os << "\n\\quotes_language "
1214 << string_quotes_language[quotes_language]
1215 << "\n\\papercolumns " << columns
1216 << "\n\\papersides " << sides
1217 << "\n\\paperpagestyle " << pagestyle << '\n';
1218 if (!listings_params.empty())
1219 os << "\\listings_params \"" <<
1220 InsetListingsParams(listings_params).encodedString() << "\"\n";
1221 for (int i = 0; i < 4; ++i) {
1222 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1223 if (user_defined_bullet(i).getFont() != -1) {
1224 os << "\\bullet " << i << " "
1225 << user_defined_bullet(i).getFont() << " "
1226 << user_defined_bullet(i).getCharacter() << " "
1227 << user_defined_bullet(i).getSize() << "\n";
1231 os << "\\bulletLaTeX " << i << " \""
1232 << lyx::to_ascii(user_defined_bullet(i).getText())
1238 os << "\\tracking_changes " << convert<string>(track_changes) << '\n'
1239 << "\\output_changes " << convert<string>(output_changes) << '\n'
1240 << "\\html_math_output " << html_math_output << '\n'
1241 << "\\html_css_as_file " << html_css_as_file << '\n'
1242 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1244 if (html_math_img_scale != 1.0)
1245 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1246 if (!html_latex_start.empty())
1247 os << "\\html_latex_start " << html_latex_start << '\n';
1248 if (!html_latex_end.empty())
1249 os << "\\html_latex_end " << html_latex_end << '\n';
1251 os << pimpl_->authorlist;
1255 void BufferParams::validate(LaTeXFeatures & features) const
1257 features.require(documentClass().requires());
1259 if (columns > 1 && language->rightToLeft())
1260 features.require("rtloutputdblcol");
1262 if (output_changes) {
1263 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1264 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1265 LaTeXFeatures::isAvailable("xcolor");
1267 switch (features.runparams().flavor) {
1268 case OutputParams::LATEX:
1269 case OutputParams::DVILUATEX:
1271 features.require("ct-dvipost");
1272 features.require("dvipost");
1273 } else if (xcolorulem) {
1274 features.require("ct-xcolor-ulem");
1275 features.require("ulem");
1276 features.require("xcolor");
1278 features.require("ct-none");
1281 case OutputParams::LUATEX:
1282 case OutputParams::PDFLATEX:
1283 case OutputParams::XETEX:
1285 features.require("ct-xcolor-ulem");
1286 features.require("ulem");
1287 features.require("xcolor");
1288 // improves color handling in PDF output
1289 features.require("pdfcolmk");
1291 features.require("ct-none");
1299 // Floats with 'Here definitely' as default setting.
1300 if (float_placement.find('H') != string::npos)
1301 features.require("float");
1303 for (PackageMap::const_iterator it = use_packages.begin();
1304 it != use_packages.end(); ++it) {
1305 if (it->first == "amsmath") {
1306 // AMS Style is at document level
1307 if (it->second == package_on ||
1308 features.isProvided("amsmath"))
1309 features.require(it->first);
1310 } else if (it->second == package_on)
1311 features.require(it->first);
1314 // Document-level line spacing
1315 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1316 features.require("setspace");
1318 // the bullet shapes are buffer level not paragraph level
1319 // so they are tested here
1320 for (int i = 0; i < 4; ++i) {
1321 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1323 int const font = user_defined_bullet(i).getFont();
1325 int const c = user_defined_bullet(i).getCharacter();
1331 features.require("latexsym");
1333 } else if (font == 1) {
1334 features.require("amssymb");
1335 } else if (font >= 2 && font <= 5) {
1336 features.require("pifont");
1340 if (pdfoptions().use_hyperref) {
1341 features.require("hyperref");
1342 // due to interferences with babel and hyperref, the color package has to
1343 // be loaded after hyperref when hyperref is used with the colorlinks
1344 // option, see http://www.lyx.org/trac/ticket/5291
1345 if (pdfoptions().colorlinks)
1346 features.require("color");
1348 if (!listings_params.empty()) {
1349 // do not test validity because listings_params is
1350 // supposed to be valid
1352 InsetListingsParams(listings_params).separatedParams(true);
1353 // we can't support all packages, but we should load the color package
1354 if (par.find("\\color", 0) != string::npos)
1355 features.require("color");
1358 // some languages are only available via polyglossia
1359 if ((features.runparams().flavor == OutputParams::XETEX
1360 || features.runparams().flavor == OutputParams::LUATEX)
1361 && (features.hasPolyglossiaExclusiveLanguages()
1363 features.require("polyglossia");
1365 if (useNonTeXFonts && fonts_math != "auto")
1366 features.require("unicode-math");
1368 if (!language->requires().empty())
1369 features.require(language->requires());
1373 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1374 FileName const & filepath) const
1376 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1377 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1378 // \RequirePackage to do so, rather than the normal \usepackage
1379 // Do not try to load any other package before the document class, unless you
1380 // have a thorough understanding of the LATEX internals and know exactly what you
1382 if (features.mustProvide("fix-cm"))
1383 os << "\\RequirePackage{fix-cm}\n";
1384 // Likewise for fixltx2e. If other packages conflict with this policy,
1385 // treat it as a package bug (and report it!)
1386 // See http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/4407
1387 if (features.mustProvide("fixltx2e"))
1388 os << "\\RequirePackage{fixltx2e}\n";
1390 os << "\\documentclass";
1392 DocumentClass const & tclass = documentClass();
1394 ostringstream clsoptions; // the document class options.
1396 if (tokenPos(tclass.opt_fontsize(),
1397 '|', fontsize) >= 0) {
1398 // only write if existing in list (and not default)
1399 clsoptions << fontsize << "pt,";
1402 // all paper sizes except of A4, A5, B5 and the US sizes need the
1404 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1405 && papersize != PAPER_USLETTER
1406 && papersize != PAPER_USLEGAL
1407 && papersize != PAPER_USEXECUTIVE
1408 && papersize != PAPER_A4
1409 && papersize != PAPER_A5
1410 && papersize != PAPER_B5;
1412 if (!use_geometry) {
1413 switch (papersize) {
1415 clsoptions << "a4paper,";
1417 case PAPER_USLETTER:
1418 clsoptions << "letterpaper,";
1421 clsoptions << "a5paper,";
1424 clsoptions << "b5paper,";
1426 case PAPER_USEXECUTIVE:
1427 clsoptions << "executivepaper,";
1430 clsoptions << "legalpaper,";
1464 if (sides != tclass.sides()) {
1467 clsoptions << "oneside,";
1470 clsoptions << "twoside,";
1476 if (columns != tclass.columns()) {
1478 clsoptions << "twocolumn,";
1480 clsoptions << "onecolumn,";
1484 && orientation == ORIENTATION_LANDSCAPE)
1485 clsoptions << "landscape,";
1487 // language should be a parameter to \documentclass
1488 if (language->babel() == "hebrew"
1489 && default_language->babel() != "hebrew")
1490 // This seems necessary
1491 features.useLanguage(default_language);
1493 ostringstream language_options;
1494 bool const use_babel = features.useBabel() && !features.isProvided("babel");
1495 bool const use_polyglossia = features.usePolyglossia();
1496 bool const global = lyxrc.language_global_options;
1497 if (use_babel || (use_polyglossia && global)) {
1498 language_options << features.getBabelLanguages();
1499 if (!language->babel().empty()) {
1500 if (!language_options.str().empty())
1501 language_options << ',';
1502 language_options << language->babel();
1504 if (global && !features.needBabelLangOptions()
1505 && !language_options.str().empty())
1506 clsoptions << language_options.str() << ',';
1509 // the predefined options from the layout
1510 if (use_default_options && !tclass.options().empty())
1511 clsoptions << tclass.options() << ',';
1513 // the user-defined options
1514 if (!options.empty()) {
1515 clsoptions << options << ',';
1518 string strOptions(clsoptions.str());
1519 if (!strOptions.empty()) {
1520 strOptions = rtrim(strOptions, ",");
1522 os << '[' << from_utf8(strOptions) << ']';
1525 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1526 // end of \documentclass defs
1528 // if we use fontspec or newtxmath, we have to load the AMS packages here
1529 string const ams = features.loadAMSPackages();
1530 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
1531 bool const use_newtxmath =
1532 theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getUsedPackage(
1533 ot1, false, false) == "newtxmath";
1534 if ((useNonTeXFonts || use_newtxmath) && !ams.empty())
1535 os << from_ascii(ams);
1537 if (useNonTeXFonts) {
1538 os << "\\usepackage{fontspec}\n";
1539 if (features.mustProvide("unicode-math")
1540 && features.isAvailable("unicode-math"))
1541 os << "\\usepackage{unicode-math}\n";
1544 // font selection must be done before loading fontenc.sty
1545 string const fonts = loadFonts(features);
1547 os << from_utf8(fonts);
1549 if (fonts_default_family != "default")
1550 os << "\\renewcommand{\\familydefault}{\\"
1551 << from_ascii(fonts_default_family) << "}\n";
1553 // set font encoding
1554 // XeTeX and LuaTeX (with OS fonts) do not need fontenc
1555 if (!useNonTeXFonts && !features.isProvided("fontenc")
1556 && font_encoding() != "default") {
1557 // get main font encodings
1558 vector<string> fontencs = font_encodings();
1559 // get font encodings of secondary languages
1560 features.getFontEncodings(fontencs);
1561 if (!fontencs.empty()) {
1562 os << "\\usepackage["
1563 << from_ascii(getStringFromVector(fontencs))
1568 // handle inputenc etc.
1569 writeEncodingPreamble(os, features);
1572 if (!features.runparams().includeall && !included_children_.empty()) {
1573 os << "\\includeonly{";
1574 list<string>::const_iterator it = included_children_.begin();
1575 list<string>::const_iterator en = included_children_.end();
1577 for (; it != en; ++it) {
1578 string incfile = *it;
1579 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1580 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1582 if (!features.runparams().nice)
1584 // \includeonly doesn't want an extension
1585 incfile = changeExtension(incfile, string());
1586 incfile = support::latex_path(incfile);
1587 if (!incfile.empty()) {
1590 os << from_utf8(incfile);
1597 if (!features.isProvided("geometry")
1598 && (use_geometry || nonstandard_papersize)) {
1599 odocstringstream ods;
1600 if (!getGraphicsDriver("geometry").empty())
1601 ods << getGraphicsDriver("geometry");
1602 if (orientation == ORIENTATION_LANDSCAPE)
1603 ods << ",landscape";
1604 switch (papersize) {
1606 if (!paperwidth.empty())
1607 ods << ",paperwidth="
1608 << from_ascii(paperwidth);
1609 if (!paperheight.empty())
1610 ods << ",paperheight="
1611 << from_ascii(paperheight);
1613 case PAPER_USLETTER:
1614 ods << ",letterpaper";
1617 ods << ",legalpaper";
1619 case PAPER_USEXECUTIVE:
1620 ods << ",executivepaper";
1709 docstring const g_options = trim(ods.str(), ",");
1710 os << "\\usepackage";
1711 if (!g_options.empty())
1712 os << '[' << g_options << ']';
1713 os << "{geometry}\n";
1714 // output this only if use_geometry is true
1716 os << "\\geometry{verbose";
1717 if (!topmargin.empty())
1718 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1719 if (!bottommargin.empty())
1720 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1721 if (!leftmargin.empty())
1722 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1723 if (!rightmargin.empty())
1724 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1725 if (!headheight.empty())
1726 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1727 if (!headsep.empty())
1728 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1729 if (!footskip.empty())
1730 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1731 if (!columnsep.empty())
1732 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1735 } else if (orientation == ORIENTATION_LANDSCAPE
1736 || papersize != PAPER_DEFAULT) {
1737 features.require("papersize");
1740 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1741 if (pagestyle == "fancy")
1742 os << "\\usepackage{fancyhdr}\n";
1743 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1746 // only output when the background color is not default
1747 if (isbackgroundcolor == true) {
1748 // only require color here, the background color will be defined
1749 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1751 features.require("color");
1752 features.require("pagecolor");
1755 // only output when the font color is not default
1756 if (isfontcolor == true) {
1757 // only require color here, the font color will be defined
1758 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1760 features.require("color");
1761 features.require("fontcolor");
1764 // Only if class has a ToC hierarchy
1765 if (tclass.hasTocLevels()) {
1766 if (secnumdepth != tclass.secnumdepth()) {
1767 os << "\\setcounter{secnumdepth}{"
1771 if (tocdepth != tclass.tocdepth()) {
1772 os << "\\setcounter{tocdepth}{"
1778 if (paragraph_separation) {
1779 // when skip separation
1780 switch (getDefSkip().kind()) {
1781 case VSpace::SMALLSKIP:
1782 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1784 case VSpace::MEDSKIP:
1785 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1787 case VSpace::BIGSKIP:
1788 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1790 case VSpace::LENGTH:
1791 os << "\\setlength{\\parskip}{"
1792 << from_utf8(getDefSkip().length().asLatexString())
1795 default: // should never happen // Then delete it.
1796 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1799 os << "\\setlength{\\parindent}{0pt}\n";
1801 // when separation by indentation
1802 // only output something when a width is given
1803 if (getIndentation().asLyXCommand() != "default") {
1804 os << "\\setlength{\\parindent}{"
1805 << from_utf8(getIndentation().asLatexCommand())
1810 // Now insert the LyX specific LaTeX commands...
1811 docstring lyxpreamble;
1812 features.resolveAlternatives();
1815 if (!output_sync_macro.empty())
1816 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1817 else if (features.runparams().flavor == OutputParams::LATEX)
1818 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1819 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1820 lyxpreamble += "\\synctex=-1\n";
1823 // The package options (via \PassOptionsToPackage)
1824 lyxpreamble += from_ascii(features.getPackageOptions());
1826 // due to interferences with babel and hyperref, the color package has to
1827 // be loaded (when it is not already loaded) before babel when hyperref
1828 // is used with the colorlinks option, see
1829 // http://www.lyx.org/trac/ticket/5291
1830 // we decided therefore to load color always before babel, see
1831 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1832 lyxpreamble += from_ascii(features.getColorOptions());
1834 // If we use hyperref, jurabib, japanese, varioref or vietnamese,
1835 // we have to call babel before
1837 && (features.isRequired("jurabib")
1838 || features.isRequired("hyperref")
1839 || features.isRequired("varioref")
1840 || features.isRequired("vietnamese")
1841 || features.isRequired("japanese"))) {
1843 lyxpreamble += from_utf8(features.getBabelPresettings());
1844 lyxpreamble += from_utf8(babelCall(language_options.str(),
1845 features.needBabelLangOptions())) + '\n';
1846 lyxpreamble += from_utf8(features.getBabelPostsettings());
1849 // The optional packages;
1850 lyxpreamble += from_ascii(features.getPackages());
1852 // Additional Indices
1853 if (features.isRequired("splitidx")) {
1854 IndicesList::const_iterator iit = indiceslist().begin();
1855 IndicesList::const_iterator iend = indiceslist().end();
1856 for (; iit != iend; ++iit) {
1857 pair<docstring, docstring> indexname_latex =
1858 features.runparams().encoding->latexString(iit->index(),
1859 features.runparams().dryrun);
1860 if (!indexname_latex.second.empty()) {
1861 // issue a warning about omitted characters
1862 // FIXME: should be passed to the error dialog
1863 frontend::Alert::warning(_("Uncodable characters"),
1864 bformat(_("The following characters that are used in an index name are not\n"
1865 "representable in the current encoding and therefore have been omitted:\n%1$s."),
1866 indexname_latex.second));
1868 lyxpreamble += "\\newindex[";
1869 lyxpreamble += indexname_latex.first;
1870 lyxpreamble += "]{";
1871 lyxpreamble += escape(iit->shortcut());
1872 lyxpreamble += "}\n";
1877 lyxpreamble += from_utf8(spacing().writePreamble(features.isProvided("SetSpace")));
1880 // * Hyperref manual: "Make sure it comes last of your loaded
1881 // packages, to give it a fighting chance of not being over-written,
1882 // since its job is to redefine many LaTeX commands."
1883 // * Email from Heiko Oberdiek: "It is usually better to load babel
1884 // before hyperref. Then hyperref has a chance to detect babel.
1885 // * Has to be loaded before the "LyX specific LaTeX commands" to
1886 // avoid errors with algorithm floats.
1887 // use hyperref explicitly if it is required
1888 if (features.isRequired("hyperref")) {
1889 // pass what we have to stream here, since we need
1890 // to access the stream itself in PDFOptions.
1893 OutputParams tmp_params = features.runparams();
1894 pdfoptions().writeLaTeX(tmp_params, os,
1895 features.isProvided("hyperref"));
1896 // set back for the rest
1897 lyxpreamble.clear();
1898 // correctly break URLs with hyperref and dvi output
1899 if (features.runparams().flavor == OutputParams::LATEX
1900 && features.isAvailable("breakurl"))
1901 lyxpreamble += "\\usepackage{breakurl}\n";
1902 } else if (features.isRequired("nameref"))
1903 // hyperref loads this automatically
1904 lyxpreamble += "\\usepackage{nameref}\n";
1906 // bibtopic needs to be loaded after hyperref.
1907 // the dot provides the aux file naming which LyX can detect.
1908 if (features.mustProvide("bibtopic"))
1909 lyxpreamble += "\\usepackage[dot]{bibtopic}\n";
1911 // Will be surrounded by \makeatletter and \makeatother when not empty
1912 docstring atlyxpreamble;
1914 // Some macros LyX will need
1915 docstring tmppreamble(features.getMacros());
1917 if (!tmppreamble.empty())
1918 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1919 "LyX specific LaTeX commands.\n"
1920 + tmppreamble + '\n';
1922 // the text class specific preamble
1923 tmppreamble = features.getTClassPreamble();
1924 if (!tmppreamble.empty())
1925 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1926 "Textclass specific LaTeX commands.\n"
1927 + tmppreamble + '\n';
1929 // suppress date if selected
1930 // use \@ifundefined because we cannot be sure that every document class
1931 // has a \date command
1933 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1935 /* the user-defined preamble */
1936 if (!containsOnly(preamble, " \n\t")) {
1938 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1939 "User specified LaTeX commands.\n";
1941 // Check if the user preamble contains uncodable glyphs
1942 docstring const u_preamble = from_utf8(preamble);
1943 odocstringstream user_preamble;
1944 docstring uncodable_glyphs;
1945 Encoding const * const enc = features.runparams().encoding;
1947 for (size_t n = 0; n < u_preamble.size(); ++n) {
1948 char_type c = u_preamble[n];
1949 if (!enc->encodable(c)) {
1950 docstring const glyph(1, c);
1951 LYXERR0("Uncodable character '"
1953 << "' in user preamble!");
1954 uncodable_glyphs += glyph;
1955 if (features.runparams().dryrun) {
1956 user_preamble << "<" << _("LyX Warning: ")
1957 << _("uncodable character") << " '";
1958 user_preamble.put(c);
1959 user_preamble << "'>";
1962 user_preamble.put(c);
1965 user_preamble << u_preamble;
1967 // On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs
1968 if (!features.runparams().dryrun && !uncodable_glyphs.empty()) {
1969 frontend::Alert::warning(
1970 _("Uncodable character in user preamble"),
1972 _("The user preamble of your document contains glyphs "
1973 "that are unknown in the current document encoding "
1974 "(namely %1$s).\nThese glyphs are omitted "
1975 " from the output, which may result in "
1976 "incomplete output."
1977 "\n\nPlease select an appropriate "
1978 "document encoding\n"
1979 "(such as utf8) or change the "
1980 "preamble code accordingly."),
1983 atlyxpreamble += user_preamble.str() + '\n';
1986 // footmisc must be loaded after setspace
1987 // Load it here to avoid clashes with footmisc loaded in the user
1988 // preamble. For that reason we also pass the options via
1989 // \PassOptionsToPackage in getPreamble() and not here.
1990 if (features.mustProvide("footmisc"))
1991 atlyxpreamble += "\\usepackage{footmisc}\n";
1993 // subfig loads internally the LaTeX package "caption". As
1994 // caption is a very popular package, users will load it in
1995 // the preamble. Therefore we must load subfig behind the
1996 // user-defined preamble and check if the caption package was
1997 // loaded or not. For the case that caption is loaded before
1998 // subfig, there is the subfig option "caption=false". This
1999 // option also works when a koma-script class is used and
2000 // koma's own caption commands are used instead of caption. We
2001 // use \PassOptionsToPackage here because the user could have
2002 // already loaded subfig in the preamble.
2003 if (features.isRequired("subfig")) {
2004 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
2005 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
2006 "\\usepackage{subfig}\n";
2009 // Itemize bullet settings need to be last in case the user
2010 // defines their own bullets that use a package included
2011 // in the user-defined preamble -- ARRae
2012 // Actually it has to be done much later than that
2013 // since some packages like frenchb make modifications
2014 // at \begin{document} time -- JMarc
2015 docstring bullets_def;
2016 for (int i = 0; i < 4; ++i) {
2017 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
2018 if (bullets_def.empty())
2019 bullets_def += "\\AtBeginDocument{\n";
2020 bullets_def += " \\def\\labelitemi";
2022 // `i' is one less than the item to modify
2029 bullets_def += "ii";
2035 bullets_def += '{' +
2036 user_defined_bullet(i).getText()
2041 if (!bullets_def.empty())
2042 atlyxpreamble += bullets_def + "}\n\n";
2044 if (!atlyxpreamble.empty())
2045 lyxpreamble += "\n\\makeatletter\n"
2046 + atlyxpreamble + "\\makeatother\n\n";
2048 // We try to load babel late, in case it interferes with other packages.
2049 // Jurabib, hyperref, varioref, bicaption and listings (bug 8995) have to be
2050 // called after babel, though.
2051 if (use_babel && !features.isRequired("jurabib")
2052 && !features.isRequired("hyperref")
2053 && !features.isRequired("varioref")
2054 && !features.isRequired("vietnamese")
2055 && !features.isRequired("japanese")) {
2057 lyxpreamble += from_utf8(features.getBabelPresettings());
2058 lyxpreamble += from_utf8(babelCall(language_options.str(),
2059 features.needBabelLangOptions())) + '\n';
2060 lyxpreamble += from_utf8(features.getBabelPostsettings());
2062 if (features.isRequired("bicaption"))
2063 lyxpreamble += "\\usepackage{bicaption}\n";
2064 if (!listings_params.empty() || features.isRequired("listings"))
2065 lyxpreamble += "\\usepackage{listings}\n";
2066 if (!listings_params.empty()) {
2067 lyxpreamble += "\\lstset{";
2068 // do not test validity because listings_params is
2069 // supposed to be valid
2071 InsetListingsParams(listings_params).separatedParams(true);
2072 lyxpreamble += from_utf8(par);
2073 lyxpreamble += "}\n";
2076 // xunicode needs to be loaded at least after amsmath, amssymb,
2077 // esint and the other packages that provide special glyphs
2078 if (features.runparams().flavor == OutputParams::XETEX
2080 lyxpreamble += "\\usepackage{xunicode}\n";
2082 // Polyglossia must be loaded last
2083 if (use_polyglossia) {
2085 lyxpreamble += "\\usepackage{polyglossia}\n";
2086 // set the main language
2087 lyxpreamble += "\\setdefaultlanguage";
2088 if (!language->polyglossiaOpts().empty())
2089 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
2090 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
2091 // now setup the other languages
2092 std::map<std::string, std::string> const polylangs =
2093 features.getPolyglossiaLanguages();
2094 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
2095 mit != polylangs.end() ; ++mit) {
2096 lyxpreamble += "\\setotherlanguage";
2097 if (!mit->second.empty())
2098 lyxpreamble += "[" + from_ascii(mit->second) + "]";
2099 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
2103 // Load custom language package here
2104 if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
2105 if (lang_package == "default")
2106 lyxpreamble += from_utf8(lyxrc.language_custom_package);
2108 lyxpreamble += from_utf8(lang_package);
2109 lyxpreamble += '\n';
2112 docstring const i18npreamble =
2113 features.getTClassI18nPreamble(use_babel, use_polyglossia);
2114 if (!i18npreamble.empty())
2115 lyxpreamble += i18npreamble + '\n';
2123 void BufferParams::useClassDefaults()
2125 DocumentClass const & tclass = documentClass();
2127 sides = tclass.sides();
2128 columns = tclass.columns();
2129 pagestyle = tclass.pagestyle();
2130 use_default_options = true;
2131 // Only if class has a ToC hierarchy
2132 if (tclass.hasTocLevels()) {
2133 secnumdepth = tclass.secnumdepth();
2134 tocdepth = tclass.tocdepth();
2139 bool BufferParams::hasClassDefaults() const
2141 DocumentClass const & tclass = documentClass();
2143 return sides == tclass.sides()
2144 && columns == tclass.columns()
2145 && pagestyle == tclass.pagestyle()
2146 && use_default_options
2147 && secnumdepth == tclass.secnumdepth()
2148 && tocdepth == tclass.tocdepth();
2152 DocumentClass const & BufferParams::documentClass() const
2154 return *doc_class_.get();
2158 DocumentClassConstPtr BufferParams::documentClassPtr() const
2164 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
2166 // evil, but this function is evil
2167 doc_class_ = const_pointer_cast<DocumentClass>(tc);
2171 bool BufferParams::setBaseClass(string const & classname)
2173 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
2174 LayoutFileList & bcl = LayoutFileList::get();
2175 if (!bcl.haveClass(classname)) {
2177 bformat(_("The layout file:\n"
2179 "could not be found. A default textclass with default\n"
2180 "layouts will be used. LyX will not be able to produce\n"
2182 from_utf8(classname));
2183 frontend::Alert::error(_("Document class not found"), s);
2184 bcl.addEmptyClass(classname);
2187 bool const success = bcl[classname].load();
2190 bformat(_("Due to some error in it, the layout file:\n"
2192 "could not be loaded. A default textclass with default\n"
2193 "layouts will be used. LyX will not be able to produce\n"
2195 from_utf8(classname));
2196 frontend::Alert::error(_("Could not load class"), s);
2197 bcl.addEmptyClass(classname);
2200 pimpl_->baseClass_ = classname;
2201 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2206 LayoutFile const * BufferParams::baseClass() const
2208 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2209 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2215 LayoutFileIndex const & BufferParams::baseClassID() const
2217 return pimpl_->baseClass_;
2221 void BufferParams::makeDocumentClass(bool const clone)
2226 LayoutModuleList mods;
2227 LayoutModuleList::iterator it = layout_modules_.begin();
2228 LayoutModuleList::iterator en = layout_modules_.end();
2229 for (; it != en; ++it)
2230 mods.push_back(*it);
2232 it = cite_engine_.begin();
2233 en = cite_engine_.end();
2234 for (; it != en; ++it)
2235 mods.push_back(*it);
2237 doc_class_ = getDocumentClass(*baseClass(), mods, clone);
2239 TextClass::ReturnValues success = TextClass::OK;
2240 if (!forced_local_layout_.empty())
2241 success = doc_class_->read(forced_local_layout_, TextClass::MODULE);
2242 if (!local_layout_.empty() &&
2243 (success == TextClass::OK || success == TextClass::OK_OLDFORMAT))
2244 success = doc_class_->read(local_layout_, TextClass::MODULE);
2245 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2246 docstring const msg = _("Error reading internal layout information");
2247 frontend::Alert::warning(_("Read Error"), msg);
2252 bool BufferParams::layoutModuleCanBeAdded(string const & modName) const
2254 return layout_modules_.moduleCanBeAdded(modName, baseClass());
2258 bool BufferParams::citationModuleCanBeAdded(string const & modName) const
2260 return cite_engine_.moduleCanBeAdded(modName, baseClass());
2264 std::string BufferParams::getLocalLayout(bool forced) const
2267 return doc_class_->forcedLayouts();
2269 return local_layout_;
2273 void BufferParams::setLocalLayout(string const & layout, bool forced)
2276 forced_local_layout_ = layout;
2278 local_layout_ = layout;
2282 bool BufferParams::addLayoutModule(string const & modName)
2284 LayoutModuleList::const_iterator it = layout_modules_.begin();
2285 LayoutModuleList::const_iterator end = layout_modules_.end();
2286 for (; it != end; ++it)
2289 layout_modules_.push_back(modName);
2294 string BufferParams::bufferFormat() const
2296 string format = documentClass().outputFormat();
2297 if (format == "latex") {
2300 if (encoding().package() == Encoding::japanese)
2307 bool BufferParams::isExportable(string const & format) const
2309 vector<string> backs = backends();
2310 for (vector<string>::const_iterator it = backs.begin();
2311 it != backs.end(); ++it)
2312 if (theConverters().isReachable(*it, format))
2318 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2320 vector<string> const backs = backends();
2321 set<string> excludes;
2322 if (useNonTeXFonts) {
2323 excludes.insert("latex");
2324 excludes.insert("pdflatex");
2326 vector<Format const *> result =
2327 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2328 for (vector<string>::const_iterator it = backs.begin() + 1;
2329 it != backs.end(); ++it) {
2330 vector<Format const *> r =
2331 theConverters().getReachable(*it, only_viewable, false, excludes);
2332 result.insert(result.end(), r.begin(), r.end());
2338 bool BufferParams::isExportableFormat(string const & format) const
2340 typedef vector<Format const *> Formats;
2342 formats = exportableFormats(true);
2343 Formats::const_iterator fit = formats.begin();
2344 Formats::const_iterator end = formats.end();
2345 for (; fit != end ; ++fit) {
2346 if ((*fit)->name() == format)
2353 vector<string> BufferParams::backends() const
2356 string const buffmt = bufferFormat();
2358 // FIXME: Don't hardcode format names here, but use a flag
2359 if (buffmt == "latex") {
2360 if (!useNonTeXFonts) {
2361 v.push_back("pdflatex");
2362 v.push_back("latex");
2364 v.push_back("luatex");
2365 v.push_back("dviluatex");
2366 v.push_back("xetex");
2367 } else if (buffmt == "xetex") {
2368 v.push_back("xetex");
2369 // FIXME: need to test all languages (bug 8205)
2370 if (!language || !language->isPolyglossiaExclusive()) {
2371 v.push_back("luatex");
2372 v.push_back("dviluatex");
2375 v.push_back(buffmt);
2377 v.push_back("xhtml");
2378 v.push_back("text");
2384 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const
2386 string const dformat = (format.empty() || format == "default") ?
2387 getDefaultOutputFormat() : format;
2388 DefaultFlavorCache::const_iterator it =
2389 default_flavors_.find(dformat);
2391 if (it != default_flavors_.end())
2394 OutputParams::FLAVOR result = OutputParams::LATEX;
2396 // FIXME It'd be better not to hardcode this, but to do
2397 // something with formats.
2398 if (dformat == "xhtml")
2399 result = OutputParams::HTML;
2400 else if (dformat == "text")
2401 result = OutputParams::TEXT;
2402 else if (dformat == "lyx")
2403 result = OutputParams::LYX;
2404 else if (dformat == "pdflatex")
2405 result = OutputParams::PDFLATEX;
2406 else if (dformat == "xetex")
2407 result = OutputParams::XETEX;
2408 else if (dformat == "luatex")
2409 result = OutputParams::LUATEX;
2410 else if (dformat == "dviluatex")
2411 result = OutputParams::DVILUATEX;
2413 // Try to determine flavor of default output format
2414 vector<string> backs = backends();
2415 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2416 // Get shortest path to format
2417 Graph::EdgePath path;
2418 for (vector<string>::const_iterator it = backs.begin();
2419 it != backs.end(); ++it) {
2420 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2421 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2426 result = theConverters().getFlavor(path);
2429 // cache this flavor
2430 default_flavors_[dformat] = result;
2435 string BufferParams::getDefaultOutputFormat() const
2437 if (!default_output_format.empty()
2438 && default_output_format != "default")
2439 return default_output_format;
2441 || encoding().package() == Encoding::japanese) {
2442 vector<Format const *> const formats = exportableFormats(true);
2443 if (formats.empty())
2445 // return the first we find
2446 return formats.front()->name();
2449 return lyxrc.default_otf_view_format;
2450 return lyxrc.default_view_format;
2453 Font const BufferParams::getFont() const
2455 FontInfo f = documentClass().defaultfont();
2456 if (fonts_default_family == "rmdefault")
2457 f.setFamily(ROMAN_FAMILY);
2458 else if (fonts_default_family == "sfdefault")
2459 f.setFamily(SANS_FAMILY);
2460 else if (fonts_default_family == "ttdefault")
2461 f.setFamily(TYPEWRITER_FAMILY);
2462 return Font(f, language);
2466 InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const & qs) const
2468 return quoteslangtranslator().find(qs);
2472 bool BufferParams::isLatex() const
2474 return documentClass().outputType() == LATEX;
2478 bool BufferParams::isLiterate() const
2480 return documentClass().outputType() == LITERATE;
2484 bool BufferParams::isDocBook() const
2486 return documentClass().outputType() == DOCBOOK;
2490 void BufferParams::readPreamble(Lexer & lex)
2492 if (lex.getString() != "\\begin_preamble")
2493 lyxerr << "Error (BufferParams::readPreamble):"
2494 "consistency check failed." << endl;
2496 preamble = lex.getLongString("\\end_preamble");
2500 void BufferParams::readLocalLayout(Lexer & lex, bool forced)
2502 string const expected = forced ? "\\begin_forced_local_layout" :
2503 "\\begin_local_layout";
2504 if (lex.getString() != expected)
2505 lyxerr << "Error (BufferParams::readLocalLayout):"
2506 "consistency check failed." << endl;
2509 forced_local_layout_ =
2510 lex.getLongString("\\end_forced_local_layout");
2512 local_layout_ = lex.getLongString("\\end_local_layout");
2516 bool BufferParams::setLanguage(string const & lang)
2518 Language const *new_language = languages.getLanguage(lang);
2519 if (!new_language) {
2520 // Language lang was not found
2523 language = new_language;
2528 void BufferParams::readLanguage(Lexer & lex)
2530 if (!lex.next()) return;
2532 string const tmptok = lex.getString();
2534 // check if tmptok is part of tex_babel in tex-defs.h
2535 if (!setLanguage(tmptok)) {
2536 // Language tmptok was not found
2537 language = default_language;
2538 lyxerr << "Warning: Setting language `"
2539 << tmptok << "' to `" << language->lang()
2545 void BufferParams::readGraphicsDriver(Lexer & lex)
2550 string const tmptok = lex.getString();
2551 // check if tmptok is part of tex_graphics in tex_defs.h
2554 string const test = tex_graphics[n++];
2556 if (test == tmptok) {
2557 graphics_driver = tmptok;
2562 "Warning: graphics driver `$$Token' not recognized!\n"
2563 " Setting graphics driver to `default'.\n");
2564 graphics_driver = "default";
2571 void BufferParams::readBullets(Lexer & lex)
2576 int const index = lex.getInteger();
2578 int temp_int = lex.getInteger();
2579 user_defined_bullet(index).setFont(temp_int);
2580 temp_bullet(index).setFont(temp_int);
2582 user_defined_bullet(index).setCharacter(temp_int);
2583 temp_bullet(index).setCharacter(temp_int);
2585 user_defined_bullet(index).setSize(temp_int);
2586 temp_bullet(index).setSize(temp_int);
2590 void BufferParams::readBulletsLaTeX(Lexer & lex)
2592 // The bullet class should be able to read this.
2595 int const index = lex.getInteger();
2597 docstring const temp_str = lex.getDocString();
2599 user_defined_bullet(index).setText(temp_str);
2600 temp_bullet(index).setText(temp_str);
2604 void BufferParams::readModules(Lexer & lex)
2606 if (!lex.eatLine()) {
2607 lyxerr << "Error (BufferParams::readModules):"
2608 "Unexpected end of input." << endl;
2612 string mod = lex.getString();
2613 if (mod == "\\end_modules")
2615 addLayoutModule(mod);
2621 void BufferParams::readRemovedModules(Lexer & lex)
2623 if (!lex.eatLine()) {
2624 lyxerr << "Error (BufferParams::readRemovedModules):"
2625 "Unexpected end of input." << endl;
2629 string mod = lex.getString();
2630 if (mod == "\\end_removed_modules")
2632 removed_modules_.push_back(mod);
2635 // now we want to remove any removed modules that were previously
2636 // added. normally, that will be because default modules were added in
2637 // setBaseClass(), which gets called when \textclass is read at the
2638 // start of the read.
2639 list<string>::const_iterator rit = removed_modules_.begin();
2640 list<string>::const_iterator const ren = removed_modules_.end();
2641 for (; rit != ren; ++rit) {
2642 LayoutModuleList::iterator const mit = layout_modules_.begin();
2643 LayoutModuleList::iterator const men = layout_modules_.end();
2644 LayoutModuleList::iterator found = find(mit, men, *rit);
2647 layout_modules_.erase(found);
2652 void BufferParams::readIncludeonly(Lexer & lex)
2654 if (!lex.eatLine()) {
2655 lyxerr << "Error (BufferParams::readIncludeonly):"
2656 "Unexpected end of input." << endl;
2660 string child = lex.getString();
2661 if (child == "\\end_includeonly")
2663 included_children_.push_back(child);
2669 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2671 switch (papersize) {
2673 // could be anything, so don't guess
2675 case PAPER_CUSTOM: {
2676 if (purpose == XDVI && !paperwidth.empty() &&
2677 !paperheight.empty()) {
2678 // heightxwidth<unit>
2679 string first = paperwidth;
2680 string second = paperheight;
2681 if (orientation == ORIENTATION_LANDSCAPE)
2684 return first.erase(first.length() - 2)
2690 // dvips and dvipdfm do not know this
2691 if (purpose == DVIPS || purpose == DVIPDFM)
2695 if (purpose == DVIPS || purpose == DVIPDFM)
2699 if (purpose == DVIPS || purpose == DVIPDFM)
2709 if (purpose == DVIPS || purpose == DVIPDFM)
2713 if (purpose == DVIPS || purpose == DVIPDFM)
2717 if (purpose == DVIPS || purpose == DVIPDFM)
2721 if (purpose == DVIPS || purpose == DVIPDFM)
2725 if (purpose == DVIPS || purpose == DVIPDFM)
2729 // dvipdfm does not know this
2730 if (purpose == DVIPDFM)
2734 if (purpose == DVIPDFM)
2738 if (purpose == DVIPS || purpose == DVIPDFM)
2742 if (purpose == DVIPS || purpose == DVIPDFM)
2746 if (purpose == DVIPS || purpose == DVIPDFM)
2750 if (purpose == DVIPS || purpose == DVIPDFM)
2754 if (purpose == DVIPS || purpose == DVIPDFM)
2758 if (purpose == DVIPS || purpose == DVIPDFM)
2762 if (purpose == DVIPS || purpose == DVIPDFM)
2766 if (purpose == DVIPS || purpose == DVIPDFM)
2770 if (purpose == DVIPS || purpose == DVIPDFM)
2774 if (purpose == DVIPS || purpose == DVIPDFM)
2778 if (purpose == DVIPS || purpose == DVIPDFM)
2782 if (purpose == DVIPS || purpose == DVIPDFM)
2786 if (purpose == DVIPS || purpose == DVIPDFM)
2790 if (purpose == DVIPS || purpose == DVIPDFM)
2794 if (purpose == DVIPS || purpose == DVIPDFM)
2797 case PAPER_USEXECUTIVE:
2798 // dvipdfm does not know this
2799 if (purpose == DVIPDFM)
2804 case PAPER_USLETTER:
2806 if (purpose == XDVI)
2813 string const BufferParams::dvips_options() const
2817 // If the class loads the geometry package, we do not know which
2818 // paper size is used, since we do not set it (bug 7013).
2819 // Therefore we must not specify any argument here.
2820 // dvips gets the correct paper size via DVI specials in this case
2821 // (if the class uses the geometry package correctly).
2822 if (documentClass().provides("geometry"))
2826 && papersize == PAPER_CUSTOM
2827 && !lyxrc.print_paper_dimension_flag.empty()
2828 && !paperwidth.empty()
2829 && !paperheight.empty()) {
2830 // using a custom papersize
2831 result = lyxrc.print_paper_dimension_flag;
2832 result += ' ' + paperwidth;
2833 result += ',' + paperheight;
2835 string const paper_option = paperSizeName(DVIPS);
2836 if (!paper_option.empty() && (paper_option != "letter" ||
2837 orientation != ORIENTATION_LANDSCAPE)) {
2838 // dvips won't accept -t letter -t landscape.
2839 // In all other cases, include the paper size
2841 result = lyxrc.print_paper_flag;
2842 result += ' ' + paper_option;
2845 if (orientation == ORIENTATION_LANDSCAPE &&
2846 papersize != PAPER_CUSTOM)
2847 result += ' ' + lyxrc.print_landscape_flag;
2852 string const BufferParams::font_encoding() const
2854 return font_encodings().empty() ? "default" : font_encodings().back();
2858 vector<string> const BufferParams::font_encodings() const
2860 string doc_fontenc = (fontenc == "global") ? lyxrc.fontenc : fontenc;
2862 vector<string> fontencs;
2864 // "default" means "no explicit font encoding"
2865 if (doc_fontenc != "default") {
2866 fontencs = getVectorFromString(doc_fontenc);
2867 if (!language->fontenc().empty()
2868 && ascii_lowercase(language->fontenc()) != "none") {
2869 vector<string> fencs = getVectorFromString(language->fontenc());
2870 vector<string>::const_iterator fit = fencs.begin();
2871 for (; fit != fencs.end(); ++fit) {
2872 if (find(fontencs.begin(), fontencs.end(), *fit) == fontencs.end())
2873 fontencs.push_back(*fit);
2882 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2884 // suppress the babel call if there is no BabelName defined
2885 // for the document language in the lib/languages file and if no
2886 // other languages are used (lang_opts is then empty)
2887 if (lang_opts.empty())
2889 // either a specific language (AsBabelOptions setting in
2890 // lib/languages) or the prefs require the languages to
2891 // be submitted to babel itself (not the class).
2893 return "\\usepackage[" + lang_opts + "]{babel}";
2894 return "\\usepackage{babel}";
2898 docstring BufferParams::getGraphicsDriver(string const & package) const
2902 if (package == "geometry") {
2903 if (graphics_driver == "dvips"
2904 || graphics_driver == "dvipdfm"
2905 || graphics_driver == "pdftex"
2906 || graphics_driver == "vtex")
2907 result = from_ascii(graphics_driver);
2908 else if (graphics_driver == "dvipdfmx")
2909 result = from_ascii("dvipdfm");
2916 void BufferParams::writeEncodingPreamble(otexstream & os,
2917 LaTeXFeatures & features) const
2919 // XeTeX does not need this
2920 if (features.runparams().flavor == OutputParams::XETEX)
2922 // LuaTeX neither, but with tex fonts, we need to load
2923 // the luainputenc package.
2924 if (features.runparams().flavor == OutputParams::LUATEX
2925 || features.runparams().flavor == OutputParams::DVILUATEX) {
2926 if (!useNonTeXFonts && inputenc != "default"
2927 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2928 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2929 os << "\\usepackage[utf8]{luainputenc}\n";
2933 if (inputenc == "auto") {
2934 string const doc_encoding =
2935 language->encoding()->latexName();
2936 Encoding::Package const package =
2937 language->encoding()->package();
2939 // Create a list with all the input encodings used
2941 set<string> encodings =
2942 features.getEncodingSet(doc_encoding);
2944 // If the "japanese" package (i.e. pLaTeX) is used,
2945 // inputenc must be omitted.
2946 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2947 if ((!encodings.empty() || package == Encoding::inputenc)
2948 && !features.isRequired("japanese")
2949 && !features.isProvided("inputenc")) {
2950 os << "\\usepackage[";
2951 set<string>::const_iterator it = encodings.begin();
2952 set<string>::const_iterator const end = encodings.end();
2954 os << from_ascii(*it);
2957 for (; it != end; ++it)
2958 os << ',' << from_ascii(*it);
2959 if (package == Encoding::inputenc) {
2960 if (!encodings.empty())
2962 os << from_ascii(doc_encoding);
2964 os << "]{inputenc}\n";
2966 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2967 if (language->encoding()->name() == "utf8-cjk"
2968 && LaTeXFeatures::isAvailable("CJKutf8"))
2969 os << "\\usepackage{CJKutf8}\n";
2971 os << "\\usepackage{CJK}\n";
2973 } else if (inputenc != "default") {
2974 switch (encoding().package()) {
2975 case Encoding::none:
2976 case Encoding::japanese:
2978 case Encoding::inputenc:
2979 // do not load inputenc if japanese is used
2980 // or if the class provides inputenc
2981 if (features.isRequired("japanese")
2982 || features.isProvided("inputenc"))
2984 os << "\\usepackage[" << from_ascii(encoding().latexName())
2988 if (encoding().name() == "utf8-cjk"
2989 && LaTeXFeatures::isAvailable("CJKutf8"))
2990 os << "\\usepackage{CJKutf8}\n";
2992 os << "\\usepackage{CJK}\n";
2995 // Load the CJK package if needed by a secondary language.
2996 // If the main encoding is some variant of UTF8, use CJKutf8.
2997 if (encoding().package() != Encoding::CJK && features.mustProvide("CJK")) {
2998 if (encoding().iconvName() == "UTF-8"
2999 && LaTeXFeatures::isAvailable("CJKutf8"))
3000 os << "\\usepackage{CJKutf8}\n";
3002 os << "\\usepackage{CJK}\n";
3008 string const BufferParams::parseFontName(string const & name) const
3010 string mangled = name;
3011 size_t const idx = mangled.find('[');
3012 if (idx == string::npos || idx == 0)
3015 return mangled.substr(0, idx - 1);
3019 string const BufferParams::loadFonts(LaTeXFeatures & features) const
3021 if (fonts_roman == "default" && fonts_sans == "default"
3022 && fonts_typewriter == "default"
3023 && (fonts_math == "default" || fonts_math == "auto"))
3029 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
3030 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
3031 * Mapping=tex-text option assures TeX ligatures (such as "--")
3032 * are resolved. Note that tt does not use these ligatures.
3034 * -- add more GUI options?
3035 * -- add more fonts (fonts for other scripts)
3036 * -- if there's a way to find out if a font really supports
3037 * OldStyle, enable/disable the widget accordingly.
3039 if (useNonTeXFonts && features.isAvailable("fontspec")) {
3040 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
3041 // However, until v.2 (2010/07/11) fontspec only knew
3042 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
3043 // was introduced for both XeTeX and LuaTeX (LuaTeX
3044 // didn't understand "Mapping=tex-text", while XeTeX
3045 // understood both. With most recent versions, both
3046 // variants are understood by both engines. However,
3047 // we want to provide support for at least TeXLive 2009
3048 // (for XeTeX; LuaTeX is only supported as of v.2)
3049 string const texmapping =
3050 (features.runparams().flavor == OutputParams::XETEX) ?
3051 "Mapping=tex-text" : "Ligatures=TeX";
3052 if (fonts_roman != "default") {
3053 os << "\\setmainfont[" << texmapping;
3054 if (fonts_old_figures)
3055 os << ",Numbers=OldStyle";
3056 os << "]{" << parseFontName(fonts_roman) << "}\n";
3058 if (fonts_sans != "default") {
3059 string const sans = parseFontName(fonts_sans);
3060 if (fonts_sans_scale != 100)
3061 os << "\\setsansfont[Scale="
3062 << float(fonts_sans_scale) / 100
3063 << "," << texmapping << "]{"
3066 os << "\\setsansfont[" << texmapping << "]{"
3069 if (fonts_typewriter != "default") {
3070 string const mono = parseFontName(fonts_typewriter);
3071 if (fonts_typewriter_scale != 100)
3072 os << "\\setmonofont[Scale="
3073 << float(fonts_typewriter_scale) / 100
3077 os << "\\setmonofont{"
3084 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
3085 bool const dryrun = features.runparams().dryrun;
3086 bool const complete = (fonts_sans == "default" && fonts_typewriter == "default");
3087 bool const nomath = (fonts_math == "default");
3090 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_roman)).getLaTeXCode(
3091 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3095 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_sans)).getLaTeXCode(
3096 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3097 nomath, fonts_sans_scale);
3099 // MONOSPACED/TYPEWRITER
3100 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_typewriter)).getLaTeXCode(
3101 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3102 nomath, fonts_typewriter_scale);
3105 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getLaTeXCode(
3106 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3113 Encoding const & BufferParams::encoding() const
3115 // FIXME: actually, we should check for the flavor
3116 // or runparams.isFullyUnicode() here:
3117 // This check will not work with XeTeX/LuaTeX and tex fonts.
3118 // Thus we have to reset the encoding in Buffer::makeLaTeXFile
3119 // (for export) and Buffer::writeLaTeXSource (for preview).
3121 return *(encodings.fromLyXName("utf8-plain"));
3122 if (inputenc == "auto" || inputenc == "default")
3123 return *language->encoding();
3124 Encoding const * const enc = encodings.fromLyXName(inputenc);
3127 LYXERR0("Unknown inputenc value `" << inputenc
3128 << "'. Using `auto' instead.");
3129 return *language->encoding();
3133 bool BufferParams::addCiteEngine(string const & engine)
3135 LayoutModuleList::const_iterator it = cite_engine_.begin();
3136 LayoutModuleList::const_iterator en = cite_engine_.end();
3137 for (; it != en; ++it)
3140 cite_engine_.push_back(engine);
3145 bool BufferParams::addCiteEngine(vector<string> const & engine)
3147 vector<string>::const_iterator it = engine.begin();
3148 vector<string>::const_iterator en = engine.end();
3150 for (; it != en; ++it)
3151 if (!addCiteEngine(*it))
3157 string const & BufferParams::defaultBiblioStyle() const
3159 return documentClass().defaultBiblioStyle();
3163 bool const & BufferParams::fullAuthorList() const
3165 return documentClass().fullAuthorList();
3169 void BufferParams::setCiteEngine(string const & engine)
3172 addCiteEngine(engine);
3176 void BufferParams::setCiteEngine(vector<string> const & engine)
3179 addCiteEngine(engine);
3183 vector<string> BufferParams::citeCommands() const
3185 static CitationStyle const default_style;
3186 vector<string> commands =
3187 documentClass().citeCommands(citeEngineType());
3188 if (commands.empty())
3189 commands.push_back(default_style.cmd);
3194 vector<CitationStyle> BufferParams::citeStyles() const
3196 static CitationStyle const default_style;
3197 vector<CitationStyle> styles =
3198 documentClass().citeStyles(citeEngineType());
3200 styles.push_back(default_style);