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 "ModuleList.h"
37 #include "OutputParams.h"
41 #include "PDFOptions.h"
43 #include "frontends/alert.h"
45 #include "insets/InsetListingsParams.h"
47 #include "support/convert.h"
48 #include "support/debug.h"
49 #include "support/docstream.h"
50 #include "support/FileName.h"
51 #include "support/filetools.h"
52 #include "support/gettext.h"
53 #include "support/Messages.h"
54 #include "support/Translator.h"
55 #include "support/lstrings.h"
61 using namespace lyx::support;
64 static char const * const string_paragraph_separation[] = {
69 static char const * const string_quotes_language[] = {
70 "english", "swedish", "german", "polish", "french", "danish", ""
74 static char const * const string_papersize[] = {
75 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
76 "a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
77 "a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
78 "b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
79 "c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
84 static char const * const string_orientation[] = {
85 "portrait", "landscape", ""
89 static char const * const string_footnotekinds[] = {
90 "footnote", "margin", "fig", "tab", "alg", "wide-fig", "wide-tab", ""
94 static char const * const tex_graphics[] = {
95 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
96 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
97 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
98 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
109 // Paragraph separation
110 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
113 ParSepTranslator const init_parseptranslator()
115 ParSepTranslator translator
116 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
117 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
122 ParSepTranslator const & parseptranslator()
124 static ParSepTranslator translator = 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 translator = init_quoteslangtranslator();
154 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
157 static PaperSizeTranslator initPaperSizeTranslator()
159 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
160 translator.addPair(string_papersize[1], PAPER_CUSTOM);
161 translator.addPair(string_papersize[2], PAPER_USLETTER);
162 translator.addPair(string_papersize[3], PAPER_USLEGAL);
163 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
164 translator.addPair(string_papersize[5], PAPER_A0);
165 translator.addPair(string_papersize[6], PAPER_A1);
166 translator.addPair(string_papersize[7], PAPER_A2);
167 translator.addPair(string_papersize[8], PAPER_A3);
168 translator.addPair(string_papersize[9], PAPER_A4);
169 translator.addPair(string_papersize[10], PAPER_A5);
170 translator.addPair(string_papersize[11], PAPER_A6);
171 translator.addPair(string_papersize[12], PAPER_B0);
172 translator.addPair(string_papersize[13], PAPER_B1);
173 translator.addPair(string_papersize[14], PAPER_B2);
174 translator.addPair(string_papersize[15], PAPER_B3);
175 translator.addPair(string_papersize[16], PAPER_B4);
176 translator.addPair(string_papersize[17], PAPER_B5);
177 translator.addPair(string_papersize[18], PAPER_B6);
178 translator.addPair(string_papersize[19], PAPER_C0);
179 translator.addPair(string_papersize[20], PAPER_C1);
180 translator.addPair(string_papersize[21], PAPER_C2);
181 translator.addPair(string_papersize[22], PAPER_C3);
182 translator.addPair(string_papersize[23], PAPER_C4);
183 translator.addPair(string_papersize[24], PAPER_C5);
184 translator.addPair(string_papersize[25], PAPER_C6);
185 translator.addPair(string_papersize[26], PAPER_JISB0);
186 translator.addPair(string_papersize[27], PAPER_JISB1);
187 translator.addPair(string_papersize[28], PAPER_JISB2);
188 translator.addPair(string_papersize[29], PAPER_JISB3);
189 translator.addPair(string_papersize[30], PAPER_JISB4);
190 translator.addPair(string_papersize[31], PAPER_JISB5);
191 translator.addPair(string_papersize[32], PAPER_JISB6);
196 PaperSizeTranslator const & papersizetranslator()
198 static PaperSizeTranslator translator = 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 translator = init_paperorientationtranslator();
223 typedef Translator<int, PageSides> SidesTranslator;
226 SidesTranslator const init_sidestranslator()
228 SidesTranslator translator(1, OneSide);
229 translator.addPair(2, TwoSides);
234 SidesTranslator const & sidestranslator()
236 static SidesTranslator translator = init_sidestranslator();
242 typedef Translator<int, BufferParams::Package> PackageTranslator;
245 PackageTranslator const init_packagetranslator()
247 PackageTranslator translator(0, BufferParams::package_off);
248 translator.addPair(1, BufferParams::package_auto);
249 translator.addPair(2, BufferParams::package_on);
254 PackageTranslator const & packagetranslator()
256 static PackageTranslator translator = init_packagetranslator();
262 typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
265 CiteEngineTypeTranslator const init_citeenginetypetranslator()
267 CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
268 translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
273 CiteEngineTypeTranslator const & citeenginetypetranslator()
275 static CiteEngineTypeTranslator translator = init_citeenginetypetranslator();
281 typedef Translator<string, Spacing::Space> SpaceTranslator;
284 SpaceTranslator const init_spacetranslator()
286 SpaceTranslator translator("default", Spacing::Default);
287 translator.addPair("single", Spacing::Single);
288 translator.addPair("onehalf", Spacing::Onehalf);
289 translator.addPair("double", Spacing::Double);
290 translator.addPair("other", Spacing::Other);
295 SpaceTranslator const & spacetranslator()
297 static SpaceTranslator translator = init_spacetranslator();
304 class BufferParams::Impl
309 AuthorList authorlist;
310 BranchList branchlist;
311 Bullet temp_bullets[4];
312 Bullet user_defined_bullets[4];
313 IndicesList indiceslist;
315 /** This is the amount of space used for paragraph_separation "skip",
316 * and for detached paragraphs in "indented" documents.
320 PDFOptions pdfoptions;
321 LayoutFileIndex baseClass_;
325 BufferParams::Impl::Impl()
326 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
328 // set initial author
330 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
335 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
339 return new BufferParams::Impl(*ptr);
343 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
349 BufferParams::BufferParams()
352 setBaseClass(defaultBaseclass());
354 paragraph_separation = ParagraphIndentSeparation;
355 quotes_language = InsetQuotes::EnglishQuotes;
356 fontsize = "default";
359 papersize = PAPER_DEFAULT;
360 orientation = ORIENTATION_PORTRAIT;
361 use_geometry = false;
362 cite_engine_.push_back("basic");
363 cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
364 biblio_style = "plain";
365 use_bibtopic = false;
367 trackChanges = false;
368 outputChanges = false;
369 use_default_options = true;
370 maintain_unincluded_children = false;
373 language = default_language;
375 fonts_roman = "default";
376 fonts_sans = "default";
377 fonts_typewriter = "default";
378 fonts_default_family = "default";
379 useNonTeXFonts = false;
380 fonts_expert_sc = false;
381 fonts_old_figures = false;
382 fonts_sans_scale = 100;
383 fonts_typewriter_scale = 100;
385 lang_package = "default";
386 graphics_driver = "default";
387 default_output_format = "default";
388 bibtex_command = "default";
389 index_command = "default";
392 listings_params = string();
393 pagestyle = "default";
394 suppress_date = false;
395 justification = true;
396 // no color is the default (white)
397 backgroundcolor = lyx::rgbFromHexName("#ffffff");
398 isbackgroundcolor = false;
399 // no color is the default (black)
400 fontcolor = lyx::rgbFromHexName("#000000");
402 // light gray is the default font color for greyed-out notes
403 notefontcolor = lyx::rgbFromHexName("#cccccc");
404 boxbgcolor = lyx::rgbFromHexName("#ff0000");
405 compressed = lyxrc.save_compressed;
406 for (int iter = 0; iter < 4; ++iter) {
407 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
408 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
411 indiceslist().addDefault(B_("Index"));
412 html_be_strict = false;
413 html_math_output = MathML;
414 html_math_img_scale = 1.0;
415 html_css_as_file = false;
422 docstring BufferParams::B_(string const & l10n) const
424 LASSERT(language, /**/);
425 return getMessages(language->code()).get(l10n);
429 BufferParams::Package BufferParams::use_package(std::string const & p) const
431 PackageMap::const_iterator it = use_packages.find(p);
432 if (it == use_packages.end())
438 void BufferParams::use_package(std::string const & p, BufferParams::Package u)
444 vector<string> const & BufferParams::auto_packages()
446 static vector<string> packages;
447 if (packages.empty()) {
448 // adding a package here implies a file format change!
449 packages.push_back("amsmath");
450 packages.push_back("amssymb");
451 packages.push_back("esint");
452 packages.push_back("mathdots");
453 packages.push_back("mathtools");
454 packages.push_back("mhchem");
455 packages.push_back("undertilde");
461 AuthorList & BufferParams::authors()
463 return pimpl_->authorlist;
467 AuthorList const & BufferParams::authors() const
469 return pimpl_->authorlist;
473 BranchList & BufferParams::branchlist()
475 return pimpl_->branchlist;
479 BranchList const & BufferParams::branchlist() const
481 return pimpl_->branchlist;
485 IndicesList & BufferParams::indiceslist()
487 return pimpl_->indiceslist;
491 IndicesList const & BufferParams::indiceslist() const
493 return pimpl_->indiceslist;
497 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
499 LASSERT(index < 4, /**/);
500 return pimpl_->temp_bullets[index];
504 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
506 LASSERT(index < 4, /**/);
507 return pimpl_->temp_bullets[index];
511 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
513 LASSERT(index < 4, /**/);
514 return pimpl_->user_defined_bullets[index];
518 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
520 LASSERT(index < 4, /**/);
521 return pimpl_->user_defined_bullets[index];
525 Spacing & BufferParams::spacing()
527 return pimpl_->spacing;
531 Spacing const & BufferParams::spacing() const
533 return pimpl_->spacing;
537 PDFOptions & BufferParams::pdfoptions()
539 return pimpl_->pdfoptions;
543 PDFOptions const & BufferParams::pdfoptions() const
545 return pimpl_->pdfoptions;
549 HSpace const & BufferParams::getIndentation() const
551 return pimpl_->indentation;
555 void BufferParams::setIndentation(HSpace const & indent)
557 pimpl_->indentation = indent;
561 VSpace const & BufferParams::getDefSkip() const
563 return pimpl_->defskip;
567 void BufferParams::setDefSkip(VSpace const & vs)
569 // DEFSKIP will cause an infinite loop
570 LASSERT(vs.kind() != VSpace::DEFSKIP, return);
571 pimpl_->defskip = vs;
575 string BufferParams::readToken(Lexer & lex, string const & token,
576 FileName const & filepath)
578 if (token == "\\textclass") {
580 string const classname = lex.getString();
581 // if there exists a local layout file, ignore the system one
582 // NOTE: in this case, the textclass (.cls file) is assumed to
585 LayoutFileList & bcl = LayoutFileList::get();
586 if (tcp.empty() && !filepath.empty())
587 tcp = bcl.addLocalLayout(classname, filepath.absFileName());
591 setBaseClass(classname);
592 // We assume that a tex class exists for local or unknown
593 // layouts so this warning, will only be given for system layouts.
594 if (!baseClass()->isTeXClassAvailable()) {
595 docstring const desc =
596 translateIfPossible(from_utf8(baseClass()->description()));
597 docstring const prereqs =
598 from_utf8(baseClass()->prerequisites());
599 docstring const msg =
600 bformat(_("The selected document class\n"
602 "requires external files that are not available.\n"
603 "The document class can still be used, but the\n"
604 "document cannot be compiled until the following\n"
605 "prerequisites are installed:\n"
607 "See section 3.1.2.2 (Class Availability) of the\n"
608 "User's Guide for more information."), desc, prereqs);
609 frontend::Alert::warning(_("Document class not available"),
612 } else if (token == "\\begin_preamble") {
614 } else if (token == "\\begin_local_layout") {
615 readLocalLayout(lex);
616 } else if (token == "\\begin_modules") {
618 } else if (token == "\\begin_removed_modules") {
619 readRemovedModules(lex);
620 } else if (token == "\\begin_includeonly") {
621 readIncludeonly(lex);
622 } else if (token == "\\maintain_unincluded_children") {
623 lex >> maintain_unincluded_children;
624 } else if (token == "\\options") {
626 options = lex.getString();
627 } else if (token == "\\use_default_options") {
628 lex >> use_default_options;
629 } else if (token == "\\master") {
631 master = lex.getString();
632 } else if (token == "\\suppress_date") {
633 lex >> suppress_date;
634 } else if (token == "\\justification") {
635 lex >> justification;
636 } else if (token == "\\language") {
638 } else if (token == "\\language_package") {
640 lang_package = lex.getString();
641 } else if (token == "\\inputencoding") {
643 } else if (token == "\\graphics") {
644 readGraphicsDriver(lex);
645 } else if (token == "\\default_output_format") {
646 lex >> default_output_format;
647 } else if (token == "\\bibtex_command") {
649 bibtex_command = lex.getString();
650 } else if (token == "\\index_command") {
652 index_command = lex.getString();
653 } else if (token == "\\fontencoding") {
655 fontenc = lex.getString();
656 } else if (token == "\\font_roman") {
658 fonts_roman = lex.getString();
659 } else if (token == "\\font_sans") {
661 fonts_sans = lex.getString();
662 } else if (token == "\\font_typewriter") {
664 fonts_typewriter = lex.getString();
665 } else if (token == "\\font_default_family") {
666 lex >> fonts_default_family;
667 } else if (token == "\\use_non_tex_fonts") {
668 lex >> useNonTeXFonts;
669 } else if (token == "\\font_sc") {
670 lex >> fonts_expert_sc;
671 } else if (token == "\\font_osf") {
672 lex >> fonts_old_figures;
673 } else if (token == "\\font_sf_scale") {
674 lex >> fonts_sans_scale;
675 } else if (token == "\\font_tt_scale") {
676 lex >> fonts_typewriter_scale;
677 } else if (token == "\\font_cjk") {
679 } else if (token == "\\paragraph_separation") {
682 paragraph_separation = parseptranslator().find(parsep);
683 } else if (token == "\\paragraph_indentation") {
685 string indentation = lex.getString();
686 pimpl_->indentation = HSpace(indentation);
687 } else if (token == "\\defskip") {
689 string const defskip = lex.getString();
690 pimpl_->defskip = VSpace(defskip);
691 if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
693 pimpl_->defskip = VSpace(VSpace::MEDSKIP);
694 } else if (token == "\\quotes_language") {
697 quotes_language = quoteslangtranslator().find(quotes_lang);
698 } else if (token == "\\papersize") {
701 papersize = papersizetranslator().find(ppsize);
702 } else if (token == "\\use_geometry") {
704 } else if (token == "\\use_package") {
709 use_package(package, packagetranslator().find(use));
710 } else if (token == "\\cite_engine") {
712 vector<string> engine = getVectorFromString(lex.getString());
713 setCiteEngine(engine);
714 } else if (token == "\\cite_engine_type") {
717 cite_engine_type_ = citeenginetypetranslator().find(engine_type);
718 } else if (token == "\\biblio_style") {
720 biblio_style = lex.getString();
721 } else if (token == "\\use_bibtopic") {
723 } else if (token == "\\use_indices") {
725 } else if (token == "\\tracking_changes") {
727 } else if (token == "\\output_changes") {
728 lex >> outputChanges;
729 } else if (token == "\\branch") {
731 docstring branch = lex.getDocString();
732 branchlist().add(branch);
735 string const tok = lex.getString();
736 if (tok == "\\end_branch")
738 Branch * branch_ptr = branchlist().find(branch);
739 if (tok == "\\selected") {
742 branch_ptr->setSelected(lex.getInteger());
744 if (tok == "\\filename_suffix") {
747 branch_ptr->setFileNameSuffix(lex.getInteger());
749 if (tok == "\\color") {
751 string color = lex.getString();
753 branch_ptr->setColor(color);
754 // Update also the Color table:
756 color = lcolor.getX11Name(Color_background);
758 lcolor.setColor(to_utf8(branch), color);
761 } else if (token == "\\index") {
763 docstring index = lex.getDocString();
765 indiceslist().add(index);
768 string const tok = lex.getString();
769 if (tok == "\\end_index")
771 Index * index_ptr = indiceslist().find(index);
772 if (tok == "\\shortcut") {
774 shortcut = lex.getDocString();
776 index_ptr->setShortcut(shortcut);
778 if (tok == "\\color") {
780 string color = lex.getString();
782 index_ptr->setColor(color);
783 // Update also the Color table:
785 color = lcolor.getX11Name(Color_background);
787 if (!shortcut.empty())
788 lcolor.setColor(to_utf8(shortcut), color);
791 } else if (token == "\\author") {
793 istringstream ss(lex.getString());
796 author_map[a.bufferId()] = pimpl_->authorlist.record(a);
797 } else if (token == "\\paperorientation") {
800 orientation = paperorientationtranslator().find(orient);
801 } else if (token == "\\backgroundcolor") {
803 backgroundcolor = lyx::rgbFromHexName(lex.getString());
804 isbackgroundcolor = true;
805 } else if (token == "\\fontcolor") {
807 fontcolor = lyx::rgbFromHexName(lex.getString());
809 } else if (token == "\\notefontcolor") {
811 string color = lex.getString();
812 notefontcolor = lyx::rgbFromHexName(color);
813 } else if (token == "\\boxbgcolor") {
815 string color = lex.getString();
816 boxbgcolor = lyx::rgbFromHexName(color);
817 } else if (token == "\\paperwidth") {
819 } else if (token == "\\paperheight") {
821 } else if (token == "\\leftmargin") {
823 } else if (token == "\\topmargin") {
825 } else if (token == "\\rightmargin") {
827 } else if (token == "\\bottommargin") {
829 } else if (token == "\\headheight") {
831 } else if (token == "\\headsep") {
833 } else if (token == "\\footskip") {
835 } else if (token == "\\columnsep") {
837 } else if (token == "\\paperfontsize") {
839 } else if (token == "\\papercolumns") {
841 } else if (token == "\\listings_params") {
844 listings_params = InsetListingsParams(par).params();
845 } else if (token == "\\papersides") {
848 sides = sidestranslator().find(psides);
849 } else if (token == "\\paperpagestyle") {
851 } else if (token == "\\bullet") {
853 } else if (token == "\\bulletLaTeX") {
854 readBulletsLaTeX(lex);
855 } else if (token == "\\secnumdepth") {
857 } else if (token == "\\tocdepth") {
859 } else if (token == "\\spacing") {
863 if (nspacing == "other") {
866 spacing().set(spacetranslator().find(nspacing), tmp_val);
867 } else if (token == "\\float_placement") {
868 lex >> float_placement;
870 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
871 string toktmp = pdfoptions().readToken(lex, token);
872 if (!toktmp.empty()) {
873 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
877 } else if (token == "\\html_math_output") {
880 html_math_output = static_cast<MathOutput>(temp);
881 } else if (token == "\\html_be_strict") {
882 lex >> html_be_strict;
883 } else if (token == "\\html_css_as_file") {
884 lex >> html_css_as_file;
885 } else if (token == "\\html_math_img_scale") {
886 lex >> html_math_img_scale;
887 } else if (token == "\\html_latex_start") {
889 html_latex_start = lex.getString();
890 } else if (token == "\\html_latex_end") {
892 html_latex_end = lex.getString();
893 } else if (token == "\\output_sync") {
895 } else if (token == "\\output_sync_macro") {
896 lex >> output_sync_macro;
897 } else if (token == "\\use_refstyle") {
900 lyxerr << "BufferParams::readToken(): Unknown token: " <<
909 void BufferParams::writeFile(ostream & os) const
911 // The top of the file is written by the buffer.
912 // Prints out the buffer info into the .lyx file given by file
915 os << "\\textclass " << baseClass()->name() << '\n';
918 if (!preamble.empty()) {
919 // remove '\n' from the end of preamble
920 string const tmppreamble = rtrim(preamble, "\n");
921 os << "\\begin_preamble\n"
923 << "\n\\end_preamble\n";
927 if (!options.empty()) {
928 os << "\\options " << options << '\n';
931 // use the class options defined in the layout?
932 os << "\\use_default_options "
933 << convert<string>(use_default_options) << "\n";
935 // the master document
936 if (!master.empty()) {
937 os << "\\master " << master << '\n';
941 if (!removed_modules_.empty()) {
942 os << "\\begin_removed_modules" << '\n';
943 list<string>::const_iterator it = removed_modules_.begin();
944 list<string>::const_iterator en = removed_modules_.end();
945 for (; it != en; ++it)
947 os << "\\end_removed_modules" << '\n';
951 if (!layout_modules_.empty()) {
952 os << "\\begin_modules" << '\n';
953 LayoutModuleList::const_iterator it = layout_modules_.begin();
954 LayoutModuleList::const_iterator en = layout_modules_.end();
955 for (; it != en; ++it)
957 os << "\\end_modules" << '\n';
961 if (!included_children_.empty()) {
962 os << "\\begin_includeonly" << '\n';
963 list<string>::const_iterator it = included_children_.begin();
964 list<string>::const_iterator en = included_children_.end();
965 for (; it != en; ++it)
967 os << "\\end_includeonly" << '\n';
969 os << "\\maintain_unincluded_children "
970 << convert<string>(maintain_unincluded_children) << '\n';
972 // local layout information
973 if (!local_layout.empty()) {
974 // remove '\n' from the end
975 string const tmplocal = rtrim(local_layout, "\n");
976 os << "\\begin_local_layout\n"
978 << "\n\\end_local_layout\n";
981 // then the text parameters
982 if (language != ignore_language)
983 os << "\\language " << language->lang() << '\n';
984 os << "\\language_package " << lang_package
985 << "\n\\inputencoding " << inputenc
986 << "\n\\fontencoding " << fontenc
987 << "\n\\font_roman " << fonts_roman
988 << "\n\\font_sans " << fonts_sans
989 << "\n\\font_typewriter " << fonts_typewriter
990 << "\n\\font_default_family " << fonts_default_family
991 << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts)
992 << "\n\\font_sc " << convert<string>(fonts_expert_sc)
993 << "\n\\font_osf " << convert<string>(fonts_old_figures)
994 << "\n\\font_sf_scale " << fonts_sans_scale
995 << "\n\\font_tt_scale " << fonts_typewriter_scale
997 if (!fonts_cjk.empty()) {
998 os << "\\font_cjk " << fonts_cjk << '\n';
1000 os << "\n\\graphics " << graphics_driver << '\n';
1001 os << "\\default_output_format " << default_output_format << '\n';
1002 os << "\\output_sync " << output_sync << '\n';
1003 if (!output_sync_macro.empty())
1004 os << "\\output_sync_macro \"" << output_sync_macro << "\"\n";
1005 os << "\\bibtex_command " << bibtex_command << '\n';
1006 os << "\\index_command " << index_command << '\n';
1008 if (!float_placement.empty()) {
1009 os << "\\float_placement " << float_placement << '\n';
1011 os << "\\paperfontsize " << fontsize << '\n';
1013 spacing().writeFile(os);
1014 pdfoptions().writeFile(os);
1016 os << "\\papersize " << string_papersize[papersize]
1017 << "\n\\use_geometry " << convert<string>(use_geometry);
1018 vector<string> const & packages = auto_packages();
1019 for (size_t i = 0; i < packages.size(); ++i)
1020 os << "\n\\use_package " << packages[i] << ' '
1021 << use_package(packages[i]);
1023 os << "\n\\cite_engine ";
1025 if (!cite_engine_.empty()) {
1026 LayoutModuleList::const_iterator be = cite_engine_.begin();
1027 LayoutModuleList::const_iterator en = cite_engine_.end();
1028 for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
1037 os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
1038 << "\n\\biblio_style " << biblio_style
1039 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
1040 << "\n\\use_indices " << convert<string>(use_indices)
1041 << "\n\\paperorientation " << string_orientation[orientation]
1042 << "\n\\suppress_date " << convert<string>(suppress_date)
1043 << "\n\\justification " << convert<string>(justification)
1044 << "\n\\use_refstyle " << use_refstyle
1046 if (isbackgroundcolor == true)
1047 os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
1048 if (isfontcolor == true)
1049 os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n';
1050 if (notefontcolor != lyx::rgbFromHexName("#cccccc"))
1051 os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n';
1052 if (boxbgcolor != lyx::rgbFromHexName("#ff0000"))
1053 os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n';
1055 BranchList::const_iterator it = branchlist().begin();
1056 BranchList::const_iterator end = branchlist().end();
1057 for (; it != end; ++it) {
1058 os << "\\branch " << to_utf8(it->branch())
1059 << "\n\\selected " << it->isSelected()
1060 << "\n\\filename_suffix " << it->hasFileNameSuffix()
1061 << "\n\\color " << lyx::X11hexname(it->color())
1066 IndicesList::const_iterator iit = indiceslist().begin();
1067 IndicesList::const_iterator iend = indiceslist().end();
1068 for (; iit != iend; ++iit) {
1069 os << "\\index " << to_utf8(iit->index())
1070 << "\n\\shortcut " << to_utf8(iit->shortcut())
1071 << "\n\\color " << lyx::X11hexname(iit->color())
1076 if (!paperwidth.empty())
1077 os << "\\paperwidth "
1078 << VSpace(paperwidth).asLyXCommand() << '\n';
1079 if (!paperheight.empty())
1080 os << "\\paperheight "
1081 << VSpace(paperheight).asLyXCommand() << '\n';
1082 if (!leftmargin.empty())
1083 os << "\\leftmargin "
1084 << VSpace(leftmargin).asLyXCommand() << '\n';
1085 if (!topmargin.empty())
1086 os << "\\topmargin "
1087 << VSpace(topmargin).asLyXCommand() << '\n';
1088 if (!rightmargin.empty())
1089 os << "\\rightmargin "
1090 << VSpace(rightmargin).asLyXCommand() << '\n';
1091 if (!bottommargin.empty())
1092 os << "\\bottommargin "
1093 << VSpace(bottommargin).asLyXCommand() << '\n';
1094 if (!headheight.empty())
1095 os << "\\headheight "
1096 << VSpace(headheight).asLyXCommand() << '\n';
1097 if (!headsep.empty())
1099 << VSpace(headsep).asLyXCommand() << '\n';
1100 if (!footskip.empty())
1102 << VSpace(footskip).asLyXCommand() << '\n';
1103 if (!columnsep.empty())
1104 os << "\\columnsep "
1105 << VSpace(columnsep).asLyXCommand() << '\n';
1106 os << "\\secnumdepth " << secnumdepth
1107 << "\n\\tocdepth " << tocdepth
1108 << "\n\\paragraph_separation "
1109 << string_paragraph_separation[paragraph_separation];
1110 if (!paragraph_separation)
1111 os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
1113 os << "\n\\defskip " << getDefSkip().asLyXCommand();
1114 os << "\n\\quotes_language "
1115 << string_quotes_language[quotes_language]
1116 << "\n\\papercolumns " << columns
1117 << "\n\\papersides " << sides
1118 << "\n\\paperpagestyle " << pagestyle << '\n';
1119 if (!listings_params.empty())
1120 os << "\\listings_params \"" <<
1121 InsetListingsParams(listings_params).encodedString() << "\"\n";
1122 for (int i = 0; i < 4; ++i) {
1123 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1124 if (user_defined_bullet(i).getFont() != -1) {
1125 os << "\\bullet " << i << " "
1126 << user_defined_bullet(i).getFont() << " "
1127 << user_defined_bullet(i).getCharacter() << " "
1128 << user_defined_bullet(i).getSize() << "\n";
1132 os << "\\bulletLaTeX " << i << " \""
1133 << lyx::to_ascii(user_defined_bullet(i).getText())
1139 os << "\\tracking_changes " << convert<string>(trackChanges) << '\n'
1140 << "\\output_changes " << convert<string>(outputChanges) << '\n'
1141 << "\\html_math_output " << html_math_output << '\n'
1142 << "\\html_css_as_file " << html_css_as_file << '\n'
1143 << "\\html_be_strict " << convert<string>(html_be_strict) << '\n';
1145 if (html_math_img_scale != 1.0)
1146 os << "\\html_math_img_scale " << convert<string>(html_math_img_scale) << '\n';
1147 if (!html_latex_start.empty())
1148 os << "\\html_latex_start " << html_latex_start << '\n';
1149 if (!html_latex_end.empty())
1150 os << "\\html_latex_end " << html_latex_end << '\n';
1152 os << pimpl_->authorlist;
1156 void BufferParams::validate(LaTeXFeatures & features) const
1158 features.require(documentClass().requires());
1160 if (outputChanges) {
1161 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
1162 bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
1163 LaTeXFeatures::isAvailable("xcolor");
1165 switch (features.runparams().flavor) {
1166 case OutputParams::LATEX:
1167 case OutputParams::DVILUATEX:
1169 features.require("ct-dvipost");
1170 features.require("dvipost");
1171 } else if (xcolorulem) {
1172 features.require("ct-xcolor-ulem");
1173 features.require("ulem");
1174 features.require("xcolor");
1176 features.require("ct-none");
1179 case OutputParams::LUATEX:
1180 case OutputParams::PDFLATEX:
1181 case OutputParams::XETEX:
1183 features.require("ct-xcolor-ulem");
1184 features.require("ulem");
1185 features.require("xcolor");
1186 // improves color handling in PDF output
1187 features.require("pdfcolmk");
1189 features.require("ct-none");
1197 // Floats with 'Here definitely' as default setting.
1198 if (float_placement.find('H') != string::npos)
1199 features.require("float");
1201 for (PackageMap::const_iterator it = use_packages.begin();
1202 it != use_packages.end(); ++it) {
1203 if (it->first == "amsmath") {
1204 // AMS Style is at document level
1205 if (it->second == package_on ||
1206 documentClass().provides("amsmath"))
1207 features.require(it->first);
1208 } else if (it->second == package_on)
1209 features.require(it->first);
1212 // Document-level line spacing
1213 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
1214 features.require("setspace");
1216 // the bullet shapes are buffer level not paragraph level
1217 // so they are tested here
1218 for (int i = 0; i < 4; ++i) {
1219 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
1221 int const font = user_defined_bullet(i).getFont();
1223 int const c = user_defined_bullet(i).getCharacter();
1229 features.require("latexsym");
1231 } else if (font == 1) {
1232 features.require("amssymb");
1233 } else if (font >= 2 && font <= 5) {
1234 features.require("pifont");
1238 if (pdfoptions().use_hyperref) {
1239 features.require("hyperref");
1240 // due to interferences with babel and hyperref, the color package has to
1241 // be loaded after hyperref when hyperref is used with the colorlinks
1242 // option, see http://www.lyx.org/trac/ticket/5291
1243 if (pdfoptions().colorlinks)
1244 features.require("color");
1247 // some languages are only available via polyglossia
1248 if ( (features.runparams().flavor == OutputParams::XETEX
1249 || language->lang() == "ancientgreek"
1250 || language->lang() == "coptic"
1251 || language->lang() == "divehi"
1252 || language->lang() == "hindi"
1253 || language->lang() == "kurmanji"
1254 || language->lang() == "lao"
1255 || language->lang() == "marathi"
1256 || language->lang() == "occitan"
1257 || language->lang() == "sanskrit"
1258 || language->lang() == "syriac"
1259 || language->lang() == "tamil"
1260 || language->lang() == "telugu"
1261 || language->lang() == "urdu"
1262 ) && useNonTeXFonts)
1263 features.require("polyglossia");
1265 if (language->lang() == "vietnamese")
1266 features.require("vietnamese");
1267 else if (language->lang() == "japanese")
1268 features.require("japanese");
1272 bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
1273 FileName const & filepath) const
1275 // http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
1276 // !! To use the Fix-cm package, load it before \documentclass, and use the command
1277 // \RequirePackage to do so, rather than the normal \usepackage
1278 // Do not try to load any other package before the document class, unless you
1279 // have a thorough understanding of the LATEX internals and know exactly what you
1281 if (features.mustProvide("fix-cm"))
1282 os << "\\RequirePackage{fix-cm}\n";
1284 os << "\\documentclass";
1286 DocumentClass const & tclass = documentClass();
1288 ostringstream clsoptions; // the document class options.
1290 if (tokenPos(tclass.opt_fontsize(),
1291 '|', fontsize) >= 0) {
1292 // only write if existing in list (and not default)
1293 clsoptions << fontsize << "pt,";
1296 // all paper sizes except of A4, A5, B5 and the US sizes need the
1298 bool nonstandard_papersize = papersize != PAPER_DEFAULT
1299 && papersize != PAPER_USLETTER
1300 && papersize != PAPER_USLEGAL
1301 && papersize != PAPER_USEXECUTIVE
1302 && papersize != PAPER_A4
1303 && papersize != PAPER_A5
1304 && papersize != PAPER_B5;
1306 if (!use_geometry) {
1307 switch (papersize) {
1309 clsoptions << "a4paper,";
1311 case PAPER_USLETTER:
1312 clsoptions << "letterpaper,";
1315 clsoptions << "a5paper,";
1318 clsoptions << "b5paper,";
1320 case PAPER_USEXECUTIVE:
1321 clsoptions << "executivepaper,";
1324 clsoptions << "legalpaper,";
1358 if (sides != tclass.sides()) {
1361 clsoptions << "oneside,";
1364 clsoptions << "twoside,";
1370 if (columns != tclass.columns()) {
1372 clsoptions << "twocolumn,";
1374 clsoptions << "onecolumn,";
1378 && orientation == ORIENTATION_LANDSCAPE)
1379 clsoptions << "landscape,";
1381 // language should be a parameter to \documentclass
1382 if (language->babel() == "hebrew"
1383 && default_language->babel() != "hebrew")
1384 // This seems necessary
1385 features.useLanguage(default_language);
1387 ostringstream language_options;
1388 bool const use_babel = features.useBabel() && !tclass.provides("babel");
1389 bool const use_polyglossia = features.usePolyglossia();
1390 bool const global = lyxrc.language_global_options;
1391 if (use_babel || (use_polyglossia && global)) {
1392 language_options << features.getLanguages();
1393 if (!language->babel().empty()) {
1394 if (!language_options.str().empty())
1395 language_options << ',';
1396 language_options << language->babel();
1398 if (global && !features.needBabelLangOptions())
1399 clsoptions << language_options.str() << ',';
1402 // the predefined options from the layout
1403 if (use_default_options && !tclass.options().empty())
1404 clsoptions << tclass.options() << ',';
1406 // the user-defined options
1407 if (!options.empty()) {
1408 clsoptions << options << ',';
1411 string strOptions(clsoptions.str());
1412 if (!strOptions.empty()) {
1413 strOptions = rtrim(strOptions, ",");
1415 os << '[' << from_utf8(strOptions) << ']';
1418 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1419 // end of \documentclass defs
1421 // if we use fontspec, we have to load the AMS packages here
1422 string const ams = features.loadAMSPackages();
1423 if (useNonTeXFonts && !ams.empty())
1424 os << from_ascii(ams);
1427 os << "\\usepackage{fontspec}\n";
1429 // font selection must be done before loading fontenc.sty
1430 string const fonts =
1431 loadFonts(fonts_roman, fonts_sans, fonts_typewriter,
1432 fonts_expert_sc, fonts_old_figures,
1433 fonts_sans_scale, fonts_typewriter_scale,
1434 useNonTeXFonts, features);
1436 os << from_utf8(fonts);
1438 if (fonts_default_family != "default")
1439 os << "\\renewcommand{\\familydefault}{\\"
1440 << from_ascii(fonts_default_family) << "}\n";
1442 // set font encoding
1443 // for arabic_arabi and farsi we also need to load the LAE and
1445 // XeTeX and LuaTeX (with OS fonts) work without fontenc
1446 if (font_encoding() != "default" && language->lang() != "japanese"
1447 && !useNonTeXFonts && !tclass.provides("fontenc")) {
1448 size_t fars = language_options.str().find("farsi");
1449 size_t arab = language_options.str().find("arabic");
1450 if (language->lang() == "arabic_arabi"
1451 || language->lang() == "farsi" || fars != string::npos
1452 || arab != string::npos) {
1453 os << "\\usepackage[" << from_ascii(font_encoding())
1454 << ",LFE,LAE]{fontenc}\n";
1456 os << "\\usepackage[" << from_ascii(font_encoding())
1461 // handle inputenc etc.
1462 writeEncodingPreamble(os, features);
1465 if (!features.runparams().includeall && !included_children_.empty()) {
1466 os << "\\includeonly{";
1467 list<string>::const_iterator it = included_children_.begin();
1468 list<string>::const_iterator en = included_children_.end();
1470 for (; it != en; ++it) {
1471 string incfile = *it;
1472 FileName inc = makeAbsPath(incfile, filepath.absFileName());
1473 string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
1475 if (!features.runparams().nice)
1477 // \includeonly doesn't want an extension
1478 incfile = changeExtension(incfile, string());
1479 incfile = support::latex_path(incfile);
1480 if (!incfile.empty()) {
1483 os << from_utf8(incfile);
1490 if (!listings_params.empty() || features.isRequired("listings"))
1491 os << "\\usepackage{listings}\n";
1493 if (!listings_params.empty()) {
1495 // do not test validity because listings_params is
1496 // supposed to be valid
1498 InsetListingsParams(listings_params).separatedParams(true);
1499 // we can't support all packages, but we should load the color package
1500 if (par.find("\\color", 0) != string::npos)
1501 features.require("color");
1502 os << from_utf8(par)
1505 if (!tclass.provides("geometry")
1506 && (use_geometry || nonstandard_papersize)) {
1507 odocstringstream ods;
1508 if (!getGraphicsDriver("geometry").empty())
1509 ods << getGraphicsDriver("geometry");
1510 if (orientation == ORIENTATION_LANDSCAPE)
1511 ods << ",landscape";
1512 switch (papersize) {
1514 if (!paperwidth.empty())
1515 ods << ",paperwidth="
1516 << from_ascii(paperwidth);
1517 if (!paperheight.empty())
1518 ods << ",paperheight="
1519 << from_ascii(paperheight);
1521 case PAPER_USLETTER:
1522 ods << ",letterpaper";
1525 ods << ",legalpaper";
1527 case PAPER_USEXECUTIVE:
1528 ods << ",executivepaper";
1617 docstring const g_options = trim(ods.str(), ",");
1618 os << "\\usepackage";
1619 if (!g_options.empty())
1620 os << '[' << g_options << ']';
1621 os << "{geometry}\n";
1622 // output this only if use_geometry is true
1624 os << "\\geometry{verbose";
1625 if (!topmargin.empty())
1626 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1627 if (!bottommargin.empty())
1628 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1629 if (!leftmargin.empty())
1630 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1631 if (!rightmargin.empty())
1632 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1633 if (!headheight.empty())
1634 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1635 if (!headsep.empty())
1636 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1637 if (!footskip.empty())
1638 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1639 if (!columnsep.empty())
1640 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1643 } else if (orientation == ORIENTATION_LANDSCAPE
1644 || papersize != PAPER_DEFAULT) {
1645 features.require("papersize");
1648 if (tokenPos(tclass.opt_pagestyle(), '|', pagestyle) >= 0) {
1649 if (pagestyle == "fancy")
1650 os << "\\usepackage{fancyhdr}\n";
1651 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1654 // only output when the background color is not default
1655 if (isbackgroundcolor == true) {
1656 // only require color here, the background color will be defined
1657 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1659 features.require("color");
1660 features.require("pagecolor");
1663 // only output when the font color is not default
1664 if (isfontcolor == true) {
1665 // only require color here, the font color will be defined
1666 // in LaTeXFeatures.cpp to avoid interferences with the LaTeX
1668 features.require("color");
1669 features.require("fontcolor");
1672 // Only if class has a ToC hierarchy
1673 if (tclass.hasTocLevels()) {
1674 if (secnumdepth != tclass.secnumdepth()) {
1675 os << "\\setcounter{secnumdepth}{"
1679 if (tocdepth != tclass.tocdepth()) {
1680 os << "\\setcounter{tocdepth}{"
1686 if (paragraph_separation) {
1687 // when skip separation
1688 switch (getDefSkip().kind()) {
1689 case VSpace::SMALLSKIP:
1690 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1692 case VSpace::MEDSKIP:
1693 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1695 case VSpace::BIGSKIP:
1696 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1698 case VSpace::LENGTH:
1699 os << "\\setlength{\\parskip}{"
1700 << from_utf8(getDefSkip().length().asLatexString())
1703 default: // should never happen // Then delete it.
1704 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1707 os << "\\setlength{\\parindent}{0pt}\n";
1709 // when separation by indentation
1710 // only output something when a width is given
1711 if (getIndentation().asLyXCommand() != "default") {
1712 os << "\\setlength{\\parindent}{"
1713 << from_utf8(getIndentation().asLatexCommand())
1718 // Now insert the LyX specific LaTeX commands...
1719 docstring lyxpreamble;
1720 features.resolveAlternatives();
1723 if (!output_sync_macro.empty())
1724 lyxpreamble += from_utf8(output_sync_macro) +"\n";
1725 else if (features.runparams().flavor == OutputParams::LATEX)
1726 lyxpreamble += "\\usepackage[active]{srcltx}\n";
1727 else if (features.runparams().flavor == OutputParams::PDFLATEX)
1728 lyxpreamble += "\\synctex=-1\n";
1731 // due to interferences with babel and hyperref, the color package has to
1732 // be loaded (when it is not already loaded) before babel when hyperref
1733 // is used with the colorlinks option, see
1734 // http://www.lyx.org/trac/ticket/5291
1735 // we decided therefore to load color always before babel, see
1736 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1737 lyxpreamble += from_ascii(features.getColorOptions());
1739 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1741 && (features.isRequired("jurabib")
1742 || features.isRequired("hyperref")
1743 || features.isRequired("vietnamese")
1744 || features.isRequired("japanese"))) {
1746 lyxpreamble += from_utf8(features.getBabelPresettings());
1747 lyxpreamble += from_utf8(babelCall(language_options.str(),
1748 features.needBabelLangOptions())) + '\n';
1749 lyxpreamble += from_utf8(features.getBabelPostsettings());
1752 // The optional packages;
1753 lyxpreamble += from_ascii(features.getPackages());
1755 // Additional Indices
1756 if (features.isRequired("splitidx")) {
1757 IndicesList::const_iterator iit = indiceslist().begin();
1758 IndicesList::const_iterator iend = indiceslist().end();
1759 for (; iit != iend; ++iit) {
1760 lyxpreamble += "\\newindex[";
1761 lyxpreamble += iit->index();
1762 lyxpreamble += "]{";
1763 lyxpreamble += iit->shortcut();
1764 lyxpreamble += "}\n";
1769 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1772 // * Hyperref manual: "Make sure it comes last of your loaded
1773 // packages, to give it a fighting chance of not being over-written,
1774 // since its job is to redefine many LaTeX commands."
1775 // * Email from Heiko Oberdiek: "It is usually better to load babel
1776 // before hyperref. Then hyperref has a chance to detect babel.
1777 // * Has to be loaded before the "LyX specific LaTeX commands" to
1778 // avoid errors with algorithm floats.
1779 // use hyperref explicitly if it is required
1780 if (features.isRequired("hyperref")) {
1781 // pass what we have to stream here, since we need
1782 // to access the stream itself in PDFOptions.
1785 OutputParams tmp_params = features.runparams();
1786 pdfoptions().writeLaTeX(tmp_params, os,
1787 documentClass().provides("hyperref"));
1788 // set back for the rest
1789 lyxpreamble.clear();
1790 // correctly break URLs with hyperref and dvi output
1791 if (features.runparams().flavor == OutputParams::LATEX
1792 && features.isAvailable("breakurl"))
1793 lyxpreamble += "\\usepackage{breakurl}\n";
1794 } else if (features.isRequired("nameref"))
1795 // hyperref loads this automatically
1796 lyxpreamble += "\\usepackage{nameref}\n";
1798 // bibtopic needs to be loaded after hyperref.
1799 // the dot provides the aux file naming which LyX can detect.
1800 if (features.mustProvide("bibtopic"))
1801 lyxpreamble += "\\usepackage[dot]{bibtopic}\n";
1803 // Will be surrounded by \makeatletter and \makeatother when not empty
1804 docstring atlyxpreamble;
1806 // Some macros LyX will need
1807 docstring tmppreamble(features.getMacros());
1809 if (!tmppreamble.empty())
1810 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1811 "LyX specific LaTeX commands.\n"
1812 + tmppreamble + '\n';
1814 // the text class specific preamble
1815 tmppreamble = features.getTClassPreamble();
1816 if (!tmppreamble.empty())
1817 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1818 "Textclass specific LaTeX commands.\n"
1819 + tmppreamble + '\n';
1821 // suppress date if selected
1822 // use \@ifundefined because we cannot be sure that every document class
1823 // has a \date command
1825 atlyxpreamble += "\\@ifundefined{date}{}{\\date{}}\n";
1827 /* the user-defined preamble */
1828 if (!containsOnly(preamble, " \n\t"))
1830 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1831 "User specified LaTeX commands.\n"
1832 + from_utf8(preamble) + '\n';
1834 // subfig loads internally the LaTeX package "caption". As
1835 // caption is a very popular package, users will load it in
1836 // the preamble. Therefore we must load subfig behind the
1837 // user-defined preamble and check if the caption package was
1838 // loaded or not. For the case that caption is loaded before
1839 // subfig, there is the subfig option "caption=false". This
1840 // option also works when a koma-script class is used and
1841 // koma's own caption commands are used instead of caption. We
1842 // use \PassOptionsToPackage here because the user could have
1843 // already loaded subfig in the preamble.
1844 if (features.isRequired("subfig")) {
1845 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1846 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1847 "\\usepackage{subfig}\n";
1850 // Itemize bullet settings need to be last in case the user
1851 // defines their own bullets that use a package included
1852 // in the user-defined preamble -- ARRae
1853 // Actually it has to be done much later than that
1854 // since some packages like frenchb make modifications
1855 // at \begin{document} time -- JMarc
1856 docstring bullets_def;
1857 for (int i = 0; i < 4; ++i) {
1858 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1859 if (bullets_def.empty())
1860 bullets_def += "\\AtBeginDocument{\n";
1861 bullets_def += " \\def\\labelitemi";
1863 // `i' is one less than the item to modify
1870 bullets_def += "ii";
1876 bullets_def += '{' +
1877 user_defined_bullet(i).getText()
1882 if (!bullets_def.empty())
1883 atlyxpreamble += bullets_def + "}\n\n";
1885 if (!atlyxpreamble.empty())
1886 lyxpreamble += "\n\\makeatletter\n"
1887 + atlyxpreamble + "\\makeatother\n\n";
1889 // We try to load babel late, in case it interferes with other packages.
1890 // Jurabib and Hyperref have to be called after babel, though.
1891 if (use_babel && !features.isRequired("jurabib")
1892 && !features.isRequired("hyperref")
1893 && !features.isRequired("vietnamese")
1894 && !features.isRequired("japanese")) {
1896 lyxpreamble += from_utf8(features.getBabelPresettings());
1897 lyxpreamble += from_utf8(babelCall(language_options.str(),
1898 features.needBabelLangOptions())) + '\n';
1899 lyxpreamble += from_utf8(features.getBabelPostsettings());
1902 // xunicode needs to be loaded at least after amsmath, amssymb,
1903 // esint and the other packages that provide special glyphs
1904 if (features.runparams().flavor == OutputParams::XETEX)
1905 lyxpreamble += "\\usepackage{xunicode}\n";
1907 // Polyglossia must be loaded last
1908 if (use_polyglossia) {
1910 lyxpreamble += "\\usepackage{polyglossia}\n";
1911 // set the main language
1912 lyxpreamble += "\\setdefaultlanguage";
1913 if (!language->polyglossiaOpts().empty())
1914 lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
1915 lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
1916 // now setup the other languages
1917 std::map<std::string, std::string> const polylangs =
1918 features.getPolyglossiaLanguages();
1919 for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
1920 mit != polylangs.end() ; ++mit) {
1921 lyxpreamble += "\\setotherlanguage";
1922 if (!mit->second.empty())
1923 lyxpreamble += "[" + from_ascii(mit->second) + "]";
1924 lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
1928 docstring const i18npreamble =
1929 features.getTClassI18nPreamble(use_babel, use_polyglossia);
1930 if (!i18npreamble.empty())
1931 lyxpreamble += i18npreamble + '\n';
1939 void BufferParams::useClassDefaults()
1941 DocumentClass const & tclass = documentClass();
1943 sides = tclass.sides();
1944 columns = tclass.columns();
1945 pagestyle = tclass.pagestyle();
1946 use_default_options = true;
1947 // Only if class has a ToC hierarchy
1948 if (tclass.hasTocLevels()) {
1949 secnumdepth = tclass.secnumdepth();
1950 tocdepth = tclass.tocdepth();
1955 bool BufferParams::hasClassDefaults() const
1957 DocumentClass const & tclass = documentClass();
1959 return sides == tclass.sides()
1960 && columns == tclass.columns()
1961 && pagestyle == tclass.pagestyle()
1962 && use_default_options
1963 && secnumdepth == tclass.secnumdepth()
1964 && tocdepth == tclass.tocdepth();
1968 DocumentClass const & BufferParams::documentClass() const
1970 return *doc_class_.get();
1974 DocumentClassConstPtr BufferParams::documentClassPtr() const
1980 void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
1982 // evil, but this function is evil
1983 doc_class_ = const_pointer_cast<DocumentClass>(tc);
1987 bool BufferParams::setBaseClass(string const & classname)
1989 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1990 LayoutFileList & bcl = LayoutFileList::get();
1991 if (!bcl.haveClass(classname)) {
1993 bformat(_("The layout file:\n"
1995 "could not be found. A default textclass with default\n"
1996 "layouts will be used. LyX will not be able to produce\n"
1998 from_utf8(classname));
1999 frontend::Alert::error(_("Document class not found"), s);
2000 bcl.addEmptyClass(classname);
2003 bool const success = bcl[classname].load();
2006 bformat(_("Due to some error in it, the layout file:\n"
2008 "could not be loaded. A default textclass with default\n"
2009 "layouts will be used. LyX will not be able to produce\n"
2011 from_utf8(classname));
2012 frontend::Alert::error(_("Could not load class"), s);
2013 bcl.addEmptyClass(classname);
2016 pimpl_->baseClass_ = classname;
2017 layout_modules_.adaptToBaseClass(baseClass(), removed_modules_);
2022 LayoutFile const * BufferParams::baseClass() const
2024 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
2025 return &(LayoutFileList::get()[pimpl_->baseClass_]);
2031 LayoutFileIndex const & BufferParams::baseClassID() const
2033 return pimpl_->baseClass_;
2037 void BufferParams::makeDocumentClass()
2042 LayoutModuleList mods;
2043 LayoutModuleList::iterator it;
2044 LayoutModuleList::iterator en;
2046 it = layout_modules_.begin();
2047 en = layout_modules_.end();
2048 for (; it != en; ++it)
2049 mods.push_back(*it);
2050 it = cite_engine_.begin();
2051 en = cite_engine_.end();
2052 for (; it != en; ++it)
2053 mods.push_back(*it);
2054 doc_class_ = getDocumentClass(*baseClass(), mods);
2056 if (!local_layout.empty()) {
2057 TextClass::ReturnValues success =
2058 doc_class_->read(local_layout, TextClass::MODULE);
2059 if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
2060 docstring const msg = _("Error reading internal layout information");
2061 frontend::Alert::warning(_("Read Error"), msg);
2067 bool BufferParams::moduleCanBeAdded(string const & modName) const
2069 return cite_engine_.moduleCanBeAdded(modName, baseClass()) &&
2070 layout_modules_.moduleCanBeAdded(modName, baseClass());
2074 bool BufferParams::addLayoutModule(string const & modName)
2076 LayoutModuleList::const_iterator it = layout_modules_.begin();
2077 LayoutModuleList::const_iterator end = layout_modules_.end();
2078 for (; it != end; ++it)
2081 layout_modules_.push_back(modName);
2086 string BufferParams::bufferFormat() const
2088 string format = documentClass().outputFormat();
2089 if (format == "latex") {
2092 if (encoding().package() == Encoding::japanese)
2099 bool BufferParams::isExportable(string const & format) const
2101 vector<string> backs = backends();
2102 for (vector<string>::const_iterator it = backs.begin();
2103 it != backs.end(); ++it)
2104 if (theConverters().isReachable(*it, format))
2111 bool formatSorter(Format const * lhs, Format const * rhs) {
2112 return _(lhs->prettyname()) < _(rhs->prettyname());
2117 vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const
2119 vector<string> const backs = backends();
2120 set<string> excludes;
2121 if (useNonTeXFonts) {
2122 excludes.insert("latex");
2123 excludes.insert("pdflatex");
2125 vector<Format const *> result =
2126 theConverters().getReachable(backs[0], only_viewable, true, excludes);
2127 for (vector<string>::const_iterator it = backs.begin() + 1;
2128 it != backs.end(); ++it) {
2129 vector<Format const *> r =
2130 theConverters().getReachable(*it, only_viewable, false, excludes);
2131 result.insert(result.end(), r.begin(), r.end());
2133 sort(result.begin(), result.end(), formatSorter);
2138 bool BufferParams::isExportableFormat(string const & format) const
2140 typedef vector<Format const *> Formats;
2142 formats = exportableFormats(true);
2143 Formats::const_iterator fit = formats.begin();
2144 Formats::const_iterator end = formats.end();
2145 for (; fit != end ; ++fit) {
2146 if ((*fit)->name() == format)
2153 vector<string> BufferParams::backends() const
2156 string const buffmt = bufferFormat();
2158 // FIXME: Don't hardcode format names here, but use a flag
2159 if (buffmt == "latex") {
2160 if (!useNonTeXFonts) {
2161 v.push_back("pdflatex");
2162 v.push_back("latex");
2164 v.push_back("luatex");
2165 v.push_back("dviluatex");
2166 v.push_back("xetex");
2167 } else if (buffmt == "xetex") {
2168 v.push_back("xetex");
2169 v.push_back("luatex");
2170 v.push_back("dviluatex");
2172 v.push_back(buffmt);
2174 v.push_back("xhtml");
2175 v.push_back("text");
2181 OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
2183 string const dformat = (format.empty() || format == "default") ?
2184 getDefaultOutputFormat() : format;
2185 DefaultFlavorCache::const_iterator it =
2186 default_flavors_.find(dformat);
2188 if (it != default_flavors_.end())
2191 OutputParams::FLAVOR result = OutputParams::LATEX;
2193 if (dformat == "xhtml")
2194 result = OutputParams::HTML;
2195 else if (dformat == "text")
2196 result = OutputParams::TEXT;
2197 else if (dformat == "lyx")
2198 result = OutputParams::LYX;
2200 // Try to determine flavor of default output format
2201 vector<string> backs = backends();
2202 if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
2203 // Get shortest path to format
2204 Graph::EdgePath path;
2205 for (vector<string>::const_iterator it = backs.begin();
2206 it != backs.end(); ++it) {
2207 Graph::EdgePath p = theConverters().getPath(*it, dformat);
2208 if (!p.empty() && (path.empty() || p.size() < path.size())) {
2213 result = theConverters().getFlavor(path);
2216 // cache this flavor
2217 default_flavors_[dformat] = result;
2222 string BufferParams::getDefaultOutputFormat() const
2224 if (!default_output_format.empty()
2225 && default_output_format != "default")
2226 return default_output_format;
2229 || encoding().package() == Encoding::japanese) {
2230 vector<Format const *> const formats = exportableFormats(true);
2231 if (formats.empty())
2233 // return the first we find
2234 return formats.front()->name();
2236 return lyxrc.default_view_format;
2239 Font const BufferParams::getFont() const
2241 FontInfo f = documentClass().defaultfont();
2242 if (fonts_default_family == "rmdefault")
2243 f.setFamily(ROMAN_FAMILY);
2244 else if (fonts_default_family == "sfdefault")
2245 f.setFamily(SANS_FAMILY);
2246 else if (fonts_default_family == "ttdefault")
2247 f.setFamily(TYPEWRITER_FAMILY);
2248 return Font(f, language);
2252 bool BufferParams::isLatex() const
2254 return documentClass().outputType() == LATEX;
2258 bool BufferParams::isLiterate() const
2260 return documentClass().outputType() == LITERATE;
2264 bool BufferParams::isDocBook() const
2266 return documentClass().outputType() == DOCBOOK;
2270 void BufferParams::readPreamble(Lexer & lex)
2272 if (lex.getString() != "\\begin_preamble")
2273 lyxerr << "Error (BufferParams::readPreamble):"
2274 "consistency check failed." << endl;
2276 preamble = lex.getLongString("\\end_preamble");
2280 void BufferParams::readLocalLayout(Lexer & lex)
2282 if (lex.getString() != "\\begin_local_layout")
2283 lyxerr << "Error (BufferParams::readLocalLayout):"
2284 "consistency check failed." << endl;
2286 local_layout = lex.getLongString("\\end_local_layout");
2290 bool BufferParams::setLanguage(string const & lang)
2292 Language const *new_language = languages.getLanguage(lang);
2293 if (!new_language) {
2294 // Language lang was not found
2297 language = new_language;
2302 void BufferParams::readLanguage(Lexer & lex)
2304 if (!lex.next()) return;
2306 string const tmptok = lex.getString();
2308 // check if tmptok is part of tex_babel in tex-defs.h
2309 if (!setLanguage(tmptok)) {
2310 // Language tmptok was not found
2311 language = default_language;
2312 lyxerr << "Warning: Setting language `"
2313 << tmptok << "' to `" << language->lang()
2319 void BufferParams::readGraphicsDriver(Lexer & lex)
2324 string const tmptok = lex.getString();
2325 // check if tmptok is part of tex_graphics in tex_defs.h
2328 string const test = tex_graphics[n++];
2330 if (test == tmptok) {
2331 graphics_driver = tmptok;
2336 "Warning: graphics driver `$$Token' not recognized!\n"
2337 " Setting graphics driver to `default'.\n");
2338 graphics_driver = "default";
2345 void BufferParams::readBullets(Lexer & lex)
2350 int const index = lex.getInteger();
2352 int temp_int = lex.getInteger();
2353 user_defined_bullet(index).setFont(temp_int);
2354 temp_bullet(index).setFont(temp_int);
2356 user_defined_bullet(index).setCharacter(temp_int);
2357 temp_bullet(index).setCharacter(temp_int);
2359 user_defined_bullet(index).setSize(temp_int);
2360 temp_bullet(index).setSize(temp_int);
2364 void BufferParams::readBulletsLaTeX(Lexer & lex)
2366 // The bullet class should be able to read this.
2369 int const index = lex.getInteger();
2371 docstring const temp_str = lex.getDocString();
2373 user_defined_bullet(index).setText(temp_str);
2374 temp_bullet(index).setText(temp_str);
2378 void BufferParams::readModules(Lexer & lex)
2380 if (!lex.eatLine()) {
2381 lyxerr << "Error (BufferParams::readModules):"
2382 "Unexpected end of input." << endl;
2386 string mod = lex.getString();
2387 if (mod == "\\end_modules")
2389 addLayoutModule(mod);
2395 void BufferParams::readRemovedModules(Lexer & lex)
2397 if (!lex.eatLine()) {
2398 lyxerr << "Error (BufferParams::readRemovedModules):"
2399 "Unexpected end of input." << endl;
2403 string mod = lex.getString();
2404 if (mod == "\\end_removed_modules")
2406 removed_modules_.push_back(mod);
2409 // now we want to remove any removed modules that were previously
2410 // added. normally, that will be because default modules were added in
2411 // setBaseClass(), which gets called when \textclass is read at the
2412 // start of the read.
2413 list<string>::const_iterator rit = removed_modules_.begin();
2414 list<string>::const_iterator const ren = removed_modules_.end();
2415 for (; rit != ren; ++rit) {
2416 LayoutModuleList::iterator const mit = layout_modules_.begin();
2417 LayoutModuleList::iterator const men = layout_modules_.end();
2418 LayoutModuleList::iterator found = find(mit, men, *rit);
2421 layout_modules_.erase(found);
2426 void BufferParams::readIncludeonly(Lexer & lex)
2428 if (!lex.eatLine()) {
2429 lyxerr << "Error (BufferParams::readIncludeonly):"
2430 "Unexpected end of input." << endl;
2434 string child = lex.getString();
2435 if (child == "\\end_includeonly")
2437 included_children_.push_back(child);
2443 string BufferParams::paperSizeName(PapersizePurpose purpose) const
2445 switch (papersize) {
2447 // could be anything, so don't guess
2449 case PAPER_CUSTOM: {
2450 if (purpose == XDVI && !paperwidth.empty() &&
2451 !paperheight.empty()) {
2452 // heightxwidth<unit>
2453 string first = paperwidth;
2454 string second = paperheight;
2455 if (orientation == ORIENTATION_LANDSCAPE)
2458 return first.erase(first.length() - 2)
2464 // dvips and dvipdfm do not know this
2465 if (purpose == DVIPS || purpose == DVIPDFM)
2469 if (purpose == DVIPS || purpose == DVIPDFM)
2473 if (purpose == DVIPS || purpose == DVIPDFM)
2483 if (purpose == DVIPS || purpose == DVIPDFM)
2487 if (purpose == DVIPS || purpose == DVIPDFM)
2491 if (purpose == DVIPS || purpose == DVIPDFM)
2495 if (purpose == DVIPS || purpose == DVIPDFM)
2499 if (purpose == DVIPS || purpose == DVIPDFM)
2503 // dvipdfm does not know this
2504 if (purpose == DVIPDFM)
2508 if (purpose == DVIPDFM)
2512 if (purpose == DVIPS || purpose == DVIPDFM)
2516 if (purpose == DVIPS || purpose == DVIPDFM)
2520 if (purpose == DVIPS || purpose == DVIPDFM)
2524 if (purpose == DVIPS || purpose == DVIPDFM)
2528 if (purpose == DVIPS || purpose == DVIPDFM)
2532 if (purpose == DVIPS || purpose == DVIPDFM)
2536 if (purpose == DVIPS || purpose == DVIPDFM)
2540 if (purpose == DVIPS || purpose == DVIPDFM)
2544 if (purpose == DVIPS || purpose == DVIPDFM)
2548 if (purpose == DVIPS || purpose == DVIPDFM)
2552 if (purpose == DVIPS || purpose == DVIPDFM)
2556 if (purpose == DVIPS || purpose == DVIPDFM)
2560 if (purpose == DVIPS || purpose == DVIPDFM)
2564 if (purpose == DVIPS || purpose == DVIPDFM)
2568 if (purpose == DVIPS || purpose == DVIPDFM)
2571 case PAPER_USEXECUTIVE:
2572 // dvipdfm does not know this
2573 if (purpose == DVIPDFM)
2578 case PAPER_USLETTER:
2580 if (purpose == XDVI)
2587 string const BufferParams::dvips_options() const
2591 // If the class loads the geometry package, we do not know which
2592 // paper size is used, since we do not set it (bug 7013).
2593 // Therefore we must not specify any argument here.
2594 // dvips gets the correct paper size via DVI specials in this case
2595 // (if the class uses the geometry package correctly).
2596 if (documentClass().provides("geometry"))
2600 && papersize == PAPER_CUSTOM
2601 && !lyxrc.print_paper_dimension_flag.empty()
2602 && !paperwidth.empty()
2603 && !paperheight.empty()) {
2604 // using a custom papersize
2605 result = lyxrc.print_paper_dimension_flag;
2606 result += ' ' + paperwidth;
2607 result += ',' + paperheight;
2609 string const paper_option = paperSizeName(DVIPS);
2610 if (!paper_option.empty() && (paper_option != "letter" ||
2611 orientation != ORIENTATION_LANDSCAPE)) {
2612 // dvips won't accept -t letter -t landscape.
2613 // In all other cases, include the paper size
2615 result = lyxrc.print_paper_flag;
2616 result += ' ' + paper_option;
2619 if (orientation == ORIENTATION_LANDSCAPE &&
2620 papersize != PAPER_CUSTOM)
2621 result += ' ' + lyxrc.print_landscape_flag;
2626 string const BufferParams::font_encoding() const
2628 return (fontenc == "global") ? lyxrc.fontenc : fontenc;
2632 string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
2634 if (lang_package != "auto" && lang_package != "babel"
2635 && lang_package != "default" && lang_package != "none")
2636 return lang_package;
2637 if (lyxrc.language_package_selection == LyXRC::LP_CUSTOM)
2638 return lyxrc.language_custom_package;
2639 // suppress the babel call if there is no BabelName defined
2640 // for the document language in the lib/languages file and if no
2641 // other languages are used (lang_opts is then empty)
2642 if (lang_opts.empty())
2644 // either a specific language (AsBabelOptions setting in
2645 // lib/languages) or the prefs require the languages to
2646 // be submitted to babel itself (not the class).
2648 return "\\usepackage[" + lang_opts + "]{babel}";
2649 return "\\usepackage{babel}";
2653 docstring BufferParams::getGraphicsDriver(string const & package) const
2657 if (package == "geometry") {
2658 if (graphics_driver == "dvips"
2659 || graphics_driver == "dvipdfm"
2660 || graphics_driver == "pdftex"
2661 || graphics_driver == "vtex")
2662 result = from_ascii(graphics_driver);
2663 else if (graphics_driver == "dvipdfmx")
2664 result = from_ascii("dvipdfm");
2671 void BufferParams::writeEncodingPreamble(otexstream & os,
2672 LaTeXFeatures & features) const
2674 // XeTeX does not need this
2675 if (features.runparams().flavor == OutputParams::XETEX)
2677 // LuaTeX neither, but with tex fonts, we need to load
2678 // the luainputenc package.
2679 if (features.runparams().flavor == OutputParams::LUATEX
2680 || features.runparams().flavor == OutputParams::DVILUATEX) {
2681 if (!useNonTeXFonts && inputenc != "default"
2682 && ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
2683 || (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
2684 os << "\\usepackage[utf8]{luainputenc}\n";
2688 if (inputenc == "auto") {
2689 string const doc_encoding =
2690 language->encoding()->latexName();
2691 Encoding::Package const package =
2692 language->encoding()->package();
2694 // Create a list with all the input encodings used
2696 set<string> encodings =
2697 features.getEncodingSet(doc_encoding);
2699 // If the "japanese" package (i.e. pLaTeX) is used,
2700 // inputenc must be omitted.
2701 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
2702 if (package == Encoding::japanese)
2703 features.require("japanese");
2705 if ((!encodings.empty() || package == Encoding::inputenc)
2706 && !features.isRequired("japanese")) {
2707 os << "\\usepackage[";
2708 set<string>::const_iterator it = encodings.begin();
2709 set<string>::const_iterator const end = encodings.end();
2711 os << from_ascii(*it);
2714 for (; it != end; ++it)
2715 os << ',' << from_ascii(*it);
2716 if (package == Encoding::inputenc) {
2717 if (!encodings.empty())
2719 os << from_ascii(doc_encoding);
2721 os << "]{inputenc}\n";
2723 if (package == Encoding::CJK || features.mustProvide("CJK")) {
2724 if (language->encoding()->name() == "utf8-cjk"
2725 && LaTeXFeatures::isAvailable("CJKutf8"))
2726 os << "\\usepackage{CJKutf8}\n";
2728 os << "\\usepackage{CJK}\n";
2730 } else if (inputenc != "default") {
2731 switch (encoding().package()) {
2732 case Encoding::none:
2733 case Encoding::japanese:
2735 case Encoding::inputenc:
2736 // do not load inputenc if japanese is used
2737 if (features.isRequired("japanese"))
2739 os << "\\usepackage[" << from_ascii(inputenc)
2743 if (encoding().name() == "utf8-cjk"
2744 && LaTeXFeatures::isAvailable("CJKutf8"))
2745 os << "\\usepackage{CJKutf8}\n";
2747 os << "\\usepackage{CJK}\n";
2752 // The encoding "armscii8" (for Armenian) is only available when
2753 // the package "armtex" is loaded.
2754 if (language->encoding()->latexName() == "armscii8"
2755 || inputenc == "armscii8")
2756 os << "\\usepackage{armtex}\n";
2760 string const BufferParams::parseFontName(string const & name) const
2762 string mangled = name;
2763 size_t const idx = mangled.find('[');
2764 if (idx == string::npos || idx == 0)
2767 return mangled.substr(0, idx - 1);
2771 string const BufferParams::loadFonts(string const & rm,
2772 string const & sf, string const & tt,
2773 bool const & sc, bool const & osf,
2774 int const & sfscale, int const & ttscale,
2775 bool const & use_systemfonts,
2776 LaTeXFeatures & features) const
2778 /* The LaTeX font world is in a flux. In the PSNFSS font interface,
2779 several packages have been replaced by others, that might not
2780 be installed on every system. We have to take care for that
2781 (see psnfss.pdf). We try to support all psnfss fonts as well
2782 as the fonts that have become de facto standard in the LaTeX
2783 world (e.g. Latin Modern). We do not support obsolete fonts
2784 (like PSLatex). In general, it should be possible to mix any
2785 rm font with any sf or tt font, respectively. (JSpitzm)
2787 -- separate math fonts.
2790 if (rm == "default" && sf == "default" && tt == "default")
2796 /* Fontspec (XeTeX, LuaTeX): we provide GUI support for oldstyle
2797 * numbers (Numbers=OldStyle) and sf/tt scaling. The Ligatures=TeX/
2798 * Mapping=tex-text option assures TeX ligatures (such as "--")
2799 * are resolved. Note that tt does not use these ligatures.
2801 * -- add more GUI options?
2802 * -- add more fonts (fonts for other scripts)
2803 * -- if there's a way to find out if a font really supports
2804 * OldStyle, enable/disable the widget accordingly.
2806 if (use_systemfonts && features.isAvailable("fontspec")) {
2807 // "Mapping=tex-text" and "Ligatures=TeX" are equivalent.
2808 // However, until v.2 (2010/07/11) fontspec only knew
2809 // Mapping=tex-text (for XeTeX only); then "Ligatures=TeX"
2810 // was introduced for both XeTeX and LuaTeX (LuaTeX
2811 // didn't understand "Mapping=tex-text", while XeTeX
2812 // understood both. With most recent versions, both
2813 // variants are understood by both engines. However,
2814 // we want to provide support for at least TeXLive 2009
2815 // (for XeTeX; LuaTeX is only supported as of v.2)
2816 string const texmapping =
2817 (features.runparams().flavor == OutputParams::XETEX) ?
2818 "Mapping=tex-text" : "Ligatures=TeX";
2819 if (rm != "default") {
2820 os << "\\setmainfont[" << texmapping;
2822 os << ",Numbers=OldStyle";
2823 os << "]{" << parseFontName(rm) << "}\n";
2825 if (sf != "default") {
2826 string const sans = parseFontName(sf);
2828 os << "\\setsansfont[Scale="
2829 << float(sfscale) / 100
2830 << "," << texmapping << "]{"
2833 os << "\\setsansfont[" << texmapping << "]{"
2836 if (tt != "default") {
2837 string const mono = parseFontName(tt);
2839 os << "\\setmonofont[Scale="
2840 << float(ttscale) / 100
2844 os << "\\setmonofont{"
2851 // Computer Modern (must be explicitly selectable -- there might be classes
2852 // that define a different default font!
2854 os << "\\renewcommand{\\rmdefault}{cmr}\n";
2855 // osf for Computer Modern needs eco.sty
2857 os << "\\usepackage{eco}\n";
2859 // Latin Modern Roman
2860 else if (rm == "lmodern")
2861 os << "\\usepackage{lmodern}\n";
2863 else if (rm == "ae") {
2864 // not needed when using OT1 font encoding.
2865 if (font_encoding() != "default")
2866 os << "\\usepackage{ae,aecompl}\n";
2869 else if (rm == "times") {
2870 // try to load the best available package
2871 if (LaTeXFeatures::isAvailable("mathptmx"))
2872 os << "\\usepackage{mathptmx}\n";
2873 else if (LaTeXFeatures::isAvailable("mathptm"))
2874 os << "\\usepackage{mathptm}\n";
2876 os << "\\usepackage{times}\n";
2879 else if (rm == "palatino") {
2880 // try to load the best available package
2881 if (LaTeXFeatures::isAvailable("mathpazo")) {
2882 os << "\\usepackage";
2888 // "osf" includes "sc"!
2892 os << "{mathpazo}\n";
2894 else if (LaTeXFeatures::isAvailable("mathpple"))
2895 os << "\\usepackage{mathpple}\n";
2897 os << "\\usepackage{palatino}\n";
2900 else if (rm == "utopia") {
2901 // fourier supersedes utopia.sty, but does
2902 // not work with OT1 encoding.
2903 if (LaTeXFeatures::isAvailable("fourier")
2904 && font_encoding() != "default") {
2905 os << "\\usepackage";
2916 os << "{fourier}\n";
2919 os << "\\usepackage{utopia}\n";
2921 // Bera (complete fontset)
2922 else if (rm == "bera" && sf == "default" && tt == "default")
2923 os << "\\usepackage{bera}\n";
2925 else if (rm != "default")
2926 os << "\\usepackage" << "{" << rm << "}\n";
2929 // Helvetica, Bera Sans
2930 if (sf == "helvet" || sf == "berasans") {
2932 os << "\\usepackage[scaled=" << float(sfscale) / 100
2933 << "]{" << sf << "}\n";
2935 os << "\\usepackage{" << sf << "}\n";
2938 else if (sf == "avant")
2939 os << "\\usepackage{" << sf << "}\n";
2940 // Computer Modern, Latin Modern, CM Bright
2941 else if (sf != "default")
2942 os << "\\renewcommand{\\sfdefault}{" << sf << "}\n";
2944 // monospaced/typewriter
2945 // Courier, LuxiMono
2946 if (tt == "luximono" || tt == "beramono") {
2948 os << "\\usepackage[scaled=" << float(ttscale) / 100
2949 << "]{" << tt << "}\n";
2951 os << "\\usepackage{" << tt << "}\n";
2954 else if (tt == "courier" )
2955 os << "\\usepackage{" << tt << "}\n";
2956 // Computer Modern, Latin Modern, CM Bright
2957 else if (tt != "default")
2958 os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
2964 Encoding const & BufferParams::encoding() const
2966 // FIXME: actually, we should check for the flavor
2967 // or runparams.isFullyUnicode() here:
2968 // This check will not work with XeTeX/LuaTeX and tex fonts.
2969 // Thus we have to reset the encoding in Buffer::makeLaTeXFile.
2971 return *(encodings.fromLaTeXName("utf8-plain"));
2972 if (inputenc == "auto" || inputenc == "default")
2973 return *language->encoding();
2974 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2977 LYXERR0("Unknown inputenc value `" << inputenc
2978 << "'. Using `auto' instead.");
2979 return *language->encoding();
2983 bool BufferParams::addCiteEngine(string const & engine)
2985 LayoutModuleList::const_iterator it = cite_engine_.begin();
2986 LayoutModuleList::const_iterator en = cite_engine_.end();
2987 for (; it != en; ++it)
2990 cite_engine_.push_back(engine);
2995 bool BufferParams::addCiteEngine(vector<string> const & engine)
2997 vector<string>::const_iterator it = engine.begin();
2998 vector<string>::const_iterator en = engine.end();
3000 for (; it != en; ++it)
3001 if (!addCiteEngine(*it))
3007 string const & BufferParams::defaultBiblioStyle() const
3009 return documentClass().defaultBiblioStyle();
3013 bool const & BufferParams::fullAuthorList() const
3015 return documentClass().fullAuthorList();
3019 void BufferParams::setCiteEngine(string const & engine)
3022 addCiteEngine(engine);
3026 void BufferParams::setCiteEngine(vector<string> const & engine)
3029 addCiteEngine(engine);
3033 vector<string> BufferParams::citeCommands() const
3035 static CitationStyle const default_style;
3036 vector<string> commands =
3037 documentClass().citeCommands(citeEngineType());
3038 if (commands.empty())
3039 commands.push_back(default_style.cmd);
3044 vector<CitationStyle> BufferParams::citeStyles() const
3046 static CitationStyle const default_style;
3047 vector<CitationStyle> styles =
3048 documentClass().citeStyles(citeEngineType());
3050 styles.push_back(default_style);