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"
28 #include "LaTeXFeatures.h"
29 #include "ModuleList.h"
33 #include "OutputParams.h"
37 #include "PDFOptions.h"
39 #include "frontends/alert.h"
41 #include "insets/InsetListingsParams.h"
43 #include "support/convert.h"
44 #include "support/debug.h"
45 #include "support/docstream.h"
46 #include "support/FileName.h"
47 #include "support/filetools.h"
48 #include "support/gettext.h"
49 #include "support/Messages.h"
50 #include "support/Translator.h"
51 #include "support/lstrings.h"
57 using namespace lyx::support;
60 static char const * const string_paragraph_separation[] = {
65 static char const * const string_quotes_language[] = {
66 "english", "swedish", "german", "polish", "french", "danish", ""
70 static char const * const string_papersize[] = {
71 "default", "custom", "letterpaper", "legalpaper", "executivepaper",
72 "a3paper", "a4paper", "a5paper", "b3paper", "b4paper", "b5paper", ""
76 static char const * const string_orientation[] = {
77 "portrait", "landscape", ""
81 static char const * const string_footnotekinds[] = {
82 "footnote", "margin", "fig", "tab", "alg", "wide-fig", "wide-tab", ""
86 static char const * const tex_graphics[] = {
87 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
88 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
89 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
90 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
100 // Paragraph separation
101 typedef Translator<string, BufferParams::ParagraphSeparation> ParSepTranslator;
104 ParSepTranslator const init_parseptranslator()
106 ParSepTranslator translator
107 (string_paragraph_separation[0], BufferParams::ParagraphIndentSeparation);
108 translator.addPair(string_paragraph_separation[1], BufferParams::ParagraphSkipSeparation);
113 ParSepTranslator const & parseptranslator()
115 static ParSepTranslator translator = init_parseptranslator();
121 typedef Translator<string, InsetQuotes::QuoteLanguage> QuotesLangTranslator;
124 QuotesLangTranslator const init_quoteslangtranslator()
126 QuotesLangTranslator translator
127 (string_quotes_language[0], InsetQuotes::EnglishQuotes);
128 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQuotes);
129 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQuotes);
130 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQuotes);
131 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQuotes);
132 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQuotes);
137 QuotesLangTranslator const & quoteslangtranslator()
139 static QuotesLangTranslator translator = init_quoteslangtranslator();
145 typedef Translator<string, PAPER_SIZE> PaperSizeTranslator;
148 static PaperSizeTranslator initPaperSizeTranslator()
150 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
151 translator.addPair(string_papersize[1], PAPER_CUSTOM);
152 translator.addPair(string_papersize[2], PAPER_USLETTER);
153 translator.addPair(string_papersize[3], PAPER_USLEGAL);
154 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
155 translator.addPair(string_papersize[5], PAPER_A3);
156 translator.addPair(string_papersize[6], PAPER_A4);
157 translator.addPair(string_papersize[7], PAPER_A5);
158 translator.addPair(string_papersize[8], PAPER_B3);
159 translator.addPair(string_papersize[9], PAPER_B4);
160 translator.addPair(string_papersize[10], PAPER_B5);
165 PaperSizeTranslator const & papersizetranslator()
167 static PaperSizeTranslator translator = initPaperSizeTranslator();
173 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
176 PaperOrientationTranslator const init_paperorientationtranslator()
178 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
179 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
184 PaperOrientationTranslator const & paperorientationtranslator()
186 static PaperOrientationTranslator translator = init_paperorientationtranslator();
192 typedef Translator<int, PageSides> SidesTranslator;
195 SidesTranslator const init_sidestranslator()
197 SidesTranslator translator(1, OneSide);
198 translator.addPair(2, TwoSides);
203 SidesTranslator const & sidestranslator()
205 static SidesTranslator translator = init_sidestranslator();
211 typedef Translator<int, BufferParams::Package> PackageTranslator;
214 PackageTranslator const init_packagetranslator()
216 PackageTranslator translator(0, BufferParams::package_off);
217 translator.addPair(1, BufferParams::package_auto);
218 translator.addPair(2, BufferParams::package_on);
223 PackageTranslator const & packagetranslator()
225 static PackageTranslator translator = init_packagetranslator();
231 typedef Translator<string, CiteEngine> CiteEngineTranslator;
234 CiteEngineTranslator const init_citeenginetranslator()
236 CiteEngineTranslator translator("basic", ENGINE_BASIC);
237 translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL);
238 translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
239 translator.addPair("jurabib", ENGINE_JURABIB);
244 CiteEngineTranslator const & citeenginetranslator()
246 static CiteEngineTranslator translator = init_citeenginetranslator();
252 typedef Translator<string, Spacing::Space> SpaceTranslator;
255 SpaceTranslator const init_spacetranslator()
257 SpaceTranslator translator("default", Spacing::Default);
258 translator.addPair("single", Spacing::Single);
259 translator.addPair("onehalf", Spacing::Onehalf);
260 translator.addPair("double", Spacing::Double);
261 translator.addPair("other", Spacing::Other);
266 SpaceTranslator const & spacetranslator()
268 static SpaceTranslator translator = init_spacetranslator();
276 class BufferParams::Impl
281 AuthorList authorlist;
282 BranchList branchlist;
283 Bullet temp_bullets[4];
284 Bullet user_defined_bullets[4];
286 /** This is the amount of space used for paragraph_separation "skip",
287 * and for detached paragraphs in "indented" documents.
290 PDFOptions pdfoptions;
291 LayoutFileIndex baseClass_;
295 BufferParams::Impl::Impl()
296 : defskip(VSpace::MEDSKIP), baseClass_(string(""))
298 // set initial author
300 authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email)));
305 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
309 return new BufferParams::Impl(*ptr);
313 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
319 BufferParams::BufferParams()
322 setBaseClass(defaultBaseclass());
324 paragraph_separation = ParagraphIndentSeparation;
325 quotes_language = InsetQuotes::EnglishQuotes;
326 fontsize = "default";
329 papersize = PAPER_DEFAULT;
330 orientation = ORIENTATION_PORTRAIT;
331 use_geometry = false;
332 use_amsmath = package_auto;
333 use_esint = package_auto;
334 cite_engine_ = ENGINE_BASIC;
335 use_bibtopic = false;
336 trackChanges = false;
337 outputChanges = false;
340 language = default_language;
341 fontsRoman = "default";
342 fontsSans = "default";
343 fontsTypewriter = "default";
344 fontsDefaultFamily = "default";
347 fontsSansScale = 100;
348 fontsTypewriterScale = 100;
350 graphicsDriver = "default";
353 listings_params = string();
354 pagestyle = "default";
356 for (int iter = 0; iter < 4; ++iter) {
357 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
358 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
363 docstring BufferParams::B_(string const & l10n) const
365 LASSERT(language, /**/);
366 return getMessages(language->code()).get(l10n);
370 AuthorList & BufferParams::authors()
372 return pimpl_->authorlist;
376 AuthorList const & BufferParams::authors() const
378 return pimpl_->authorlist;
382 BranchList & BufferParams::branchlist()
384 return pimpl_->branchlist;
388 BranchList const & BufferParams::branchlist() const
390 return pimpl_->branchlist;
394 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
396 LASSERT(index < 4, /**/);
397 return pimpl_->temp_bullets[index];
401 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
403 LASSERT(index < 4, /**/);
404 return pimpl_->temp_bullets[index];
408 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
410 LASSERT(index < 4, /**/);
411 return pimpl_->user_defined_bullets[index];
415 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
417 LASSERT(index < 4, /**/);
418 return pimpl_->user_defined_bullets[index];
422 Spacing & BufferParams::spacing()
424 return pimpl_->spacing;
428 Spacing const & BufferParams::spacing() const
430 return pimpl_->spacing;
434 PDFOptions & BufferParams::pdfoptions()
436 return pimpl_->pdfoptions;
440 PDFOptions const & BufferParams::pdfoptions() const
442 return pimpl_->pdfoptions;
446 VSpace const & BufferParams::getDefSkip() const
448 return pimpl_->defskip;
452 void BufferParams::setDefSkip(VSpace const & vs)
454 pimpl_->defskip = vs;
458 string BufferParams::readToken(Lexer & lex, string const & token,
459 FileName const & filepath)
461 if (token == "\\textclass") {
463 string const classname = lex.getString();
464 // if there exists a local layout file, ignore the system one
465 // NOTE: in this case, the textclass (.cls file) is assumed to be available.
467 LayoutFileList & bcl = LayoutFileList::get();
468 if (tcp.empty() && !filepath.empty())
469 tcp = bcl.addLocalLayout(classname, filepath.absFilename());
473 setBaseClass(classname);
474 // We assume that a tex class exists for local or unknown layouts so this warning
475 // will only be given for system layouts.
476 if (!baseClass()->isTeXClassAvailable()) {
477 docstring const msg =
478 bformat(_("The layout file requested by this document,\n"
480 "is not usable. This is probably because a LaTeX\n"
481 "class or style file required by it is not\n"
482 "available. See the Customization documentation\n"
483 "for more information.\n"), from_utf8(classname));
484 frontend::Alert::warning(_("Document class not available"),
485 msg + _("LyX will not be able to produce output."));
487 } else if (token == "\\begin_preamble") {
489 } else if (token == "\\begin_local_layout") {
490 readLocalLayout(lex);
491 } else if (token == "\\begin_modules") {
493 } else if (token == "\\begin_removed_modules") {
494 readRemovedModules(lex);
495 } else if (token == "\\options") {
497 options = lex.getString();
498 } else if (token == "\\master") {
500 master = lex.getString();
501 } else if (token == "\\language") {
503 } else if (token == "\\inputencoding") {
505 } else if (token == "\\graphics") {
506 readGraphicsDriver(lex);
507 } else if (token == "\\font_roman") {
509 } else if (token == "\\font_sans") {
511 } else if (token == "\\font_typewriter") {
512 lex >> fontsTypewriter;
513 } else if (token == "\\font_default_family") {
514 lex >> fontsDefaultFamily;
515 } else if (token == "\\font_sc") {
517 } else if (token == "\\font_osf") {
519 } else if (token == "\\font_sf_scale") {
520 lex >> fontsSansScale;
521 } else if (token == "\\font_tt_scale") {
522 lex >> fontsTypewriterScale;
523 } else if (token == "\\font_cjk") {
525 } else if (token == "\\paragraph_separation") {
528 paragraph_separation = parseptranslator().find(parsep);
529 } else if (token == "\\defskip") {
531 string defskip = lex.getString();
532 if (defskip == "defskip")
535 pimpl_->defskip = VSpace(defskip);
536 } else if (token == "\\quotes_language") {
539 quotes_language = quoteslangtranslator().find(quotes_lang);
540 } else if (token == "\\papersize") {
543 papersize = papersizetranslator().find(ppsize);
544 } else if (token == "\\use_geometry") {
546 } else if (token == "\\use_amsmath") {
549 use_amsmath = packagetranslator().find(use_ams);
550 } else if (token == "\\use_esint") {
553 use_esint = packagetranslator().find(useesint);
554 } else if (token == "\\cite_engine") {
557 cite_engine_ = citeenginetranslator().find(engine);
558 } else if (token == "\\use_bibtopic") {
560 } else if (token == "\\tracking_changes") {
562 } else if (token == "\\output_changes") {
563 lex >> outputChanges;
564 } else if (token == "\\branch") {
566 docstring branch = lex.getDocString();
567 branchlist().add(branch);
570 string const tok = lex.getString();
571 if (tok == "\\end_branch")
573 Branch * branch_ptr = branchlist().find(branch);
574 if (tok == "\\selected") {
577 branch_ptr->setSelected(lex.getInteger());
579 // not yet operational
580 if (tok == "\\color") {
582 string color = lex.getString();
584 branch_ptr->setColor(color);
585 // Update also the Color table:
587 color = lcolor.getX11Name(Color_background);
589 lcolor.setColor(to_utf8(branch), color);
593 } else if (token == "\\author") {
595 istringstream ss(lex.getString());
598 author_map.push_back(pimpl_->authorlist.record(a));
599 } else if (token == "\\paperorientation") {
602 orientation = paperorientationtranslator().find(orient);
603 } else if (token == "\\paperwidth") {
605 } else if (token == "\\paperheight") {
607 } else if (token == "\\leftmargin") {
609 } else if (token == "\\topmargin") {
611 } else if (token == "\\rightmargin") {
613 } else if (token == "\\bottommargin") {
615 } else if (token == "\\headheight") {
617 } else if (token == "\\headsep") {
619 } else if (token == "\\footskip") {
621 } else if (token == "\\columnsep") {
623 } else if (token == "\\paperfontsize") {
625 } else if (token == "\\papercolumns") {
627 } else if (token == "\\listings_params") {
630 listings_params = InsetListingsParams(par).params();
631 } else if (token == "\\papersides") {
634 sides = sidestranslator().find(psides);
635 } else if (token == "\\paperpagestyle") {
637 } else if (token == "\\bullet") {
639 } else if (token == "\\bulletLaTeX") {
640 readBulletsLaTeX(lex);
641 } else if (token == "\\secnumdepth") {
643 } else if (token == "\\tocdepth") {
645 } else if (token == "\\spacing") {
649 if (nspacing == "other") {
652 spacing().set(spacetranslator().find(nspacing), tmp_val);
653 } else if (token == "\\float_placement") {
654 lex >> float_placement;
656 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
657 string toktmp = pdfoptions().readToken(lex, token);
658 if (!toktmp.empty()) {
659 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
664 lyxerr << "BufferParams::readToken(): Unknown token: " <<
673 void BufferParams::writeFile(ostream & os) const
675 // The top of the file is written by the buffer.
676 // Prints out the buffer info into the .lyx file given by file
679 os << "\\textclass " << baseClass()->name() << '\n';
682 if (!preamble.empty()) {
683 // remove '\n' from the end of preamble
684 string const tmppreamble = rtrim(preamble, "\n");
685 os << "\\begin_preamble\n"
687 << "\n\\end_preamble\n";
691 if (!options.empty()) {
692 os << "\\options " << options << '\n';
695 // the master document
696 if (!master.empty()) {
697 os << "\\master " << master << '\n';
701 if (!removedModules_.empty()) {
702 os << "\\begin_removed_modules" << '\n';
703 set<string>::const_iterator it = removedModules_.begin();
704 set<string>::const_iterator en = removedModules_.end();
705 for (; it != en; it++)
707 os << "\\end_removed_modules" << '\n';
711 if (!layoutModules_.empty()) {
712 os << "\\begin_modules" << '\n';
713 LayoutModuleList::const_iterator it = layoutModules_.begin();
714 LayoutModuleList::const_iterator en = layoutModules_.end();
715 for (; it != en; it++)
717 os << "\\end_modules" << '\n';
720 // local layout information
721 if (!local_layout.empty()) {
722 // remove '\n' from the end
723 string const tmplocal = rtrim(local_layout, "\n");
724 os << "\\begin_local_layout\n"
726 << "\n\\end_local_layout\n";
729 // then the text parameters
730 if (language != ignore_language)
731 os << "\\language " << language->lang() << '\n';
732 os << "\\inputencoding " << inputenc
733 << "\n\\font_roman " << fontsRoman
734 << "\n\\font_sans " << fontsSans
735 << "\n\\font_typewriter " << fontsTypewriter
736 << "\n\\font_default_family " << fontsDefaultFamily
737 << "\n\\font_sc " << convert<string>(fontsSC)
738 << "\n\\font_osf " << convert<string>(fontsOSF)
739 << "\n\\font_sf_scale " << fontsSansScale
740 << "\n\\font_tt_scale " << fontsTypewriterScale
742 if (!fontsCJK.empty()) {
743 os << "\\font_cjk " << fontsCJK << '\n';
745 os << "\n\\graphics " << graphicsDriver << '\n';
747 if (!float_placement.empty()) {
748 os << "\\float_placement " << float_placement << '\n';
750 os << "\\paperfontsize " << fontsize << '\n';
752 spacing().writeFile(os);
753 pdfoptions().writeFile(os);
755 os << "\\papersize " << string_papersize[papersize]
756 << "\n\\use_geometry " << convert<string>(use_geometry)
757 << "\n\\use_amsmath " << use_amsmath
758 << "\n\\use_esint " << use_esint
759 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
760 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
761 << "\n\\paperorientation " << string_orientation[orientation]
764 BranchList::const_iterator it = branchlist().begin();
765 BranchList::const_iterator end = branchlist().end();
766 for (; it != end; ++it) {
767 os << "\\branch " << to_utf8(it->branch())
768 << "\n\\selected " << it->isSelected()
769 << "\n\\color " << lyx::X11hexname(it->color())
774 if (!paperwidth.empty())
775 os << "\\paperwidth "
776 << VSpace(paperwidth).asLyXCommand() << '\n';
777 if (!paperheight.empty())
778 os << "\\paperheight "
779 << VSpace(paperheight).asLyXCommand() << '\n';
780 if (!leftmargin.empty())
781 os << "\\leftmargin "
782 << VSpace(leftmargin).asLyXCommand() << '\n';
783 if (!topmargin.empty())
785 << VSpace(topmargin).asLyXCommand() << '\n';
786 if (!rightmargin.empty())
787 os << "\\rightmargin "
788 << VSpace(rightmargin).asLyXCommand() << '\n';
789 if (!bottommargin.empty())
790 os << "\\bottommargin "
791 << VSpace(bottommargin).asLyXCommand() << '\n';
792 if (!headheight.empty())
793 os << "\\headheight "
794 << VSpace(headheight).asLyXCommand() << '\n';
795 if (!headsep.empty())
797 << VSpace(headsep).asLyXCommand() << '\n';
798 if (!footskip.empty())
800 << VSpace(footskip).asLyXCommand() << '\n';
801 if (!columnsep.empty())
803 << VSpace(columnsep).asLyXCommand() << '\n';
804 os << "\\secnumdepth " << secnumdepth
805 << "\n\\tocdepth " << tocdepth
806 << "\n\\paragraph_separation "
807 << string_paragraph_separation[paragraph_separation]
808 << "\n\\defskip " << getDefSkip().asLyXCommand()
809 << "\n\\quotes_language "
810 << string_quotes_language[quotes_language]
811 << "\n\\papercolumns " << columns
812 << "\n\\papersides " << sides
813 << "\n\\paperpagestyle " << pagestyle << '\n';
814 if (!listings_params.empty())
815 os << "\\listings_params \"" <<
816 InsetListingsParams(listings_params).encodedString() << "\"\n";
817 for (int i = 0; i < 4; ++i) {
818 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
819 if (user_defined_bullet(i).getFont() != -1) {
820 os << "\\bullet " << i << " "
821 << user_defined_bullet(i).getFont() << " "
822 << user_defined_bullet(i).getCharacter() << " "
823 << user_defined_bullet(i).getSize() << "\n";
827 os << "\\bulletLaTeX " << i << " \""
828 << lyx::to_ascii(user_defined_bullet(i).getText())
834 os << "\\tracking_changes " << convert<string>(trackChanges) << "\n";
835 os << "\\output_changes " << convert<string>(outputChanges) << "\n";
837 AuthorList::Authors::const_iterator a_it = pimpl_->authorlist.begin();
838 AuthorList::Authors::const_iterator a_end = pimpl_->authorlist.end();
839 for (; a_it != a_end; ++a_it) {
840 if (a_it->second.used())
841 os << "\\author " << a_it->second << "\n";
843 os << "\\author " << Author() << "\n";
848 void BufferParams::validate(LaTeXFeatures & features) const
850 features.require(documentClass().requires());
853 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
854 bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
855 LaTeXFeatures::isAvailable("xcolor");
857 switch (features.runparams().flavor) {
858 case OutputParams::LATEX:
860 features.require("ct-dvipost");
861 features.require("dvipost");
862 } else if (xcolorsoul) {
863 features.require("ct-xcolor-soul");
864 features.require("soul");
865 features.require("xcolor");
867 features.require("ct-none");
870 case OutputParams::PDFLATEX:
872 features.require("ct-xcolor-soul");
873 features.require("soul");
874 features.require("xcolor");
875 // improves color handling in PDF output
876 features.require("pdfcolmk");
878 features.require("ct-none");
886 // Floats with 'Here definitely' as default setting.
887 if (float_placement.find('H') != string::npos)
888 features.require("float");
890 // AMS Style is at document level
891 if (use_amsmath == package_on
892 || documentClass().provides("amsmath"))
893 features.require("amsmath");
894 if (use_esint == package_on)
895 features.require("esint");
897 // Document-level line spacing
898 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
899 features.require("setspace");
901 // the bullet shapes are buffer level not paragraph level
902 // so they are tested here
903 for (int i = 0; i < 4; ++i) {
904 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
906 int const font = user_defined_bullet(i).getFont();
908 int const c = user_defined_bullet(i).getCharacter();
914 features.require("latexsym");
916 } else if (font == 1) {
917 features.require("amssymb");
918 } else if (font >= 2 && font <= 5) {
919 features.require("pifont");
923 if (pdfoptions().use_hyperref) {
924 features.require("hyperref");
925 // due to interferences with babel and hyperref, the color package has to
926 // be loaded after hyperref when hyperref is used with the colorlinks
927 // option, see http://bugzilla.lyx.org/show_bug.cgi?id=5291
928 if (pdfoptions().colorlinks)
929 features.require("color");
932 if (language->lang() == "vietnamese")
933 features.require("vietnamese");
934 else if (language->lang() == "japanese")
935 features.require("japanese");
939 bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
940 TexRow & texrow) const
942 os << "\\documentclass";
944 DocumentClass const & tclass = documentClass();
946 ostringstream clsoptions; // the document class options.
948 if (tokenPos(tclass.opt_fontsize(),
949 '|', fontsize) >= 0) {
950 // only write if existing in list (and not default)
951 clsoptions << fontsize << "pt,";
954 // custom, A3, B3 and B4 paper sizes need geometry
955 bool nonstandard_papersize = papersize == PAPER_B3
956 || papersize == PAPER_B4
957 || papersize == PAPER_A3
958 || papersize == PAPER_CUSTOM;
963 clsoptions << "a4paper,";
966 clsoptions << "letterpaper,";
969 clsoptions << "a5paper,";
972 clsoptions << "b5paper,";
974 case PAPER_USEXECUTIVE:
975 clsoptions << "executivepaper,";
978 clsoptions << "legalpaper,";
990 if (sides != tclass.sides()) {
993 clsoptions << "oneside,";
996 clsoptions << "twoside,";
1002 if (columns != tclass.columns()) {
1004 clsoptions << "twocolumn,";
1006 clsoptions << "onecolumn,";
1010 && orientation == ORIENTATION_LANDSCAPE)
1011 clsoptions << "landscape,";
1013 // language should be a parameter to \documentclass
1014 if (language->babel() == "hebrew"
1015 && default_language->babel() != "hebrew")
1016 // This seems necessary
1017 features.useLanguage(default_language);
1019 ostringstream language_options;
1020 bool const use_babel = features.useBabel();
1022 language_options << features.getLanguages();
1023 if (!language->babel().empty()) {
1024 if (!language_options.str().empty())
1025 language_options << ',';
1026 language_options << language->babel();
1028 // if Vietnamese is used, babel must directly be loaded
1029 // with language options, not in the class options, see
1030 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
1031 size_t viet = language_options.str().find("vietnam");
1032 // viet = string::npos when not found
1033 // if Japanese is used, babel must directly be loaded
1034 // with language options, not in the class options, see
1035 // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
1036 size_t japan = language_options.str().find("japanese");
1037 // japan = string::npos when not found
1038 if (lyxrc.language_global_options
1039 && !language_options.str().empty()
1040 && viet == string::npos && japan == string::npos)
1041 clsoptions << language_options.str() << ',';
1044 // the user-defined options
1045 if (!options.empty()) {
1046 clsoptions << options << ',';
1049 string strOptions(clsoptions.str());
1050 if (!strOptions.empty()) {
1051 strOptions = rtrim(strOptions, ",");
1053 os << '[' << from_utf8(strOptions) << ']';
1056 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1058 // end of \documentclass defs
1060 // font selection must be done before loading fontenc.sty
1061 string const fonts =
1062 loadFonts(fontsRoman, fontsSans,
1063 fontsTypewriter, fontsSC, fontsOSF,
1064 fontsSansScale, fontsTypewriterScale);
1065 if (!fonts.empty()) {
1066 os << from_ascii(fonts);
1069 if (fontsDefaultFamily != "default")
1070 os << "\\renewcommand{\\familydefault}{\\"
1071 << from_ascii(fontsDefaultFamily) << "}\n";
1073 // set font encoding
1074 // this one is not per buffer
1075 // for arabic_arabi and farsi we also need to load the LAE and
1077 if (lyxrc.fontenc != "default" && language->lang() != "japanese") {
1078 if (language->lang() == "arabic_arabi"
1079 || language->lang() == "farsi") {
1080 os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
1081 << ",LFE,LAE]{fontenc}\n";
1084 os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
1090 // handle inputenc etc.
1091 writeEncodingPreamble(os, features, texrow);
1093 if (!listings_params.empty() || features.isRequired("listings")) {
1094 os << "\\usepackage{listings}\n";
1097 if (!listings_params.empty()) {
1099 // do not test validity because listings_params is
1100 // supposed to be valid
1102 InsetListingsParams(listings_params).separatedParams(true);
1103 // we can't support all packages, but we should load the color package
1104 if (par.find("\\color", 0) != string::npos)
1105 features.require("color");
1106 os << from_utf8(par);
1107 // count the number of newlines
1108 for (size_t i = 0; i < par.size(); ++i)
1114 if (use_geometry || nonstandard_papersize) {
1115 os << "\\usepackage{geometry}\n";
1117 os << "\\geometry{verbose";
1118 if (orientation == ORIENTATION_LANDSCAPE)
1120 switch (papersize) {
1122 if (!paperwidth.empty())
1123 os << ",paperwidth="
1124 << from_ascii(paperwidth);
1125 if (!paperheight.empty())
1126 os << ",paperheight="
1127 << from_ascii(paperheight);
1129 case PAPER_USLETTER:
1130 os << ",letterpaper";
1133 os << ",legalpaper";
1135 case PAPER_USEXECUTIVE:
1136 os << ",executivepaper";
1157 // default papersize ie PAPER_DEFAULT
1158 switch (lyxrc.default_papersize) {
1159 case PAPER_DEFAULT: // keep compiler happy
1160 case PAPER_USLETTER:
1161 os << ",letterpaper";
1164 os << ",legalpaper";
1166 case PAPER_USEXECUTIVE:
1167 os << ",executivepaper";
1187 if (!topmargin.empty())
1188 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1189 if (!bottommargin.empty())
1190 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1191 if (!leftmargin.empty())
1192 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1193 if (!rightmargin.empty())
1194 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1195 if (!headheight.empty())
1196 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1197 if (!headsep.empty())
1198 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1199 if (!footskip.empty())
1200 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1201 if (!columnsep.empty())
1202 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1205 } else if (orientation == ORIENTATION_LANDSCAPE) {
1206 features.require("papersize");
1209 if (tokenPos(tclass.opt_pagestyle(),
1210 '|', pagestyle) >= 0) {
1211 if (pagestyle == "fancy") {
1212 os << "\\usepackage{fancyhdr}\n";
1215 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1219 // Only if class has a ToC hierarchy
1220 if (tclass.hasTocLevels()) {
1221 if (secnumdepth != tclass.secnumdepth()) {
1222 os << "\\setcounter{secnumdepth}{"
1227 if (tocdepth != tclass.tocdepth()) {
1228 os << "\\setcounter{tocdepth}{"
1235 if (paragraph_separation) {
1236 switch (getDefSkip().kind()) {
1237 case VSpace::SMALLSKIP:
1238 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1240 case VSpace::MEDSKIP:
1241 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1243 case VSpace::BIGSKIP:
1244 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1246 case VSpace::LENGTH:
1247 os << "\\setlength{\\parskip}{"
1248 << from_utf8(getDefSkip().length().asLatexString())
1251 default: // should never happen // Then delete it.
1252 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1257 os << "\\setlength{\\parindent}{0pt}\n";
1261 // Now insert the LyX specific LaTeX commands...
1262 docstring lyxpreamble;
1264 // due to interferences with babel and hyperref, the color package has to
1265 // be loaded (when it is not already loaded) before babel when hyperref
1266 // is used with the colorlinks option, see
1267 // http://bugzilla.lyx.org/show_bug.cgi?id=5291
1268 // we decided therefore to load color always before babel, see
1269 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1270 lyxpreamble += from_ascii(features.getColorOptions());
1272 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1274 && (features.isRequired("jurabib")
1275 || features.isRequired("hyperref")
1276 || features.isRequired("vietnamese")
1277 || features.isRequired("japanese") ) ) {
1279 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1280 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1283 // The optional packages;
1284 lyxpreamble += from_ascii(features.getPackages());
1287 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1290 // * Hyperref manual: "Make sure it comes last of your loaded
1291 // packages, to give it a fighting chance of not being over-written,
1292 // since its job is to redefine many LATEX commands."
1293 // * Email from Heiko Oberdiek: "It is usually better to load babel
1294 // before hyperref. Then hyperref has a chance to detect babel.
1295 // * Has to be loaded before the "LyX specific LaTeX commands" to
1296 // avoid errors with algorithm floats.
1297 // use hyperref explicitely when it is required
1298 if (features.isRequired("hyperref")) {
1299 odocstringstream oss;
1300 pdfoptions().writeLaTeX(oss, documentClass().provides("hyperref"));
1301 lyxpreamble += oss.str();
1304 // Will be surrounded by \makeatletter and \makeatother when needed
1305 docstring atlyxpreamble;
1307 // Some macros LyX will need
1308 docstring tmppreamble(from_ascii(features.getMacros()));
1310 if (!tmppreamble.empty())
1311 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1312 "LyX specific LaTeX commands.\n"
1313 + tmppreamble + '\n';
1315 // the text class specific preamble
1316 tmppreamble = features.getTClassPreamble();
1317 if (!tmppreamble.empty())
1318 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1319 "Textclass specific LaTeX commands.\n"
1320 + tmppreamble + '\n';
1322 /* the user-defined preamble */
1323 if (!preamble.empty())
1325 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1326 "User specified LaTeX commands.\n"
1327 + from_utf8(preamble) + '\n';
1329 // subfig loads internally the LaTeX package "caption". As
1330 // caption is a very popular package, users will load it in
1331 // the preamble. Therefore we must load subfig behind the
1332 // user-defined preamble and check if the caption package was
1333 // loaded or not. For the case that caption is loaded before
1334 // subfig, there is the subfig option "caption=false". This
1335 // option also works when a koma-script class is used and
1336 // koma's own caption commands are used instead of caption. We
1337 // use \PassOptionsToPackage here because the user could have
1338 // already loaded subfig in the preamble.
1339 if (features.isRequired("subfig")) {
1340 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1341 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1342 "\\usepackage{subfig}\n";
1345 // Itemize bullet settings need to be last in case the user
1346 // defines their own bullets that use a package included
1347 // in the user-defined preamble -- ARRae
1348 // Actually it has to be done much later than that
1349 // since some packages like frenchb make modifications
1350 // at \begin{document} time -- JMarc
1351 docstring bullets_def;
1352 for (int i = 0; i < 4; ++i) {
1353 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1354 if (bullets_def.empty())
1355 bullets_def += "\\AtBeginDocument{\n";
1356 bullets_def += " \\def\\labelitemi";
1358 // `i' is one less than the item to modify
1365 bullets_def += "ii";
1371 bullets_def += '{' +
1372 user_defined_bullet(i).getText()
1377 if (!bullets_def.empty())
1378 atlyxpreamble += bullets_def + "}\n\n";
1380 if (atlyxpreamble.find(from_ascii("@")) != docstring::npos)
1381 lyxpreamble += "\n\\makeatletter\n"
1382 + atlyxpreamble + "\\makeatother\n\n";
1384 lyxpreamble += '\n' + atlyxpreamble;
1386 // We try to load babel late, in case it interferes with other packages.
1387 // Jurabib and Hyperref have to be called after babel, though.
1388 if (use_babel && !features.isRequired("jurabib")
1389 && !features.isRequired("hyperref")
1390 && !features.isRequired("vietnamese")
1391 && !features.isRequired("japanese")) {
1393 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1394 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1398 int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1399 for (int j = 0; j != nlines; ++j) {
1408 void BufferParams::useClassDefaults()
1410 DocumentClass const & tclass = documentClass();
1412 sides = tclass.sides();
1413 columns = tclass.columns();
1414 pagestyle = tclass.pagestyle();
1415 options = tclass.options();
1416 // Only if class has a ToC hierarchy
1417 if (tclass.hasTocLevels()) {
1418 secnumdepth = tclass.secnumdepth();
1419 tocdepth = tclass.tocdepth();
1424 bool BufferParams::hasClassDefaults() const
1426 DocumentClass const & tclass = documentClass();
1428 return sides == tclass.sides()
1429 && columns == tclass.columns()
1430 && pagestyle == tclass.pagestyle()
1431 && options == tclass.options()
1432 && secnumdepth == tclass.secnumdepth()
1433 && tocdepth == tclass.tocdepth();
1437 DocumentClass const & BufferParams::documentClass() const
1443 DocumentClass const * BufferParams::documentClassPtr() const {
1448 void BufferParams::setDocumentClass(DocumentClass const * const tc) {
1449 // evil, but this function is evil
1450 doc_class_ = const_cast<DocumentClass *>(tc);
1454 bool BufferParams::setBaseClass(string const & classname)
1456 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1457 LayoutFileList & bcl = LayoutFileList::get();
1458 if (!bcl.haveClass(classname)) {
1460 bformat(_("The document class %1$s could not be found. "
1461 "A default textclass with default layouts will be used. "
1462 "LyX might not be able to produce output unless a correct "
1463 "textclass is selected from the document settings dialog."),
1464 from_utf8(classname));
1465 frontend::Alert::error(_("Document class not found"), s);
1466 bcl.addEmptyClass(classname);
1469 bool const success = bcl[classname].load();
1472 bformat(_("The document class %1$s could not be loaded."),
1473 from_utf8(classname));
1474 frontend::Alert::error(_("Could not load class"), s);
1478 pimpl_->baseClass_ = classname;
1480 // add any required modules not already in use
1481 set<string> const & mods = baseClass()->defaultModules();
1482 set<string>::const_iterator mit = mods.begin();
1483 set<string>::const_iterator men = mods.end();
1484 for (; mit != men; mit++) {
1485 string const & modName = *mit;
1486 // see if we're already in use
1487 if (find(layoutModules_.begin(), layoutModules_.end(), modName) !=
1488 layoutModules_.end()) {
1489 LYXERR(Debug::TCLASS, "Default module `" << modName <<
1490 "' not added because already used.");
1493 // make sure the user hasn't removed it
1494 if (find(removedModules_.begin(), removedModules_.end(), modName) !=
1495 removedModules_.end()) {
1496 LYXERR(Debug::TCLASS, "Default module `" << modName <<
1497 "' not added because removed by user.");
1500 // Now we want to check the list of selected modules to see if any of them
1501 // exclude this one.
1502 bool foundit = false;
1503 // so iterate over the selected modules...
1504 LayoutModuleList::const_iterator lit = layoutModules_.begin();
1505 LayoutModuleList::const_iterator len = layoutModules_.end();
1506 for (; lit != len; lit++) {
1507 LyXModule * lm = moduleList[*lit];
1510 vector<string> const & exc = lm->getExcludedModules();
1511 // ...and see if this one excludes us.
1512 if (find(exc.begin(), exc.end(), modName) != exc.end()) {
1514 LYXERR(Debug::TCLASS, "Default module `" << modName <<
1515 "' not added because excluded by loaded module `" <<
1521 LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
1522 layoutModules_.push_back(modName);
1529 LayoutFile const * BufferParams::baseClass() const
1531 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
1532 return &(LayoutFileList::get()[pimpl_->baseClass_]);
1538 LayoutFileIndex const & BufferParams::baseClassID() const
1540 return pimpl_->baseClass_;
1544 void BufferParams::makeDocumentClass()
1549 doc_class_ = &(DocumentClassBundle::get().newClass(*baseClass()));
1551 // FIXME It might be worth loading the children's modules here,
1552 // just as we load their bibliographies and such, instead of just
1553 // doing a check in InsetInclude.
1554 LayoutModuleList::const_iterator it = layoutModules_.begin();
1555 for (; it != layoutModules_.end(); it++) {
1556 string const modName = *it;
1557 LyXModule * lm = moduleList[modName];
1559 docstring const msg =
1560 bformat(_("The module %1$s has been requested by\n"
1561 "this document but has not been found in the list of\n"
1562 "available modules. If you recently installed it, you\n"
1563 "probably need to reconfigure LyX.\n"), from_utf8(modName));
1564 frontend::Alert::warning(_("Module not available"),
1565 msg + _("Some layouts may not be available."));
1566 LYXERR0("BufferParams::makeDocumentClass(): Module " <<
1567 modName << " requested but not found in module list.");
1570 if (!lm->isAvailable()) {
1571 docstring const msg =
1572 bformat(_("The module %1$s requires a package that is\n"
1573 "not available in your LaTeX installation. LaTeX output\n"
1574 "may not be possible.\n"), from_utf8(modName));
1575 frontend::Alert::warning(_("Package not available"), msg);
1577 FileName layout_file = libFileSearch("layouts", lm->getFilename());
1578 if (!doc_class_->read(layout_file, TextClass::MODULE)) {
1579 docstring const msg =
1580 bformat(_("Error reading module %1$s\n"), from_utf8(modName));
1581 frontend::Alert::warning(_("Read Error"), msg);
1584 if (!local_layout.empty()) {
1585 if (!doc_class_->read(local_layout, TextClass::MODULE)) {
1586 docstring const msg = _("Error reading internal layout information");
1587 frontend::Alert::warning(_("Read Error"), msg);
1593 bool BufferParams::addLayoutModule(string const & modName)
1595 LayoutModuleList::const_iterator it = layoutModules_.begin();
1596 LayoutModuleList::const_iterator end = layoutModules_.end();
1597 for (; it != end; it++)
1600 layoutModules_.push_back(modName);
1605 Font const BufferParams::getFont() const
1607 FontInfo f = documentClass().defaultfont();
1608 if (fontsDefaultFamily == "rmdefault")
1609 f.setFamily(ROMAN_FAMILY);
1610 else if (fontsDefaultFamily == "sfdefault")
1611 f.setFamily(SANS_FAMILY);
1612 else if (fontsDefaultFamily == "ttdefault")
1613 f.setFamily(TYPEWRITER_FAMILY);
1614 return Font(f, language);
1618 void BufferParams::readPreamble(Lexer & lex)
1620 if (lex.getString() != "\\begin_preamble")
1621 lyxerr << "Error (BufferParams::readPreamble):"
1622 "consistency check failed." << endl;
1624 preamble = lex.getLongString("\\end_preamble");
1628 void BufferParams::readLocalLayout(Lexer & lex)
1630 if (lex.getString() != "\\begin_local_layout")
1631 lyxerr << "Error (BufferParams::readLocalLayout):"
1632 "consistency check failed." << endl;
1634 local_layout = lex.getLongString("\\end_local_layout");
1638 void BufferParams::readLanguage(Lexer & lex)
1640 if (!lex.next()) return;
1642 string const tmptok = lex.getString();
1644 // check if tmptok is part of tex_babel in tex-defs.h
1645 language = languages.getLanguage(tmptok);
1647 // Language tmptok was not found
1648 language = default_language;
1649 lyxerr << "Warning: Setting language `"
1650 << tmptok << "' to `" << language->lang()
1656 void BufferParams::readGraphicsDriver(Lexer & lex)
1661 string const tmptok = lex.getString();
1662 // check if tmptok is part of tex_graphics in tex_defs.h
1665 string const test = tex_graphics[n++];
1667 if (test == tmptok) {
1668 graphicsDriver = tmptok;
1673 "Warning: graphics driver `$$Token' not recognized!\n"
1674 " Setting graphics driver to `default'.\n");
1675 graphicsDriver = "default";
1682 void BufferParams::readBullets(Lexer & lex)
1687 int const index = lex.getInteger();
1689 int temp_int = lex.getInteger();
1690 user_defined_bullet(index).setFont(temp_int);
1691 temp_bullet(index).setFont(temp_int);
1693 user_defined_bullet(index).setCharacter(temp_int);
1694 temp_bullet(index).setCharacter(temp_int);
1696 user_defined_bullet(index).setSize(temp_int);
1697 temp_bullet(index).setSize(temp_int);
1701 void BufferParams::readBulletsLaTeX(Lexer & lex)
1703 // The bullet class should be able to read this.
1706 int const index = lex.getInteger();
1708 docstring const temp_str = lex.getDocString();
1710 user_defined_bullet(index).setText(temp_str);
1711 temp_bullet(index).setText(temp_str);
1715 void BufferParams::readModules(Lexer & lex)
1717 if (!lex.eatLine()) {
1718 lyxerr << "Error (BufferParams::readModules):"
1719 "Unexpected end of input." << endl;
1723 string mod = lex.getString();
1724 if (mod == "\\end_modules")
1726 addLayoutModule(mod);
1732 void BufferParams::readRemovedModules(Lexer & lex)
1734 if (!lex.eatLine()) {
1735 lyxerr << "Error (BufferParams::readRemovedModules):"
1736 "Unexpected end of input." << endl;
1740 string mod = lex.getString();
1741 if (mod == "\\end_removed_modules")
1743 removedModules_.insert(mod);
1746 // now we want to remove any removed modules that were previously
1747 // added. normally, that will be because default modules were added in
1748 // setBaseClass(), which gets called when \textclass is read at the
1749 // start of the read.
1750 set<string>::const_iterator rit = removedModules_.begin();
1751 set<string>::const_iterator const ren = removedModules_.end();
1752 for (; rit != ren; rit++) {
1753 LayoutModuleList::iterator const mit = layoutModules_.begin();
1754 LayoutModuleList::iterator const men = layoutModules_.end();
1755 LayoutModuleList::iterator found = find(mit, men, *rit);
1758 layoutModules_.erase(found);
1763 string BufferParams::paperSizeName(PapersizePurpose purpose) const
1765 char real_papersize = papersize;
1766 if (real_papersize == PAPER_DEFAULT)
1767 real_papersize = lyxrc.default_papersize;
1769 switch (real_papersize) {
1771 // could be anything, so don't guess
1773 case PAPER_CUSTOM: {
1774 if (purpose == XDVI && !paperwidth.empty() &&
1775 !paperheight.empty()) {
1776 // heightxwidth<unit>
1777 string first = paperwidth;
1778 string second = paperheight;
1779 if (orientation == ORIENTATION_LANDSCAPE)
1782 return first.erase(first.length() - 2)
1794 // dvips and dvipdfm do not know this
1795 if (purpose == DVIPS || purpose == DVIPDFM)
1799 // dvipdfm does not know this
1800 if (purpose == DVIPDFM)
1804 // dvipdfm does not know this
1805 if (purpose == DVIPDFM)
1808 case PAPER_USEXECUTIVE:
1809 // dvipdfm does not know this
1810 if (purpose == DVIPDFM)
1815 case PAPER_USLETTER:
1817 if (purpose == XDVI)
1824 string const BufferParams::dvips_options() const
1829 && papersize == PAPER_CUSTOM
1830 && !lyxrc.print_paper_dimension_flag.empty()
1831 && !paperwidth.empty()
1832 && !paperheight.empty()) {
1833 // using a custom papersize
1834 result = lyxrc.print_paper_dimension_flag;
1835 result += ' ' + paperwidth;
1836 result += ',' + paperheight;
1838 string const paper_option = paperSizeName(DVIPS);
1839 if (!paper_option.empty() && (paper_option != "letter" ||
1840 orientation != ORIENTATION_LANDSCAPE)) {
1841 // dvips won't accept -t letter -t landscape.
1842 // In all other cases, include the paper size
1844 result = lyxrc.print_paper_flag;
1845 result += ' ' + paper_option;
1848 if (orientation == ORIENTATION_LANDSCAPE &&
1849 papersize != PAPER_CUSTOM)
1850 result += ' ' + lyxrc.print_landscape_flag;
1855 string BufferParams::babelCall(string const & lang_opts) const
1857 string lang_pack = lyxrc.language_package;
1858 if (lang_pack != "\\usepackage{babel}")
1860 // suppress the babel call when there is no babel language defined
1861 // for the document language in the lib/languages file and if no
1862 // other languages are used (lang_opts is then empty)
1863 if (lang_opts.empty())
1865 // If Vietnamese is used, babel must directly be loaded with the
1866 // language options, see
1867 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
1868 size_t viet = lang_opts.find("vietnam");
1869 // viet = string::npos when not found
1870 // If Japanese is used, babel must directly be loaded with the
1871 // language options, see
1872 // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
1873 size_t japan = lang_opts.find("japanese");
1874 // japan = string::npos when not found
1875 if (!lyxrc.language_global_options || viet != string::npos || japan != string::npos)
1876 return "\\usepackage[" + lang_opts + "]{babel}";
1881 void BufferParams::writeEncodingPreamble(odocstream & os,
1882 LaTeXFeatures & features, TexRow & texrow) const
1884 if (inputenc == "auto") {
1885 string const doc_encoding =
1886 language->encoding()->latexName();
1887 Encoding::Package const package =
1888 language->encoding()->package();
1890 // Create a list with all the input encodings used
1892 set<string> encodings =
1893 features.getEncodingSet(doc_encoding);
1895 // If the "japanese" package (i.e. pLaTeX) is used,
1896 // inputenc must be omitted.
1897 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
1898 if (package == Encoding::japanese)
1899 features.require("japanese");
1901 if ((!encodings.empty() || package == Encoding::inputenc)
1902 && !features.isRequired("japanese")) {
1903 os << "\\usepackage[";
1904 set<string>::const_iterator it = encodings.begin();
1905 set<string>::const_iterator const end = encodings.end();
1907 os << from_ascii(*it);
1910 for (; it != end; ++it)
1911 os << ',' << from_ascii(*it);
1912 if (package == Encoding::inputenc) {
1913 if (!encodings.empty())
1915 os << from_ascii(doc_encoding);
1917 os << "]{inputenc}\n";
1920 if (package == Encoding::CJK || features.mustProvide("CJK")) {
1921 os << "\\usepackage{CJK}\n";
1924 } else if (inputenc != "default") {
1925 switch (encoding().package()) {
1926 case Encoding::none:
1927 case Encoding::japanese:
1929 case Encoding::inputenc:
1930 // do not load inputenc if japanese is used
1931 if (features.isRequired("japanese"))
1933 os << "\\usepackage[" << from_ascii(inputenc)
1938 os << "\\usepackage{CJK}\n";
1944 // The encoding "armscii8" (for Armenian) is only available when
1945 // the package "armtex" is loaded.
1946 if (language->encoding()->latexName() == "armscii8"
1947 || inputenc == "armscii8") {
1948 os << "\\usepackage{armtex}\n";
1954 string const BufferParams::loadFonts(string const & rm,
1955 string const & sf, string const & tt,
1956 bool const & sc, bool const & osf,
1957 int const & sfscale, int const & ttscale) const
1959 /* The LaTeX font world is in a flux. In the PSNFSS font interface,
1960 several packages have been replaced by others, that might not
1961 be installed on every system. We have to take care for that
1962 (see psnfss.pdf). We try to support all psnfss fonts as well
1963 as the fonts that have become de facto standard in the LaTeX
1964 world (e.g. Latin Modern). We do not support obsolete fonts
1965 (like PSLatex). In general, it should be possible to mix any
1966 rm font with any sf or tt font, respectively. (JSpitzm)
1968 -- separate math fonts.
1971 if (rm == "default" && sf == "default" && tt == "default")
1978 // Computer Modern (must be explicitely selectable -- there might be classes
1979 // that define a different default font!
1981 os << "\\renewcommand{\\rmdefault}{cmr}\n";
1982 // osf for Computer Modern needs eco.sty
1984 os << "\\usepackage{eco}\n";
1986 // Latin Modern Roman
1987 else if (rm == "lmodern")
1988 os << "\\usepackage{lmodern}\n";
1990 else if (rm == "ae") {
1991 // not needed when using OT1 font encoding.
1992 if (lyxrc.fontenc != "default")
1993 os << "\\usepackage{ae,aecompl}\n";
1996 else if (rm == "times") {
1997 // try to load the best available package
1998 if (LaTeXFeatures::isAvailable("mathptmx"))
1999 os << "\\usepackage{mathptmx}\n";
2000 else if (LaTeXFeatures::isAvailable("mathptm"))
2001 os << "\\usepackage{mathptm}\n";
2003 os << "\\usepackage{times}\n";
2006 else if (rm == "palatino") {
2007 // try to load the best available package
2008 if (LaTeXFeatures::isAvailable("mathpazo")) {
2009 os << "\\usepackage";
2015 // "osf" includes "sc"!
2019 os << "{mathpazo}\n";
2021 else if (LaTeXFeatures::isAvailable("mathpple"))
2022 os << "\\usepackage{mathpple}\n";
2024 os << "\\usepackage{palatino}\n";
2027 else if (rm == "utopia") {
2028 // fourier supersedes utopia.sty, but does
2029 // not work with OT1 encoding.
2030 if (LaTeXFeatures::isAvailable("fourier")
2031 && lyxrc.fontenc != "default") {
2032 os << "\\usepackage";
2043 os << "{fourier}\n";
2046 os << "\\usepackage{utopia}\n";
2048 // Bera (complete fontset)
2049 else if (rm == "bera" && sf == "default" && tt == "default")
2050 os << "\\usepackage{bera}\n";
2052 else if (rm != "default")
2053 os << "\\usepackage" << "{" << rm << "}\n";
2056 // Helvetica, Bera Sans
2057 if (sf == "helvet" || sf == "berasans") {
2059 os << "\\usepackage[scaled=" << float(sfscale) / 100
2060 << "]{" << sf << "}\n";
2062 os << "\\usepackage{" << sf << "}\n";
2065 else if (sf == "avant")
2066 os << "\\usepackage{" << sf << "}\n";
2067 // Computer Modern, Latin Modern, CM Bright
2068 else if (sf != "default")
2069 os << "\\renewcommand{\\sfdefault}{" << sf << "}\n";
2071 // monospaced/typewriter
2072 // Courier, LuxiMono
2073 if (tt == "luximono" || tt == "beramono") {
2075 os << "\\usepackage[scaled=" << float(ttscale) / 100
2076 << "]{" << tt << "}\n";
2078 os << "\\usepackage{" << tt << "}\n";
2081 else if (tt == "courier" )
2082 os << "\\usepackage{" << tt << "}\n";
2083 // Computer Modern, Latin Modern, CM Bright
2084 else if (tt != "default")
2085 os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
2091 Encoding const & BufferParams::encoding() const
2093 if (inputenc == "auto" || inputenc == "default")
2094 return *language->encoding();
2095 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2098 LYXERR0("Unknown inputenc value `" << inputenc
2099 << "'. Using `auto' instead.");
2100 return *language->encoding();
2104 CiteEngine BufferParams::citeEngine() const
2106 // FIXME the class should provide the numerical/
2107 // authoryear choice
2108 if (documentClass().provides("natbib")
2109 && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
2110 return ENGINE_NATBIB_AUTHORYEAR;
2111 return cite_engine_;
2115 void BufferParams::setCiteEngine(CiteEngine cite_engine)
2117 cite_engine_ = cite_engine;