2 * \file BufferParams.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
11 * \author Martin Vermeer
13 * Full author contact details are available in file CREDITS.
18 #include "BufferParams.h"
21 #include "LayoutFile.h"
22 #include "BranchList.h"
23 #include "buffer_funcs.h"
27 #include "Converter.h"
30 #include "IndicesList.h"
32 #include "LaTeXFeatures.h"
33 #include "LaTeXFonts.h"
34 #include "ModuleList.h"
38 #include "OutputParams.h"
42 #include "PDFOptions.h"
44 #include "frontends/alert.h"
46 #include "insets/InsetListingsParams.h"
48 #include "support/convert.h"
49 #include "support/debug.h"
50 #include "support/docstream.h"
51 #include "support/FileName.h"
52 #include "support/filetools.h"
53 #include "support/gettext.h"
54 #include "support/Messages.h"
55 #include "support/mutex.h"
56 #include "support/Translator.h"
57 #include "support/lstrings.h"
63 using namespace lyx::support;
66 static char const * const string_paragraph_separation[] = {
71 static char const * const string_quotes_language[] = {
72 "english", "swedish", "german", "polish", "french", "danish", ""
76 static char const * const string_papersize[] = {
77 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
78 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
79 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
80 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
81 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
86 static char const * const string_orientation[] = {
87 "portrait", "landscape", ""
91 static char const * const tex_graphics[] = {
92 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
93 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
94 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
95 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
106 // Paragraph separation
107 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
110 ParSepTranslator const init_parseptranslator()
112 ParSepTranslator translator
113 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
114 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
119 ParSepTranslator const & parseptranslator()
121 static ParSepTranslator const translator =
122 init_parseptranslator();
128 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
131 QuotesLangTranslator const init_quoteslangtranslator()
133 QuotesLangTranslator translator
134 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
135 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
136 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
137 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
138 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
139 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
144 QuotesLangTranslator const & quoteslangtranslator()
146 static QuotesLangTranslator const translator =
147 init_quoteslangtranslator();
153 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
156 static PaperSizeTranslator initPaperSizeTranslator()
158 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
159 translator.addPair(string_papersize[1], PAPER_CUSTOM);
160 translator.addPair(string_papersize[2], PAPER_USLETTER);
161 translator.addPair(string_papersize[3], PAPER_USLEGAL);
162 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
163 translator.addPair(string_papersize[5], PAPER_A0);
164 translator.addPair(string_papersize[6], PAPER_A1);
165 translator.addPair(string_papersize[7], PAPER_A2);
166 translator.addPair(string_papersize[8], PAPER_A3);
167 translator.addPair(string_papersize[9], PAPER_A4);
168 translator.addPair(string_papersize[10], PAPER_A5);
169 translator.addPair(string_papersize[11], PAPER_A6);
170 translator.addPair(string_papersize[12], PAPER_B0);
171 translator.addPair(string_papersize[13], PAPER_B1);
172 translator.addPair(string_papersize[14], PAPER_B2);
173 translator.addPair(string_papersize[15], PAPER_B3);
174 translator.addPair(string_papersize[16], PAPER_B4);
175 translator.addPair(string_papersize[17], PAPER_B5);
176 translator.addPair(string_papersize[18], PAPER_B6);
177 translator.addPair(string_papersize[19], PAPER_C0);
178 translator.addPair(string_papersize[20], PAPER_C1);
179 translator.addPair(string_papersize[21], PAPER_C2);
180 translator.addPair(string_papersize[22], PAPER_C3);
181 translator.addPair(string_papersize[23], PAPER_C4);
182 translator.addPair(string_papersize[24], PAPER_C5);
183 translator.addPair(string_papersize[25], PAPER_C6);
184 translator.addPair(string_papersize[26], PAPER_JISB0);
185 translator.addPair(string_papersize[27], PAPER_JISB1);
186 translator.addPair(string_papersize[28], PAPER_JISB2);
187 translator.addPair(string_papersize[29], PAPER_JISB3);
188 translator.addPair(string_papersize[30], PAPER_JISB4);
189 translator.addPair(string_papersize[31], PAPER_JISB5);
190 translator.addPair(string_papersize[32], PAPER_JISB6);
195 PaperSizeTranslator const & papersizetranslator()
197 static PaperSizeTranslator const translator =
198 initPaperSizeTranslator();
204 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
207 PaperOrientationTranslator const init_paperorientationtranslator()
209 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
210 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
215 PaperOrientationTranslator const & paperorientationtranslator()
217 static PaperOrientationTranslator const translator =
218 init_paperorientationtranslator();
224 typedef Translator<int, PageSides> SidesTranslator;
227 SidesTranslator const init_sidestranslator()
229 SidesTranslator translator(1, OneSide);
230 translator.addPair(2, TwoSides);
235 SidesTranslator const & sidestranslator()
237 static SidesTranslator const translator = init_sidestranslator();
243 typedef Translator<int, BufferParams::Package> PackageTranslator;
246 PackageTranslator const init_packagetranslator()
248 PackageTranslator translator(0, BufferParams::package_off);
249 translator.addPair(1, BufferParams::package_auto);
250 translator.addPair(2, BufferParams::package_on);
255 PackageTranslator const & packagetranslator()
257 static PackageTranslator const translator =
258 init_packagetranslator();
264 typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
267 CiteEngineTypeTranslator const init_citeenginetypetranslator()
269 CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
270 translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
271 translator.addPair("default", ENGINE_TYPE_DEFAULT);
276 CiteEngineTypeTranslator const & citeenginetypetranslator()
278 static CiteEngineTypeTranslator const translator =
279 init_citeenginetypetranslator();
285 typedef Translator<string, Spacing::Space> SpaceTranslator;
288 SpaceTranslator const init_spacetranslator()
290 SpaceTranslator translator("default", Spacing::Default);
291 translator.addPair("single", Spacing::Single);
292 translator.addPair("onehalf", Spacing::Onehalf);
293 translator.addPair("double", Spacing::Double);
294 translator.addPair("other", Spacing::Other);
299 SpaceTranslator const & spacetranslator()
301 static SpaceTranslator const translator = init_spacetranslator();
308 class BufferParams::Impl
313 AuthorList authorlist;
314 BranchList branchlist;
315 Bullet temp_bullets[4];
316 Bullet user_defined_bullets[4];
317 IndicesList indiceslist;
319 /** This is the amount of space used for paragraph_separation "skip",
320 * and for detached paragraphs in "indented" documents.
324 PDFOptions pdfoptions;
325 LayoutFileIndex baseClass_;
329 BufferParams::Impl::Impl()
330 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
332 // set initial author
334 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
339 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
342 return new BufferParams::Impl(*ptr);
346 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
352 BufferParams::BufferParams()
355 setBaseClass(defaultBaseclass());
357 paragraph_separation = ParagraphIndentSeparation;
358 quotes_language = InsetQuotes::EnglishQuotes;
359 fontsize = "default";
362 papersize = PAPER_DEFAULT;
363 orientation = ORIENTATION_PORTRAIT;
364 use_geometry = false;
365 cite_engine_.push_back("basic");
366 cite_engine_type_ = ENGINE_TYPE_DEFAULT;
367 biblio_style = "plain";
368 use_bibtopic = false;
370 track_changes = false;
371 output_changes = false;
372 use_default_options = true;
373 maintain_unincluded_children = false;
376 language = default_language;
378 fonts_roman = "default";
379 fonts_sans = "default";
380 fonts_typewriter = "default";
382 fonts_default_family = "default";
383 useNonTeXFonts = false;
384 fonts_expert_sc = false;
385 fonts_old_figures = false;
386 fonts_sans_scale = 100;
387 fonts_typewriter_scale = 100;
389 lang_package = "default";
390 graphics_driver = "default";
391 default_output_format = "default";
392 bibtex_command = "default";
393 index_command = "default";
396 listings_params = string();
397 pagestyle = "default";
398 suppress_date = false;
399 justification = true;
400 // no color is the default (white)
401 backgroundcolor = lyx::rgbFromHexName("#ffffff");
402 isbackgroundcolor = false;
403 // no color is the default (black)
404 fontcolor = lyx::rgbFromHexName("#000000");
406 // light gray is the default font color for greyed-out notes
407 notefontcolor = lyx::rgbFromHexName("#cccccc");
408 boxbgcolor = lyx::rgbFromHexName("#ff0000");
409 compressed = lyxrc.save_compressed;
410 for (int iter = 0; iter < 4; ++iter) {
411 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
412 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
415 indiceslist().addDefault(B_("Index"));
416 html_be_strict = false;
417 html_math_output = MathML;
418 html_math_img_scale = 1.0;
419 html_css_as_file = false;
420 display_pixel_ratio = 1.0;
427 docstring BufferParams::B_(string const & l10n) const
429 LASSERT(language, return from_utf8(l10n));
430 return getMessages(language->code()).get(l10n);
434 BufferParams::Package BufferParams::use_package(std::string const & p) const
436 PackageMap::const_iterator it = use_packages.find(p);
437 if (it == use_packages.end())
443 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
449 map<string, string> const & BufferParams::auto_packages()
451 static map<string, string> packages;
452 if (packages.empty()) {
453 // We could have a race condition here that two threads
454 // discover an empty map at the same time and want to fill
455 // it, but that is no problem, since the same contents is
456 // filled in twice then. Having the locker inside the
457 // packages.empty() condition has the advantage that we
458 // don't need the mutex overhead for simple reading.
460 Mutex::Locker locker(&mutex);
461 // adding a package here implies a file format change!
462 packages["amsmath"] =
463 N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas");
464 packages["amssymb"] =
465 N_("The LaTeX package amssymb is only used if symbols from the AMS math toolbars are inserted into formulas");
467 N_("The LaTeX package cancel is only used if \\cancel commands are used in formulas");
469 N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas");
470 packages["mathdots"] =
471 N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas");
472 packages["mathtools"] =
473 N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas");
475 N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas");
476 packages["stackrel"] =
477 N_("The LaTeX package stackrel is only used if the command \\stackrel with subscript is inserted into formulas");
478 packages["stmaryrd"] =
479 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");
480 packages["undertilde"] =
481 N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'");
487 AuthorList & BufferParams::authors()
489 return pimpl_->authorlist;
493 AuthorList const & BufferParams::authors() const
495 return pimpl_->authorlist;
499 BranchList & BufferParams::branchlist()
501 return pimpl_->branchlist;
505 BranchList const & BufferParams::branchlist() const
507 return pimpl_->branchlist;
511 IndicesList & BufferParams::indiceslist()
513 return pimpl_->indiceslist;
517 IndicesList const & BufferParams::indiceslist() const
519 return pimpl_->indiceslist;
523 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
525 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
526 return pimpl_->temp_bullets[index];
530 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
532 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
533 return pimpl_->temp_bullets[index];
537 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
539 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
540 return pimpl_->user_defined_bullets[index];
544 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
546 LASSERT(index < 4, return pimpl_->temp_bullets[0]);
547 return pimpl_->user_defined_bullets[index];
551 Spacing & BufferParams::spacing()
553 return pimpl_->spacing;
557 Spacing const & BufferParams::spacing() const
559 return pimpl_->spacing;
563 PDFOptions & BufferParams::pdfoptions()
565 return pimpl_->pdfoptions;
569 PDFOptions const & BufferParams::pdfoptions() const
571 return pimpl_->pdfoptions;
575 HSpace const & BufferParams::getIndentation() const
577 return pimpl_->indentation;
581 void BufferParams::setIndentation(HSpace const & indent)
583 pimpl_->indentation = indent;
587 VSpace const & BufferParams::getDefSkip() const
589 return pimpl_->defskip;
593 void BufferParams::setDefSkip(VSpace const & vs)
595 // DEFSKIP will cause an infinite loop
596 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
597 pimpl_->defskip = vs;
601 string BufferParams::readToken(Lexer & lex, string const & token,
602 FileName const & filepath)
604 if (token == "\\textclass") {
606 string const classname = lex.getString();
607 // if there exists a local layout file, ignore the system one
608 // NOTE: in this case, the textclass (.cls file) is assumed to
611 LayoutFileList & bcl = LayoutFileList::get();
612 if (!filepath.empty())
613 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
614 // that returns non-empty if a "local" layout file is found.
618 setBaseClass(classname);
619 // We assume that a tex class exists for local or unknown
620 // layouts so this warning, will only be given for system layouts.
621 if (!baseClass()->isTeXClassAvailable()) {
622 docstring const desc =
623 translateIfPossible(from_utf8(baseClass()->description()));
624 docstring const prereqs =
625 from_utf8(baseClass()->prerequisites());
626 docstring const msg =
627 bformat(_("The selected document class\n"
629 "requires external files that are not available.\n"
630 "The document class can still be used, but the\n"
631 "document cannot be compiled until the following\n"
632 "prerequisites are installed:\n"
634 "See section 3.1.2.2 (Class Availability) of the\n"
635 "User's Guide for more information."), desc, prereqs);
636 frontend::Alert::warning(_("Document class not available"),
639 } else if (token == "\\begin_preamble") {
641 } else if (token == "\\begin_local_layout") {
642 readLocalLayout(lex, false);
643 } else if (token == "\\begin_forced_local_layout") {
644 readLocalLayout(lex, true);
645 } else if (token == "\\begin_modules") {
647 } else if (token == "\\begin_removed_modules") {
648 readRemovedModules(lex);
649 } else if (token == "\\begin_includeonly") {
650 readIncludeonly(lex);
651 } else if (token == "\\maintain_unincluded_children") {
652 lex >> maintain_unincluded_children;
653 } else if (token == "\\options") {
655 options = lex.getString();
656 } else if (token == "\\use_default_options") {
657 lex >> use_default_options;
658 } else if (token == "\\master") {
660 master = lex.getString();
661 } else if (token == "\\suppress_date") {
662 lex >> suppress_date;
663 } else if (token == "\\justification") {
664 lex >> justification;
665 } else if (token == "\\language") {
667 } else if (token == "\\language_package") {
669 lang_package = lex.getString();
670 } else if (token == "\\inputencoding") {
672 } else if (token == "\\graphics") {
673 readGraphicsDriver(lex);
674 } else if (token == "\\default_output_format") {
675 lex >> default_output_format;
676 } else if (token == "\\bibtex_command") {
678 bibtex_command = lex.getString();
679 } else if (token == "\\index_command") {
681 index_command = lex.getString();
682 } else if (token == "\\fontencoding") {
684 fontenc = lex.getString();
685 } else if (token == "\\font_roman") {
687 fonts_roman = lex.getString();
688 } else if (token == "\\font_sans") {
690 fonts_sans = lex.getString();
691 } else if (token == "\\font_typewriter") {
693 fonts_typewriter = lex.getString();
694 } else if (token == "\\font_math") {
696 fonts_math = lex.getString();
697 } else if (token == "\\font_default_family") {
698 lex >> fonts_default_family;
699 } else if (token == "\\use_non_tex_fonts") {
700 lex >> useNonTeXFonts;
701 } else if (token == "\\font_sc") {
702 lex >> fonts_expert_sc;
703 } else if (token == "\\font_osf") {
704 lex >> fonts_old_figures;
705 } else if (token == "\\font_sf_scale") {
706 lex >> fonts_sans_scale;
707 } else if (token == "\\font_tt_scale") {
708 lex >> fonts_typewriter_scale;
709 } else if (token == "\\font_cjk") {
711 } else if (token == "\\paragraph_separation") {
714 paragraph_separation = parseptranslator().find(parsep);
715 } else if (token == "\\paragraph_indentation") {
717 string indentation = lex.getString();
718 pimpl_->indentation = HSpace(indentation);
719 } else if (token == "\\defskip") {
721 string const defskip = lex.getString();
722 pimpl_->defskip = VSpace(defskip);
723 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
725 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
726 } else if (token == "\\quotes_language") {
729 quotes_language = quoteslangtranslator().find(quotes_lang);
730 } else if (token == "\\papersize") {
733 papersize = papersizetranslator().find(ppsize);
734 } else if (token == "\\use_geometry") {
736 } else if (token == "\\use_package") {
741 use_package(package, packagetranslator().find(use));
742 } else if (token == "\\cite_engine") {
744 vector<string> engine = getVectorFromString(lex.getString());
745 setCiteEngine(engine);
746 } else if (token == "\\cite_engine_type") {
749 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
750 } else if (token == "\\biblio_style") {
752 biblio_style = lex.getString();
753 } else if (token == "\\use_bibtopic") {
755 } else if (token == "\\use_indices") {
757 } else if (token == "\\tracking_changes") {
758 lex >> track_changes;
759 } else if (token == "\\output_changes") {
760 lex >> output_changes;
761 } else if (token == "\\branch") {
763 docstring branch = lex.getDocString();
764 branchlist().add(branch);
767 string const tok = lex.getString();
768 if (tok == "\\end_branch")
770 Branch * branch_ptr = branchlist().find(branch);
771 if (tok == "\\selected") {
774 branch_ptr->setSelected(lex.getInteger());
776 if (tok == "\\filename_suffix") {
779 branch_ptr->setFileNameSuffix(lex.getInteger());
781 if (tok == "\\color") {
783 string color = lex.getString();
785 branch_ptr->setColor(color);
786 // Update also the Color table:
788 color = lcolor.getX11Name(Color_background);
790 lcolor.setColor(to_utf8(branch), color);
793 } else if (token == "\\index") {
795 docstring index = lex.getDocString();
797 indiceslist().add(index);
800 string const tok = lex.getString();
801 if (tok == "\\end_index")
803 Index * index_ptr = indiceslist().find(index);
804 if (tok == "\\shortcut") {
806 shortcut = lex.getDocString();
808 index_ptr->setShortcut(shortcut);
810 if (tok == "\\color") {
812 string color = lex.getString();
814 index_ptr->setColor(color);
815 // Update also the Color table:
817 color = lcolor.getX11Name(Color_background);
819 if (!shortcut.empty())
820 lcolor.setColor(to_utf8(shortcut), color);
823 } else if (token == "\\author") {
825 istringstream ss(lex.getString());
828 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
829 } else if (token == "\\paperorientation") {
832 orientation = paperorientationtranslator().find(orient);
833 } else if (token == "\\backgroundcolor") {
835 backgroundcolor = lyx::rgbFromHexName(lex.getString());
836 isbackgroundcolor = true;
837 } else if (token == "\\fontcolor") {
839 fontcolor = lyx::rgbFromHexName(lex.getString());
841 } else if (token == "\\notefontcolor") {
843 string color = lex.getString();
844 notefontcolor = lyx::rgbFromHexName(color);
845 lcolor.setColor("notefontcolor", color);
846 } else if (token == "\\boxbgcolor") {
848 string color = lex.getString();
849 boxbgcolor = lyx::rgbFromHexName(color);
850 lcolor.setColor("boxbgcolor", color);
851 } else if (token == "\\paperwidth") {
853 } else if (token == "\\paperheight") {
855 } else if (token == "\\leftmargin") {
857 } else if (token == "\\topmargin") {
859 } else if (token == "\\rightmargin") {
861 } else if (token == "\\bottommargin") {
863 } else if (token == "\\headheight") {
865 } else if (token == "\\headsep") {
867 } else if (token == "\\footskip") {
869 } else if (token == "\\columnsep") {
871 } else if (token == "\\paperfontsize") {
873 } else if (token == "\\papercolumns") {
875 } else if (token == "\\listings_params") {
878 listings_params = InsetListingsParams(par).params();
879 } else if (token == "\\papersides") {
882 sides = sidestranslator().find(psides);
883 } else if (token == "\\paperpagestyle") {
885 } else if (token == "\\bullet") {
887 } else if (token == "\\bulletLaTeX") {
888 readBulletsLaTeX(lex);
889 } else if (token == "\\secnumdepth") {
891 } else if (token == "\\tocdepth") {
893 } else if (token == "\\spacing") {
897 if (nspacing == "other") {
900 spacing().set(spacetranslator().find(nspacing), tmp_val);
901 } else if (token == "\\float_placement") {
902 lex >> float_placement;
904 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
905 string toktmp = pdfoptions().readToken(lex, token);
906 if (!toktmp.empty()) {
907 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
911 } else if (token == "\\html_math_output") {
914 html_math_output = static_cast<MathOutput>(temp);
915 } else if (token == "\\html_be_strict") {
916 lex >> html_be_strict;
917 } else if (token == "\\html_css_as_file") {
918 lex >> html_css_as_file;
919 } else if (token == "\\html_math_img_scale") {
920 lex >> html_math_img_scale;
921 } else if (token == "\\html_latex_start") {
923 html_latex_start = lex.getString();
924 } else if (token == "\\html_latex_end") {
926 html_latex_end = lex.getString();
927 } else if (token == "\\output_sync") {
929 } else if (token == "\\output_sync_macro") {
930 lex >> output_sync_macro;
931 } else if (token == "\\use_refstyle") {
934 lyxerr << "BufferParams::readToken(): Unknown token: " <<
943 void BufferParams::writeFile(ostream & os) const
945 // The top of the file is written by the buffer.
946 // Prints out the buffer info into the .lyx file given by file
949 os << "\\textclass " << baseClass()->name() << '\n';
952 if (!preamble.empty()) {
953 // remove '\n' from the end of preamble
954 string const tmppreamble = rtrim(preamble, "\n");
955 os << "\\begin_preamble\n"
957 << "\n\\end_preamble\n";
961 if (!options.empty()) {
962 os << "\\options " << options << '\n';
965 // use the class options defined in the layout?
966 os << "\\use_default_options "
967 << convert<string>(use_default_options) << "\n";
969 // the master document
970 if (!master.empty()) {
971 os << "\\master " << master << '\n';
975 if (!removed_modules_.empty()) {
976 os << "\\begin_removed_modules" << '\n';
977 list<string>::const_iterator it = removed_modules_.begin();
978 list<string>::const_iterator en = removed_modules_.end();
979 for (; it != en; ++it)
981 os << "\\end_removed_modules" << '\n';
985 if (!layout_modules_.empty()) {
986 os << "\\begin_modules" << '\n';
987 LayoutModuleList::const_iterator it = layout_modules_.begin();
988 LayoutModuleList::const_iterator en = layout_modules_.end();
989 for (; it != en; ++it)
991 os << "\\end_modules" << '\n';
995 if (!included_children_.empty()) {
996 os << "\\begin_includeonly" << '\n';
997 list<string>::const_iterator it = included_children_.begin();
998 list<string>::const_iterator en = included_children_.end();
999 for (; it != en; ++it)
1001 os << "\\end_includeonly" << '\n';
1003 os << "\\maintain_unincluded_children "
1004 << convert<string>(maintain_unincluded_children) << '\n';
1006 // local layout information
1007 string const local_layout = getLocalLayout(false);
1008 if (!local_layout.empty()) {
1009 // remove '\n' from the end
1010 string const tmplocal = rtrim(local_layout, "\n");
1011 os << "\\begin_local_layout\n"
1013 << "\n\\end_local_layout\n";
1015 string const forced_local_layout = getLocalLayout(true);
1016 if (!forced_local_layout.empty()) {
1017 // remove '\n' from the end
1018 string const tmplocal = rtrim(forced_local_layout, "\n");
1019 os << "\\begin_forced_local_layout\n"
1021 << "\n\\end_forced_local_layout\n";
1024 // then the text parameters
1025 if (language != ignore_language)
1026 os << "\\language " << language->lang() << '\n';
1027 os << "\\language_package " << lang_package
1028 << "\n\\inputencoding " << inputenc
1029 << "\n\\fontencoding " << fontenc
1030 << "\n\\font_roman " << fonts_roman
1031 << "\n\\font_sans " << fonts_sans
1032 << "\n\\font_typewriter " << fonts_typewriter
1033 << "\n\\font_math " << fonts_math
1034 << "\n\\font_default_family " << fonts_default_family
1035 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
1036 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
1037 << "\n\\font_osf " << convert<string>(fonts_old_figures)
1038 << "\n\\font_sf_scale " << fonts_sans_scale
1039 << "\n\\font_tt_scale " << fonts_typewriter_scale
1041 if (!fonts_cjk.empty()) {
1042 os << "\\font_cjk " << fonts_cjk << '\n';
1044 os << "\\graphics " << graphics_driver << '\n';
1045 os << "\\default_output_format " << default_output_format << '\n';
1046 os << "\\output_sync " << output_sync << '\n';
1047 if (!output_sync_macro.empty())
1048 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1049 os << "\\bibtex_command " << bibtex_command << '\n';
1050 os << "\\index_command " << index_command << '\n';
1052 if (!float_placement.empty()) {
1053 os << "\\float_placement " << float_placement << '\n';
1055 os << "\\paperfontsize " << fontsize << '\n';
1057 spacing().writeFile(os);
1058 pdfoptions().writeFile(os);
1060 os << "\\papersize " << string_papersize[papersize]
1061 << "\n\\use_geometry " << convert<string>(use_geometry);
1062 map<string, string> const & packages = auto_packages();
1063 for (map<string, string>::const_iterator it = packages.begin();
1064 it != packages.end(); ++it)
1065 os << "\n\\use_package " << it->first << ' '
1066 << use_package(it->first);
1068 os << "\n\\cite_engine ";
1070 if (!cite_engine_.empty()) {
1071 LayoutModuleList::const_iterator be = cite_engine_.begin();
1072 LayoutModuleList::const_iterator en = cite_engine_.end();
1073 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1082 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1083 << "\n\\biblio_style " << biblio_style
1084 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1085 << "\n\\use_indices " << convert<string>(use_indices)
1086 << "\n\\paperorientation " << string_orientation[orientation]
1087 << "\n\\suppress_date " << convert<string>(suppress_date)
1088 << "\n\\justification " << convert<string>(justification)
1089 << "\n\\use_refstyle " << use_refstyle
1091 if (isbackgroundcolor == true)
1092 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1093 if (isfontcolor == true)
1094 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1095 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1096 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1097 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1098 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1100 BranchList::const_iterator it = branchlist().begin();
1101 BranchList::const_iterator end = branchlist().end();
1102 for (; it != end; ++it) {
1103 os << "\\branch " << to_utf8(it->branch())
1104 << "\n\\selected " << it->isSelected()
1105 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1106 << "\n\\color " << lyx::X11hexname(it->color())
1111 IndicesList::const_iterator iit = indiceslist().begin();
1112 IndicesList::const_iterator iend = indiceslist().end();
1113 for (; iit != iend; ++iit) {
1114 os << "\\index " << to_utf8(iit->index())
1115 << "\n\\shortcut " << to_utf8(iit->shortcut())
1116 << "\n\\color " << lyx::X11hexname(iit->color())
1121 if (!paperwidth.empty())
1122 os << "\\paperwidth "
1123 << VSpace(paperwidth).asLyXCommand() << '\n';
1124 if (!paperheight.empty())
1125 os << "\\paperheight "
1126 << VSpace(paperheight).asLyXCommand() << '\n';
1127 if (!leftmargin.empty())
1128 os << "\\leftmargin "
1129 << VSpace(leftmargin).asLyXCommand() << '\n';
1130 if (!topmargin.empty())
1131 os << "\\topmargin "
1132 << VSpace(topmargin).asLyXCommand() << '\n';
1133 if (!rightmargin.empty())
1134 os << "\\rightmargin "
1135 << VSpace(rightmargin).asLyXCommand() << '\n';
1136 if (!bottommargin.empty())
1137 os << "\\bottommargin "
1138 << VSpace(bottommargin).asLyXCommand() << '\n';
1139 if (!headheight.empty())
1140 os << "\\headheight "
1141 << VSpace(headheight).asLyXCommand() << '\n';
1142 if (!headsep.empty())
1144 << VSpace(headsep).asLyXCommand() << '\n';
1145 if (!footskip.empty())
1147 << VSpace(footskip).asLyXCommand() << '\n';
1148 if (!columnsep.empty())
1149 os << "\\columnsep "
1150 << VSpace(columnsep).asLyXCommand() << '\n';
1151 os << "\\secnumdepth " << secnumdepth
1152 << "\n\\tocdepth " << tocdepth
1153 << "\n\\paragraph_separation "
1154 << string_paragraph_separation[paragraph_separation];
1155 if (!paragraph_separation)
1156 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1158 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1159 os << "\n\\quotes_language "
1160 << string_quotes_language[quotes_language]
1161 << "\n\\papercolumns " << columns
1162 << "\n\\papersides " << sides
1163 << "\n\\paperpagestyle " << pagestyle << '\n';
1164 if (!listings_params.empty())
1165 os << "\\listings_params \"" <<
1166 InsetListingsParams(listings_params).encodedString() << "\"\n";
1167 for (int i = 0; i < 4; ++i) {
1168 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1169 if (user_defined_bullet(i).getFont() != -1) {
1170 os << "\\bullet " << i << " "
1171 << user_defined_bullet(i).getFont() << " "
1172 << user_defined_bullet(i).getCharacter() << " "
1173 << user_defined_bullet(i).getSize() << "\n";
1177 os << "\\bulletLaTeX " << i << " \""
1178 << lyx::to_ascii(user_defined_bullet(i).getText())
1184 os << "\\tracking_changes " << convert<string>(track_changes) << '\n'
1185 << "\\output_changes " << convert<string>(output_changes) << '\n'
1186 << "\\html_math_output " << html_math_output << '\n'
1187 << "\\html_css_as_file " << html_css_as_file << '\n'
1188 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1190 if (html_math_img_scale != 1.0)
1191 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1192 if (!html_latex_start.empty())
1193 os << "\\html_latex_start " << html_latex_start << '\n';
1194 if (!html_latex_end.empty())
1195 os << "\\html_latex_end " << html_latex_end << '\n';
1197 os << pimpl_->authorlist;
1201 void BufferParams::validate(LaTeXFeatures & features) const
1203 features.require(documentClass().requires());
1205 if (columns > 1 && language->rightToLeft())
1206 features.require("rtloutputdblcol");
1208 if (output_changes) {
1209 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1210 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1211 LaTeXFeatures::isAvailable("xcolor");
1213 switch (features.runparams().flavor) {
1214 case OutputParams::LATEX:
1215 case OutputParams::DVILUATEX:
1217 features.require("ct-dvipost");
1218 features.require("dvipost");
1219 } else if (xcolorulem) {
1220 features.require("ct-xcolor-ulem");
1221 features.require("ulem");
1222 features.require("xcolor");
1224 features.require("ct-none");
1227 case OutputParams::LUATEX:
1228 case OutputParams::PDFLATEX:
1229 case OutputParams::XETEX:
1231 features.require("ct-xcolor-ulem");
1232 features.require("ulem");
1233 features.require("xcolor");
1234 // improves color handling in PDF output
1235 features.require("pdfcolmk");
1237 features.require("ct-none");
1245 // Floats with 'Here definitely' as default setting.
1246 if (float_placement.find('H') != string::npos)
1247 features.require("float");
1249 for (PackageMap::const_iterator it = use_packages.begin();
1250 it != use_packages.end(); ++it) {
1251 if (it->first == "amsmath") {
1252 // AMS Style is at document level
1253 if (it->second == package_on ||
1254 features.isProvided("amsmath"))
1255 features.require(it->first);
1256 } else if (it->second == package_on)
1257 features.require(it->first);
1260 // Document-level line spacing
1261 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1262 features.require("setspace");
1264 // the bullet shapes are buffer level not paragraph level
1265 // so they are tested here
1266 for (int i = 0; i < 4; ++i) {
1267 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1269 int const font = user_defined_bullet(i).getFont();
1271 int const c = user_defined_bullet(i).getCharacter();
1277 features.require("latexsym");
1279 } else if (font == 1) {
1280 features.require("amssymb");
1281 } else if (font >= 2 && font <= 5) {
1282 features.require("pifont");
1286 if (pdfoptions().use_hyperref) {
1287 features.require("hyperref");
1288 // due to interferences with babel and hyperref, the color package has to
1289 // be loaded after hyperref when hyperref is used with the colorlinks
1290 // option, see http://www.lyx.org/trac/ticket/5291
1291 if (pdfoptions().colorlinks)
1292 features.require("color");
1294 if (!listings_params.empty()) {
1295 // do not test validity because listings_params is
1296 // supposed to be valid
1298 InsetListingsParams(listings_params).separatedParams(true);
1299 // we can't support all packages, but we should load the color package
1300 if (par.find("\\color", 0) != string::npos)
1301 features.require("color");
1304 // some languages are only available via polyglossia
1305 if (features.runparams().flavor == OutputParams::XETEX
1306 && (features.hasPolyglossiaExclusiveLanguages()
1308 features.require("polyglossia");
1310 if (useNonTeXFonts && fonts_math != "auto")
1311 features.require("unicode-math");
1313 if (!language->requires().empty())
1314 features.require(language->requires());
1318 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1319 FileName const & filepath) const
1321 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1322 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1323 // \RequirePackage to do so, rather than the normal \usepackage
1324 // Do not try to load any other package before the document class, unless you
1325 // have a thorough understanding of the LATEX internals and know exactly what you
1327 if (features.mustProvide("fix-cm"))
1328 os << "\\RequirePackage{fix-cm}\n";
1329 // Likewise for fixltx2e. If other packages conflict with this policy,
1330 // treat it as a package bug (and report it!)
1331 // See http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/4407
1332 if (features.mustProvide("fixltx2e"))
1333 os << "\\RequirePackage{fixltx2e}\n";
1335 os << "\\documentclass";
1337 DocumentClass const & tclass = documentClass();
1339 ostringstream clsoptions; // the document class options.
1341 if (tokenPos(tclass.opt_fontsize(),
1342 '|', fontsize) >= 0) {
1343 // only write if existing in list (and not default)
1344 clsoptions << fontsize << "pt,";
1347 // all paper sizes except of A4, A5, B5 and the US sizes need the
1349 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1350 && papersize != PAPER_USLETTER
1351 && papersize != PAPER_USLEGAL
1352 && papersize != PAPER_USEXECUTIVE
1353 && papersize != PAPER_A4
1354 && papersize != PAPER_A5
1355 && papersize != PAPER_B5;
1357 if (!use_geometry) {
1358 switch (papersize) {
1360 clsoptions << "a4paper,";
1362 case PAPER_USLETTER:
1363 clsoptions << "letterpaper,";
1366 clsoptions << "a5paper,";
1369 clsoptions << "b5paper,";
1371 case PAPER_USEXECUTIVE:
1372 clsoptions << "executivepaper,";
1375 clsoptions << "legalpaper,";
1409 if (sides != tclass.sides()) {
1412 clsoptions << "oneside,";
1415 clsoptions << "twoside,";
1421 if (columns != tclass.columns()) {
1423 clsoptions << "twocolumn,";
1425 clsoptions << "onecolumn,";
1429 && orientation == ORIENTATION_LANDSCAPE)
1430 clsoptions << "landscape,";
1432 // language should be a parameter to \documentclass
1433 if (language->babel() == "hebrew"
1434 && default_language->babel() != "hebrew")
1435 // This seems necessary
1436 features.useLanguage(default_language);
1438 ostringstream language_options;
1439 bool const use_babel = features.useBabel() && !features.isProvided("babel");
1440 bool const use_polyglossia = features.usePolyglossia();
1441 bool const global = lyxrc.language_global_options;
1442 if (use_babel || (use_polyglossia && global)) {
1443 language_options << features.getBabelLanguages();
1444 if (!language->babel().empty()) {
1445 if (!language_options.str().empty())
1446 language_options << ',';
1447 language_options << language->babel();
1449 if (global && !features.needBabelLangOptions()
1450 && !language_options.str().empty())
1451 clsoptions << language_options.str() << ',';
1454 // the predefined options from the layout
1455 if (use_default_options && !tclass.options().empty())
1456 clsoptions << tclass.options() << ',';
1458 // the user-defined options
1459 if (!options.empty()) {
1460 clsoptions << options << ',';
1463 string strOptions(clsoptions.str());
1464 if (!strOptions.empty()) {
1465 strOptions = rtrim(strOptions, ",");
1467 os << '[' << from_utf8(strOptions) << ']';
1470 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1471 // end of \documentclass defs
1473 // if we use fontspec or newtxmath, we have to load the AMS packages here
1474 string const ams = features.loadAMSPackages();
1475 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
1476 bool const use_newtxmath =
1477 theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getUsedPackage(
1478 ot1, false, false) == "newtxmath";
1479 if ((useNonTeXFonts || use_newtxmath) && !ams.empty())
1480 os << from_ascii(ams);
1482 if (useNonTeXFonts) {
1483 os << "\\usepackage{fontspec}\n";
1484 if (features.mustProvide("unicode-math")
1485 && features.isAvailable("unicode-math"))
1486 os << "\\usepackage{unicode-math}\n";
1489 // font selection must be done before loading fontenc.sty
1490 string const fonts = loadFonts(features);
1492 os << from_utf8(fonts);
1494 if (fonts_default_family != "default")
1495 os << "\\renewcommand{\\familydefault}{\\"
1496 << from_ascii(fonts_default_family) << "}\n";
1498 // set font encoding
1499 // XeTeX and LuaTeX (with OS fonts) do not need fontenc
1500 if (!useNonTeXFonts && !features.isProvided("fontenc")
1501 && font_encoding() != "default") {
1502 vector<string> fontencs;
1503 // primary language font encoding and default encoding
1504 if (ascii_lowercase(language->fontenc()) != "none") {
1505 vector<string> fencs = getVectorFromString(font_encoding());
1506 fontencs.insert(fontencs.end(), fencs.begin(), fencs.end());
1507 fencs = getVectorFromString(language->fontenc());
1508 vector<string>::const_iterator fit = fencs.begin();
1509 for (; fit != fencs.end(); ++fit) {
1510 if (find(fontencs.begin(), fontencs.end(), *fit) == fontencs.end())
1511 fontencs.push_back(*fit);
1514 // get font encodings of secondary languages
1515 features.getFontEncodings(fontencs);
1516 if (!fontencs.empty()) {
1517 os << "\\usepackage["
1518 << from_ascii(getStringFromVector(fontencs))
1523 // handle inputenc etc.
1524 writeEncodingPreamble(os, features);
1527 if (!features.runparams().includeall && !included_children_.empty()) {
1528 os << "\\includeonly{";
1529 list<string>::const_iterator it = included_children_.begin();
1530 list<string>::const_iterator en = included_children_.end();
1532 for (; it != en; ++it) {
1533 string incfile = *it;
1534 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1535 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1537 if (!features.runparams().nice)
1539 // \includeonly doesn't want an extension
1540 incfile = changeExtension(incfile, string());
1541 incfile = support::latex_path(incfile);
1542 if (!incfile.empty()) {
1545 os << from_utf8(incfile);
1552 if (!features.isProvided("geometry")
1553 && (use_geometry || nonstandard_papersize)) {
1554 odocstringstream ods;
1555 if (!getGraphicsDriver("geometry").empty())
1556 ods << getGraphicsDriver("geometry");
1557 if (orientation == ORIENTATION_LANDSCAPE)
1558 ods << ",landscape";
1559 switch (papersize) {
1561 if (!paperwidth.empty())
1562 ods << ",paperwidth="
1563 << from_ascii(paperwidth);
1564 if (!paperheight.empty())
1565 ods << ",paperheight="
1566 << from_ascii(paperheight);
1568 case PAPER_USLETTER:
1569 ods << ",letterpaper";
1572 ods << ",legalpaper";
1574 case PAPER_USEXECUTIVE:
1575 ods << ",executivepaper";
1664 docstring const g_options = trim(ods.str(), ",");
1665 os << "\\usepackage";
1666 if (!g_options.empty())
1667 os << '[' << g_options << ']';
1668 os << "{geometry}\n";
1669 // output this only if use_geometry is true
1671 os << "\\geometry{verbose";
1672 if (!topmargin.empty())
1673 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1674 if (!bottommargin.empty())
1675 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1676 if (!leftmargin.empty())
1677 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1678 if (!rightmargin.empty())
1679 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1680 if (!headheight.empty())
1681 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1682 if (!headsep.empty())
1683 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1684 if (!footskip.empty())
1685 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1686 if (!columnsep.empty())
1687 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1690 } else if (orientation == ORIENTATION_LANDSCAPE
1691 || papersize != PAPER_DEFAULT) {
1692 features.require("papersize");
1695 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1696 if (pagestyle == "fancy")
1697 os << "\\usepackage{fancyhdr}\n";
1698 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1701 // only output when the background color is not default
1702 if (isbackgroundcolor == true) {
1703 // only require color here, the background color will be defined
1704 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1706 features.require("color");
1707 features.require("pagecolor");
1710 // only output when the font color is not default
1711 if (isfontcolor == true) {
1712 // only require color here, the font color will be defined
1713 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1715 features.require("color");
1716 features.require("fontcolor");
1719 // Only if class has a ToC hierarchy
1720 if (tclass.hasTocLevels()) {
1721 if (secnumdepth != tclass.secnumdepth()) {
1722 os << "\\setcounter{secnumdepth}{"
1726 if (tocdepth != tclass.tocdepth()) {
1727 os << "\\setcounter{tocdepth}{"
1733 if (paragraph_separation) {
1734 // when skip separation
1735 switch (getDefSkip().kind()) {
1736 case VSpace::SMALLSKIP:
1737 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1739 case VSpace::MEDSKIP:
1740 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1742 case VSpace::BIGSKIP:
1743 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1745 case VSpace::LENGTH:
1746 os << "\\setlength{\\parskip}{"
1747 << from_utf8(getDefSkip().length().asLatexString())
1750 default: // should never happen // Then delete it.
1751 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1754 os << "\\setlength{\\parindent}{0pt}\n";
1756 // when separation by indentation
1757 // only output something when a width is given
1758 if (getIndentation().asLyXCommand() != "default") {
1759 os << "\\setlength{\\parindent}{"
1760 << from_utf8(getIndentation().asLatexCommand())
1765 // Now insert the LyX specific LaTeX commands...
1766 docstring lyxpreamble;
1767 features.resolveAlternatives();
1770 if (!output_sync_macro.empty())
1771 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1772 else if (features.runparams().flavor == OutputParams::LATEX)
1773 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1774 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1775 lyxpreamble += "\\synctex=-1\n";
1778 // The package options (via \PassOptionsToPackage)
1779 lyxpreamble += from_ascii(features.getPackageOptions());
1781 // due to interferences with babel and hyperref, the color package has to
1782 // be loaded (when it is not already loaded) before babel when hyperref
1783 // is used with the colorlinks option, see
1784 // http://www.lyx.org/trac/ticket/5291
1785 // we decided therefore to load color always before babel, see
1786 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1787 lyxpreamble += from_ascii(features.getColorOptions());
1789 // If we use hyperref, jurabib, japanese, varioref or vietnamese,
1790 // we have to call babel before
1792 && (features.isRequired("jurabib")
1793 || features.isRequired("hyperref")
1794 || features.isRequired("varioref")
1795 || features.isRequired("vietnamese")
1796 || features.isRequired("japanese"))) {
1798 lyxpreamble += from_utf8(features.getBabelPresettings());
1799 lyxpreamble += from_utf8(babelCall(language_options.str(),
1800 features.needBabelLangOptions())) + '\n';
1801 lyxpreamble += from_utf8(features.getBabelPostsettings());
1804 // The optional packages;
1805 lyxpreamble += from_ascii(features.getPackages());
1807 // Additional Indices
1808 if (features.isRequired("splitidx")) {
1809 IndicesList::const_iterator iit = indiceslist().begin();
1810 IndicesList::const_iterator iend = indiceslist().end();
1811 for (; iit != iend; ++iit) {
1812 pair<docstring, docstring> indexname_latex =
1813 features.runparams().encoding->latexString(iit->index(),
1814 features.runparams().dryrun);
1815 if (!indexname_latex.second.empty()) {
1816 // issue a warning about omitted characters
1817 // FIXME: should be passed to the error dialog
1818 frontend::Alert::warning(_("Uncodable characters"),
1819 bformat(_("The following characters that are used in an index name are not\n"
1820 "representable in the current encoding and therefore have been omitted:\n%1$s."),
1821 indexname_latex.second));
1823 lyxpreamble += "\\newindex[";
1824 lyxpreamble += indexname_latex.first;
1825 lyxpreamble += "]{";
1826 lyxpreamble += escape(iit->shortcut());
1827 lyxpreamble += "}\n";
1832 lyxpreamble += from_utf8(spacing().writePreamble(features.isProvided("SetSpace")));
1835 // * Hyperref manual: "Make sure it comes last of your loaded
1836 // packages, to give it a fighting chance of not being over-written,
1837 // since its job is to redefine many LaTeX commands."
1838 // * Email from Heiko Oberdiek: "It is usually better to load babel
1839 // before hyperref. Then hyperref has a chance to detect babel.
1840 // * Has to be loaded before the "LyX specific LaTeX commands" to
1841 // avoid errors with algorithm floats.
1842 // use hyperref explicitly if it is required
1843 if (features.isRequired("hyperref")) {
1844 // pass what we have to stream here, since we need
1845 // to access the stream itself in PDFOptions.
1848 OutputParams tmp_params = features.runparams();
1849 pdfoptions().writeLaTeX(tmp_params, os,
1850 features.isProvided("hyperref"));
1851 // set back for the rest
1852 lyxpreamble.clear();
1853 // correctly break URLs with hyperref and dvi output
1854 if (features.runparams().flavor == OutputParams::LATEX
1855 && features.isAvailable("breakurl"))
1856 lyxpreamble += "\\usepackage{breakurl}\n";
1857 } else if (features.isRequired("nameref"))
1858 // hyperref loads this automatically
1859 lyxpreamble += "\\usepackage{nameref}\n";
1861 // bibtopic needs to be loaded after hyperref.
1862 // the dot provides the aux file naming which LyX can detect.
1863 if (features.mustProvide("bibtopic"))
1864 lyxpreamble += "\\usepackage[dot]{bibtopic}\n";
1866 // Will be surrounded by \makeatletter and \makeatother when not empty
1867 docstring atlyxpreamble;
1869 // Some macros LyX will need
1870 docstring tmppreamble(features.getMacros());
1872 if (!tmppreamble.empty())
1873 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1874 "LyX specific LaTeX commands.\n"
1875 + tmppreamble + '\n';
1877 // the text class specific preamble
1878 tmppreamble = features.getTClassPreamble();
1879 if (!tmppreamble.empty())
1880 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1881 "Textclass specific LaTeX commands.\n"
1882 + tmppreamble + '\n';
1884 // suppress date if selected
1885 // use \@ifundefined because we cannot be sure that every document class
1886 // has a \date command
1888 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1890 /* the user-defined preamble */
1891 if (!containsOnly(preamble, " \n\t"))
1893 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1894 "User specified LaTeX commands.\n"
1895 + from_utf8(preamble) + '\n';
1897 // footmisc must be loaded after setspace
1898 // Load it here to avoid clashes with footmisc loaded in the user
1899 // preamble. For that reason we also pass the options via
1900 // \PassOptionsToPackage in getPreamble() and not here.
1901 if (features.mustProvide("footmisc"))
1902 atlyxpreamble += "\\usepackage{footmisc}\n";
1904 // subfig loads internally the LaTeX package "caption". As
1905 // caption is a very popular package, users will load it in
1906 // the preamble. Therefore we must load subfig behind the
1907 // user-defined preamble and check if the caption package was
1908 // loaded or not. For the case that caption is loaded before
1909 // subfig, there is the subfig option "caption=false". This
1910 // option also works when a koma-script class is used and
1911 // koma's own caption commands are used instead of caption. We
1912 // use \PassOptionsToPackage here because the user could have
1913 // already loaded subfig in the preamble.
1914 if (features.isRequired("subfig")) {
1915 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1916 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1917 "\\usepackage{subfig}\n";
1920 // Itemize bullet settings need to be last in case the user
1921 // defines their own bullets that use a package included
1922 // in the user-defined preamble -- ARRae
1923 // Actually it has to be done much later than that
1924 // since some packages like frenchb make modifications
1925 // at \begin{document} time -- JMarc
1926 docstring bullets_def;
1927 for (int i = 0; i < 4; ++i) {
1928 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1929 if (bullets_def.empty())
1930 bullets_def += "\\AtBeginDocument{\n";
1931 bullets_def += " \\def\\labelitemi";
1933 // `i' is one less than the item to modify
1940 bullets_def += "ii";
1946 bullets_def += '{' +
1947 user_defined_bullet(i).getText()
1952 if (!bullets_def.empty())
1953 atlyxpreamble += bullets_def + "}\n\n";
1955 if (!atlyxpreamble.empty())
1956 lyxpreamble += "\n\\makeatletter\n"
1957 + atlyxpreamble + "\\makeatother\n\n";
1959 // We try to load babel late, in case it interferes with other packages.
1960 // Jurabib, hyperref, varioref, bicaption and listings (bug 8995) have to be
1961 // called after babel, though.
1962 if (use_babel && !features.isRequired("jurabib")
1963 && !features.isRequired("hyperref")
1964 && !features.isRequired("varioref")
1965 && !features.isRequired("vietnamese")
1966 && !features.isRequired("japanese")) {
1968 lyxpreamble += from_utf8(features.getBabelPresettings());
1969 lyxpreamble += from_utf8(babelCall(language_options.str(),
1970 features.needBabelLangOptions())) + '\n';
1971 lyxpreamble += from_utf8(features.getBabelPostsettings());
1973 if (features.isRequired("bicaption"))
1974 lyxpreamble += "\\usepackage{bicaption}\n";
1975 if (!listings_params.empty() || features.isRequired("listings"))
1976 lyxpreamble += "\\usepackage{listings}\n";
1977 if (!listings_params.empty()) {
1978 lyxpreamble += "\\lstset{";
1979 // do not test validity because listings_params is
1980 // supposed to be valid
1982 InsetListingsParams(listings_params).separatedParams(true);
1983 lyxpreamble += from_utf8(par);
1984 lyxpreamble += "}\n";
1987 // xunicode needs to be loaded at least after amsmath, amssymb,
1988 // esint and the other packages that provide special glyphs
1989 if (features.runparams().flavor == OutputParams::XETEX
1991 lyxpreamble += "\\usepackage{xunicode}\n";
1993 // Polyglossia must be loaded last
1994 if (use_polyglossia) {
1996 lyxpreamble += "\\usepackage{polyglossia}\n";
1997 // set the main language
1998 lyxpreamble += "\\setdefaultlanguage";
1999 if (!language->polyglossiaOpts().empty())
2000 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
2001 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
2002 // now setup the other languages
2003 std::map<std::string, std::string> const polylangs =
2004 features.getPolyglossiaLanguages();
2005 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
2006 mit != polylangs.end() ; ++mit) {
2007 lyxpreamble += "\\setotherlanguage";
2008 if (!mit->second.empty())
2009 lyxpreamble += "[" + from_ascii(mit->second) + "]";
2010 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
2014 // Load custom language package here
2015 if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
2016 if (lang_package == "default")
2017 lyxpreamble += from_utf8(lyxrc.language_custom_package);
2019 lyxpreamble += from_utf8(lang_package);
2020 lyxpreamble += '\n';
2023 docstring const i18npreamble =
2024 features.getTClassI18nPreamble(use_babel, use_polyglossia);
2025 if (!i18npreamble.empty())
2026 lyxpreamble += i18npreamble + '\n';
2034 void BufferParams::useClassDefaults()
2036 DocumentClass const & tclass = documentClass();
2038 sides = tclass.sides();
2039 columns = tclass.columns();
2040 pagestyle = tclass.pagestyle();
2041 use_default_options = true;
2042 // Only if class has a ToC hierarchy
2043 if (tclass.hasTocLevels()) {
2044 secnumdepth = tclass.secnumdepth();
2045 tocdepth = tclass.tocdepth();
2050 bool BufferParams::hasClassDefaults() const
2052 DocumentClass const & tclass = documentClass();
2054 return sides == tclass.sides()
2055 && columns == tclass.columns()
2056 && pagestyle == tclass.pagestyle()
2057 && use_default_options
2058 && secnumdepth == tclass.secnumdepth()
2059 && tocdepth == tclass.tocdepth();
2063 DocumentClass const & BufferParams::documentClass() const
2065 return *doc_class_.get();
2069 DocumentClassConstPtr BufferParams::documentClassPtr() const
2075 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
2077 // evil, but this function is evil
2078 doc_class_ = const_pointer_cast<DocumentClass>(tc);
2082 bool BufferParams::setBaseClass(string const & classname)
2084 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
2085 LayoutFileList & bcl = LayoutFileList::get();
2086 if (!bcl.haveClass(classname)) {
2088 bformat(_("The layout file:\n"
2090 "could not be found. A default textclass with default\n"
2091 "layouts will be used. LyX will not be able to produce\n"
2093 from_utf8(classname));
2094 frontend::Alert::error(_("Document class not found"), s);
2095 bcl.addEmptyClass(classname);
2098 bool const success = bcl[classname].load();
2101 bformat(_("Due to some error in it, the layout file:\n"
2103 "could not be loaded. A default textclass with default\n"
2104 "layouts will be used. LyX will not be able to produce\n"
2106 from_utf8(classname));
2107 frontend::Alert::error(_("Could not load class"), s);
2108 bcl.addEmptyClass(classname);
2111 pimpl_->baseClass_ = classname;
2112 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2117 LayoutFile const * BufferParams::baseClass() const
2119 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2120 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2126 LayoutFileIndex const & BufferParams::baseClassID() const
2128 return pimpl_->baseClass_;
2132 void BufferParams::makeDocumentClass(bool const clone)
2137 LayoutModuleList mods;
2138 LayoutModuleList::iterator it = layout_modules_.begin();
2139 LayoutModuleList::iterator en = layout_modules_.end();
2140 for (; it != en; ++it)
2141 mods.push_back(*it);
2143 it = cite_engine_.begin();
2144 en = cite_engine_.end();
2145 for (; it != en; ++it)
2146 mods.push_back(*it);
2148 doc_class_ = getDocumentClass(*baseClass(), mods, clone);
2150 TextClass::ReturnValues success = TextClass::OK;
2151 if (!forced_local_layout_.empty())
2152 success = doc_class_->read(forced_local_layout_, TextClass::MODULE);
2153 if (!local_layout_.empty() &&
2154 (success == TextClass::OK || success == TextClass::OK_OLDFORMAT))
2155 success = doc_class_->read(local_layout_, TextClass::MODULE);
2156 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2157 docstring const msg = _("Error reading internal layout information");
2158 frontend::Alert::warning(_("Read Error"), msg);
2163 bool BufferParams::layoutModuleCanBeAdded(string const & modName) const
2165 return layout_modules_.moduleCanBeAdded(modName, baseClass());
2169 bool BufferParams::citationModuleCanBeAdded(string const & modName) const
2171 return cite_engine_.moduleCanBeAdded(modName, baseClass());
2175 std::string BufferParams::getLocalLayout(bool forced) const
2178 return doc_class_->forcedLayouts();
2180 return local_layout_;
2184 void BufferParams::setLocalLayout(string const & layout, bool forced)
2187 forced_local_layout_ = layout;
2189 local_layout_ = layout;
2193 bool BufferParams::addLayoutModule(string const & modName)
2195 LayoutModuleList::const_iterator it = layout_modules_.begin();
2196 LayoutModuleList::const_iterator end = layout_modules_.end();
2197 for (; it != end; ++it)
2200 layout_modules_.push_back(modName);
2205 string BufferParams::bufferFormat() const
2207 string format = documentClass().outputFormat();
2208 if (format == "latex") {
2211 if (encoding().package() == Encoding::japanese)
2218 bool BufferParams::isExportable(string const & format) const
2220 vector<string> backs = backends();
2221 for (vector<string>::const_iterator it = backs.begin();
2222 it != backs.end(); ++it)
2223 if (theConverters().isReachable(*it, format))
2229 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2231 vector<string> const backs = backends();
2232 set<string> excludes;
2233 if (useNonTeXFonts) {
2234 excludes.insert("latex");
2235 excludes.insert("pdflatex");
2237 vector<Format const *> result =
2238 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2239 for (vector<string>::const_iterator it = backs.begin() + 1;
2240 it != backs.end(); ++it) {
2241 vector<Format const *> r =
2242 theConverters().getReachable(*it, only_viewable, false, excludes);
2243 result.insert(result.end(), r.begin(), r.end());
2249 bool BufferParams::isExportableFormat(string const & format) const
2251 typedef vector<Format const *> Formats;
2253 formats = exportableFormats(true);
2254 Formats::const_iterator fit = formats.begin();
2255 Formats::const_iterator end = formats.end();
2256 for (; fit != end ; ++fit) {
2257 if ((*fit)->name() == format)
2264 vector<string> BufferParams::backends() const
2267 string const buffmt = bufferFormat();
2269 // FIXME: Don't hardcode format names here, but use a flag
2270 if (buffmt == "latex") {
2271 if (!useNonTeXFonts) {
2272 v.push_back("pdflatex");
2273 v.push_back("latex");
2275 v.push_back("luatex");
2276 v.push_back("dviluatex");
2277 v.push_back("xetex");
2278 } else if (buffmt == "xetex") {
2279 v.push_back("xetex");
2280 // FIXME: need to test all languages (bug 8205)
2281 if (!language || !language->isPolyglossiaExclusive()) {
2282 v.push_back("luatex");
2283 v.push_back("dviluatex");
2286 v.push_back(buffmt);
2288 v.push_back("xhtml");
2289 v.push_back("text");
2295 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const
2297 string const dformat = (format.empty() || format == "default") ?
2298 getDefaultOutputFormat() : format;
2299 DefaultFlavorCache::const_iterator it =
2300 default_flavors_.find(dformat);
2302 if (it != default_flavors_.end())
2305 OutputParams::FLAVOR result = OutputParams::LATEX;
2307 // FIXME It'd be better not to hardcode this, but to do
2308 // something with formats.
2309 if (dformat == "xhtml")
2310 result = OutputParams::HTML;
2311 else if (dformat == "text")
2312 result = OutputParams::TEXT;
2313 else if (dformat == "lyx")
2314 result = OutputParams::LYX;
2315 else if (dformat == "pdflatex")
2316 result = OutputParams::PDFLATEX;
2317 else if (dformat == "xetex")
2318 result = OutputParams::XETEX;
2319 else if (dformat == "luatex")
2320 result = OutputParams::LUATEX;
2321 else if (dformat == "dviluatex")
2322 result = OutputParams::DVILUATEX;
2324 // Try to determine flavor of default output format
2325 vector<string> backs = backends();
2326 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2327 // Get shortest path to format
2328 Graph::EdgePath path;
2329 for (vector<string>::const_iterator it = backs.begin();
2330 it != backs.end(); ++it) {
2331 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2332 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2337 result = theConverters().getFlavor(path);
2340 // cache this flavor
2341 default_flavors_[dformat] = result;
2346 string BufferParams::getDefaultOutputFormat() const
2348 if (!default_output_format.empty()
2349 && default_output_format != "default")
2350 return default_output_format;
2352 || encoding().package() == Encoding::japanese) {
2353 vector<Format const *> const formats = exportableFormats(true);
2354 if (formats.empty())
2356 // return the first we find
2357 return formats.front()->name();
2360 return lyxrc.default_otf_view_format;
2361 return lyxrc.default_view_format;
2364 Font const BufferParams::getFont() const
2366 FontInfo f = documentClass().defaultfont();
2367 if (fonts_default_family == "rmdefault")
2368 f.setFamily(ROMAN_FAMILY);
2369 else if (fonts_default_family == "sfdefault")
2370 f.setFamily(SANS_FAMILY);
2371 else if (fonts_default_family == "ttdefault")
2372 f.setFamily(TYPEWRITER_FAMILY);
2373 return Font(f, language);
2377 InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const & qs) const
2379 return quoteslangtranslator().find(qs);
2383 bool BufferParams::isLatex() const
2385 return documentClass().outputType() == LATEX;
2389 bool BufferParams::isLiterate() const
2391 return documentClass().outputType() == LITERATE;
2395 bool BufferParams::isDocBook() const
2397 return documentClass().outputType() == DOCBOOK;
2401 void BufferParams::readPreamble(Lexer & lex)
2403 if (lex.getString() != "\\begin_preamble")
2404 lyxerr << "Error (BufferParams::readPreamble):"
2405 "consistency check failed." << endl;
2407 preamble = lex.getLongString("\\end_preamble");
2411 void BufferParams::readLocalLayout(Lexer & lex, bool forced)
2413 string const expected = forced ? "\\begin_forced_local_layout" :
2414 "\\begin_local_layout";
2415 if (lex.getString() != expected)
2416 lyxerr << "Error (BufferParams::readLocalLayout):"
2417 "consistency check failed." << endl;
2420 forced_local_layout_ =
2421 lex.getLongString("\\end_forced_local_layout");
2423 local_layout_ = lex.getLongString("\\end_local_layout");
2427 bool BufferParams::setLanguage(string const & lang)
2429 Language const *new_language = languages.getLanguage(lang);
2430 if (!new_language) {
2431 // Language lang was not found
2434 language = new_language;
2439 void BufferParams::readLanguage(Lexer & lex)
2441 if (!lex.next()) return;
2443 string const tmptok = lex.getString();
2445 // check if tmptok is part of tex_babel in tex-defs.h
2446 if (!setLanguage(tmptok)) {
2447 // Language tmptok was not found
2448 language = default_language;
2449 lyxerr << "Warning: Setting language `"
2450 << tmptok << "' to `" << language->lang()
2456 void BufferParams::readGraphicsDriver(Lexer & lex)
2461 string const tmptok = lex.getString();
2462 // check if tmptok is part of tex_graphics in tex_defs.h
2465 string const test = tex_graphics[n++];
2467 if (test == tmptok) {
2468 graphics_driver = tmptok;
2473 "Warning: graphics driver `$$Token' not recognized!\n"
2474 " Setting graphics driver to `default'.\n");
2475 graphics_driver = "default";
2482 void BufferParams::readBullets(Lexer & lex)
2487 int const index = lex.getInteger();
2489 int temp_int = lex.getInteger();
2490 user_defined_bullet(index).setFont(temp_int);
2491 temp_bullet(index).setFont(temp_int);
2493 user_defined_bullet(index).setCharacter(temp_int);
2494 temp_bullet(index).setCharacter(temp_int);
2496 user_defined_bullet(index).setSize(temp_int);
2497 temp_bullet(index).setSize(temp_int);
2501 void BufferParams::readBulletsLaTeX(Lexer & lex)
2503 // The bullet class should be able to read this.
2506 int const index = lex.getInteger();
2508 docstring const temp_str = lex.getDocString();
2510 user_defined_bullet(index).setText(temp_str);
2511 temp_bullet(index).setText(temp_str);
2515 void BufferParams::readModules(Lexer & lex)
2517 if (!lex.eatLine()) {
2518 lyxerr << "Error (BufferParams::readModules):"
2519 "Unexpected end of input." << endl;
2523 string mod = lex.getString();
2524 if (mod == "\\end_modules")
2526 addLayoutModule(mod);
2532 void BufferParams::readRemovedModules(Lexer & lex)
2534 if (!lex.eatLine()) {
2535 lyxerr << "Error (BufferParams::readRemovedModules):"
2536 "Unexpected end of input." << endl;
2540 string mod = lex.getString();
2541 if (mod == "\\end_removed_modules")
2543 removed_modules_.push_back(mod);
2546 // now we want to remove any removed modules that were previously
2547 // added. normally, that will be because default modules were added in
2548 // setBaseClass(), which gets called when \textclass is read at the
2549 // start of the read.
2550 list<string>::const_iterator rit = removed_modules_.begin();
2551 list<string>::const_iterator const ren = removed_modules_.end();
2552 for (; rit != ren; ++rit) {
2553 LayoutModuleList::iterator const mit = layout_modules_.begin();
2554 LayoutModuleList::iterator const men = layout_modules_.end();
2555 LayoutModuleList::iterator found = find(mit, men, *rit);
2558 layout_modules_.erase(found);
2563 void BufferParams::readIncludeonly(Lexer & lex)
2565 if (!lex.eatLine()) {
2566 lyxerr << "Error (BufferParams::readIncludeonly):"
2567 "Unexpected end of input." << endl;
2571 string child = lex.getString();
2572 if (child == "\\end_includeonly")
2574 included_children_.push_back(child);
2580 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2582 switch (papersize) {
2584 // could be anything, so don't guess
2586 case PAPER_CUSTOM: {
2587 if (purpose == XDVI && !paperwidth.empty() &&
2588 !paperheight.empty()) {
2589 // heightxwidth<unit>
2590 string first = paperwidth;
2591 string second = paperheight;
2592 if (orientation == ORIENTATION_LANDSCAPE)
2595 return first.erase(first.length() - 2)
2601 // dvips and dvipdfm do not know this
2602 if (purpose == DVIPS || purpose == DVIPDFM)
2606 if (purpose == DVIPS || purpose == DVIPDFM)
2610 if (purpose == DVIPS || purpose == DVIPDFM)
2620 if (purpose == DVIPS || purpose == DVIPDFM)
2624 if (purpose == DVIPS || purpose == DVIPDFM)
2628 if (purpose == DVIPS || purpose == DVIPDFM)
2632 if (purpose == DVIPS || purpose == DVIPDFM)
2636 if (purpose == DVIPS || purpose == DVIPDFM)
2640 // dvipdfm does not know this
2641 if (purpose == DVIPDFM)
2645 if (purpose == DVIPDFM)
2649 if (purpose == DVIPS || purpose == DVIPDFM)
2653 if (purpose == DVIPS || purpose == DVIPDFM)
2657 if (purpose == DVIPS || purpose == DVIPDFM)
2661 if (purpose == DVIPS || purpose == DVIPDFM)
2665 if (purpose == DVIPS || purpose == DVIPDFM)
2669 if (purpose == DVIPS || purpose == DVIPDFM)
2673 if (purpose == DVIPS || purpose == DVIPDFM)
2677 if (purpose == DVIPS || purpose == DVIPDFM)
2681 if (purpose == DVIPS || purpose == DVIPDFM)
2685 if (purpose == DVIPS || purpose == DVIPDFM)
2689 if (purpose == DVIPS || purpose == DVIPDFM)
2693 if (purpose == DVIPS || purpose == DVIPDFM)
2697 if (purpose == DVIPS || purpose == DVIPDFM)
2701 if (purpose == DVIPS || purpose == DVIPDFM)
2705 if (purpose == DVIPS || purpose == DVIPDFM)
2708 case PAPER_USEXECUTIVE:
2709 // dvipdfm does not know this
2710 if (purpose == DVIPDFM)
2715 case PAPER_USLETTER:
2717 if (purpose == XDVI)
2724 string const BufferParams::dvips_options() const
2728 // If the class loads the geometry package, we do not know which
2729 // paper size is used, since we do not set it (bug 7013).
2730 // Therefore we must not specify any argument here.
2731 // dvips gets the correct paper size via DVI specials in this case
2732 // (if the class uses the geometry package correctly).
2733 if (documentClass().provides("geometry"))
2737 && papersize == PAPER_CUSTOM
2738 && !lyxrc.print_paper_dimension_flag.empty()
2739 && !paperwidth.empty()
2740 && !paperheight.empty()) {
2741 // using a custom papersize
2742 result = lyxrc.print_paper_dimension_flag;
2743 result += ' ' + paperwidth;
2744 result += ',' + paperheight;
2746 string const paper_option = paperSizeName(DVIPS);
2747 if (!paper_option.empty() && (paper_option != "letter" ||
2748 orientation != ORIENTATION_LANDSCAPE)) {
2749 // dvips won't accept -t letter -t landscape.
2750 // In all other cases, include the paper size
2752 result = lyxrc.print_paper_flag;
2753 result += ' ' + paper_option;
2756 if (orientation == ORIENTATION_LANDSCAPE &&
2757 papersize != PAPER_CUSTOM)
2758 result += ' ' + lyxrc.print_landscape_flag;
2763 string const BufferParams::font_encoding() const
2765 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2769 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2771 // suppress the babel call if there is no BabelName defined
2772 // for the document language in the lib/languages file and if no
2773 // other languages are used (lang_opts is then empty)
2774 if (lang_opts.empty())
2776 // either a specific language (AsBabelOptions setting in
2777 // lib/languages) or the prefs require the languages to
2778 // be submitted to babel itself (not the class).
2780 return "\\usepackage[" + lang_opts + "]{babel}";
2781 return "\\usepackage{babel}";
2785 docstring BufferParams::getGraphicsDriver(string const & package) const
2789 if (package == "geometry") {
2790 if (graphics_driver == "dvips"
2791 || graphics_driver == "dvipdfm"
2792 || graphics_driver == "pdftex"
2793 || graphics_driver == "vtex")
2794 result = from_ascii(graphics_driver);
2795 else if (graphics_driver == "dvipdfmx")
2796 result = from_ascii("dvipdfm");
2803 void BufferParams::writeEncodingPreamble(otexstream & os,
2804 LaTeXFeatures & features) const
2806 // XeTeX does not need this
2807 if (features.runparams().flavor == OutputParams::XETEX)
2809 // LuaTeX neither, but with tex fonts, we need to load
2810 // the luainputenc package.
2811 if (features.runparams().flavor == OutputParams::LUATEX
2812 || features.runparams().flavor == OutputParams::DVILUATEX) {
2813 if (!useNonTeXFonts && inputenc != "default"
2814 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2815 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2816 os << "\\usepackage[utf8]{luainputenc}\n";
2820 if (inputenc == "auto") {
2821 string const doc_encoding =
2822 language->encoding()->latexName();
2823 Encoding::Package const package =
2824 language->encoding()->package();
2826 // Create a list with all the input encodings used
2828 set<string> encodings =
2829 features.getEncodingSet(doc_encoding);
2831 // If the "japanese" package (i.e. pLaTeX) is used,
2832 // inputenc must be omitted.
2833 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2834 if ((!encodings.empty() || package == Encoding::inputenc)
2835 && !features.isRequired("japanese")
2836 && !features.isProvided("inputenc")) {
2837 os << "\\usepackage[";
2838 set<string>::const_iterator it = encodings.begin();
2839 set<string>::const_iterator const end = encodings.end();
2841 os << from_ascii(*it);
2844 for (; it != end; ++it)
2845 os << ',' << from_ascii(*it);
2846 if (package == Encoding::inputenc) {
2847 if (!encodings.empty())
2849 os << from_ascii(doc_encoding);
2851 os << "]{inputenc}\n";
2853 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2854 if (language->encoding()->name() == "utf8-cjk"
2855 && LaTeXFeatures::isAvailable("CJKutf8"))
2856 os << "\\usepackage{CJKutf8}\n";
2858 os << "\\usepackage{CJK}\n";
2860 } else if (inputenc != "default") {
2861 switch (encoding().package()) {
2862 case Encoding::none:
2863 case Encoding::japanese:
2865 case Encoding::inputenc:
2866 // do not load inputenc if japanese is used
2867 // or if the class provides inputenc
2868 if (features.isRequired("japanese")
2869 || features.isProvided("inputenc"))
2871 os << "\\usepackage[" << from_ascii(encoding().latexName())
2875 if (encoding().name() == "utf8-cjk"
2876 && LaTeXFeatures::isAvailable("CJKutf8"))
2877 os << "\\usepackage{CJKutf8}\n";
2879 os << "\\usepackage{CJK}\n";
2882 // Load the CJK package if needed by a secondary language.
2883 // If the main encoding is some variant of UTF8, use CJKutf8.
2884 if (encoding().package() != Encoding::CJK && features.mustProvide("CJK")) {
2885 if (encoding().iconvName() == "UTF-8"
2886 && LaTeXFeatures::isAvailable("CJKutf8"))
2887 os << "\\usepackage{CJKutf8}\n";
2889 os << "\\usepackage{CJK}\n";
2895 string const BufferParams::parseFontName(string const & name) const
2897 string mangled = name;
2898 size_t const idx = mangled.find('[');
2899 if (idx == string::npos || idx == 0)
2902 return mangled.substr(0, idx - 1);
2906 string const BufferParams::loadFonts(LaTeXFeatures & features) const
2908 if (fonts_roman == "default" && fonts_sans == "default"
2909 && fonts_typewriter == "default"
2910 && (fonts_math == "default" || fonts_math == "auto"))
2916 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
2917 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
2918 * Mapping=tex-text option assures TeX ligatures (such as "--")
2919 * are resolved. Note that tt does not use these ligatures.
2921 * -- add more GUI options?
2922 * -- add more fonts (fonts for other scripts)
2923 * -- if there's a way to find out if a font really supports
2924 * OldStyle, enable/disable the widget accordingly.
2926 if (useNonTeXFonts && features.isAvailable("fontspec")) {
2927 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
2928 // However, until v.2 (2010/07/11) fontspec only knew
2929 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
2930 // was introduced for both XeTeX and LuaTeX (LuaTeX
2931 // didn't understand "Mapping=tex-text", while XeTeX
2932 // understood both. With most recent versions, both
2933 // variants are understood by both engines. However,
2934 // we want to provide support for at least TeXLive 2009
2935 // (for XeTeX; LuaTeX is only supported as of v.2)
2936 string const texmapping =
2937 (features.runparams().flavor == OutputParams::XETEX) ?
2938 "Mapping=tex-text" : "Ligatures=TeX";
2939 if (fonts_roman != "default") {
2940 os << "\\setmainfont[" << texmapping;
2941 if (fonts_old_figures)
2942 os << ",Numbers=OldStyle";
2943 os << "]{" << parseFontName(fonts_roman) << "}\n";
2945 if (fonts_sans != "default") {
2946 string const sans = parseFontName(fonts_sans);
2947 if (fonts_sans_scale != 100)
2948 os << "\\setsansfont[Scale="
2949 << float(fonts_sans_scale) / 100
2950 << "," << texmapping << "]{"
2953 os << "\\setsansfont[" << texmapping << "]{"
2956 if (fonts_typewriter != "default") {
2957 string const mono = parseFontName(fonts_typewriter);
2958 if (fonts_typewriter_scale != 100)
2959 os << "\\setmonofont[Scale="
2960 << float(fonts_typewriter_scale) / 100
2964 os << "\\setmonofont{"
2971 bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
2972 bool const dryrun = features.runparams().dryrun;
2973 bool const complete = (fonts_sans == "default" && fonts_typewriter == "default");
2974 bool const nomath = (fonts_math == "default");
2977 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_roman)).getLaTeXCode(
2978 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2982 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_sans)).getLaTeXCode(
2983 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2984 nomath, fonts_sans_scale);
2986 // MONOSPACED/TYPEWRITER
2987 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_typewriter)).getLaTeXCode(
2988 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
2989 nomath, fonts_typewriter_scale);
2992 os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getLaTeXCode(
2993 dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures,
3000 Encoding const & BufferParams::encoding() const
3002 // FIXME: actually, we should check for the flavor
3003 // or runparams.isFullyUnicode() here:
3004 // This check will not work with XeTeX/LuaTeX and tex fonts.
3005 // Thus we have to reset the encoding in Buffer::makeLaTeXFile
3006 // (for export) and Buffer::writeLaTeXSource (for preview).
3008 return *(encodings.fromLyXName("utf8-plain"));
3009 if (inputenc == "auto" || inputenc == "default")
3010 return *language->encoding();
3011 Encoding const * const enc = encodings.fromLyXName(inputenc);
3014 LYXERR0("Unknown inputenc value `" << inputenc
3015 << "'. Using `auto' instead.");
3016 return *language->encoding();
3020 bool BufferParams::addCiteEngine(string const & engine)
3022 LayoutModuleList::const_iterator it = cite_engine_.begin();
3023 LayoutModuleList::const_iterator en = cite_engine_.end();
3024 for (; it != en; ++it)
3027 cite_engine_.push_back(engine);
3032 bool BufferParams::addCiteEngine(vector<string> const & engine)
3034 vector<string>::const_iterator it = engine.begin();
3035 vector<string>::const_iterator en = engine.end();
3037 for (; it != en; ++it)
3038 if (!addCiteEngine(*it))
3044 string const & BufferParams::defaultBiblioStyle() const
3046 return documentClass().defaultBiblioStyle();
3050 bool const & BufferParams::fullAuthorList() const
3052 return documentClass().fullAuthorList();
3056 void BufferParams::setCiteEngine(string const & engine)
3059 addCiteEngine(engine);
3063 void BufferParams::setCiteEngine(vector<string> const & engine)
3066 addCiteEngine(engine);
3070 vector<string> BufferParams::citeCommands() const
3072 static CitationStyle const default_style;
3073 vector<string> commands =
3074 documentClass().citeCommands(citeEngineType());
3075 if (commands.empty())
3076 commands.push_back(default_style.cmd);
3081 vector<CitationStyle> BufferParams::citeStyles() const
3083 static CitationStyle const default_style;
3084 vector<CitationStyle> styles =
3085 documentClass().citeStyles(citeEngineType());
3087 styles.push_back(default_style);