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;
338 use_default_options = true;
341 language = default_language;
342 fontsRoman = "default";
343 fontsSans = "default";
344 fontsTypewriter = "default";
345 fontsDefaultFamily = "default";
348 fontsSansScale = 100;
349 fontsTypewriterScale = 100;
351 graphicsDriver = "default";
354 listings_params = string();
355 pagestyle = "default";
357 for (int iter = 0; iter < 4; ++iter) {
358 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
359 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
364 docstring BufferParams::B_(string const & l10n) const
366 LASSERT(language, /**/);
367 return getMessages(language->code()).get(l10n);
371 AuthorList & BufferParams::authors()
373 return pimpl_->authorlist;
377 AuthorList const & BufferParams::authors() const
379 return pimpl_->authorlist;
383 BranchList & BufferParams::branchlist()
385 return pimpl_->branchlist;
389 BranchList const & BufferParams::branchlist() const
391 return pimpl_->branchlist;
395 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
397 LASSERT(index < 4, /**/);
398 return pimpl_->temp_bullets[index];
402 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
404 LASSERT(index < 4, /**/);
405 return pimpl_->temp_bullets[index];
409 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
411 LASSERT(index < 4, /**/);
412 return pimpl_->user_defined_bullets[index];
416 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
418 LASSERT(index < 4, /**/);
419 return pimpl_->user_defined_bullets[index];
423 Spacing & BufferParams::spacing()
425 return pimpl_->spacing;
429 Spacing const & BufferParams::spacing() const
431 return pimpl_->spacing;
435 PDFOptions & BufferParams::pdfoptions()
437 return pimpl_->pdfoptions;
441 PDFOptions const & BufferParams::pdfoptions() const
443 return pimpl_->pdfoptions;
447 VSpace const & BufferParams::getDefSkip() const
449 return pimpl_->defskip;
453 void BufferParams::setDefSkip(VSpace const & vs)
455 pimpl_->defskip = vs;
459 string BufferParams::readToken(Lexer & lex, string const & token,
460 FileName const & filepath)
462 if (token == "\\textclass") {
464 string const classname = lex.getString();
465 // if there exists a local layout file, ignore the system one
466 // NOTE: in this case, the textclass (.cls file) is assumed to be available.
468 LayoutFileList & bcl = LayoutFileList::get();
469 if (tcp.empty() && !filepath.empty())
470 tcp = bcl.addLocalLayout(classname, filepath.absFilename());
474 setBaseClass(classname);
475 // We assume that a tex class exists for local or unknown layouts so this warning
476 // will only be given for system layouts.
477 if (!baseClass()->isTeXClassAvailable()) {
478 docstring const msg =
479 bformat(_("The layout file requested by this document,\n"
481 "is not usable. This is probably because a LaTeX\n"
482 "class or style file required by it is not\n"
483 "available. See the Customization documentation\n"
484 "for more information.\n"), from_utf8(classname));
485 frontend::Alert::warning(_("Document class not available"),
486 msg + _("LyX will not be able to produce output."));
488 } else if (token == "\\begin_preamble") {
490 } else if (token == "\\begin_local_layout") {
491 readLocalLayout(lex);
492 } else if (token == "\\begin_modules") {
494 } else if (token == "\\begin_removed_modules") {
495 readRemovedModules(lex);
496 } else if (token == "\\options") {
498 options = lex.getString();
499 } else if (token == "\\use_default_options") {
500 lex >> use_default_options;
501 } else if (token == "\\master") {
503 master = lex.getString();
504 } else if (token == "\\language") {
506 } else if (token == "\\inputencoding") {
508 } else if (token == "\\graphics") {
509 readGraphicsDriver(lex);
510 } else if (token == "\\font_roman") {
512 } else if (token == "\\font_sans") {
514 } else if (token == "\\font_typewriter") {
515 lex >> fontsTypewriter;
516 } else if (token == "\\font_default_family") {
517 lex >> fontsDefaultFamily;
518 } else if (token == "\\font_sc") {
520 } else if (token == "\\font_osf") {
522 } else if (token == "\\font_sf_scale") {
523 lex >> fontsSansScale;
524 } else if (token == "\\font_tt_scale") {
525 lex >> fontsTypewriterScale;
526 } else if (token == "\\font_cjk") {
528 } else if (token == "\\paragraph_separation") {
531 paragraph_separation = parseptranslator().find(parsep);
532 } else if (token == "\\defskip") {
534 string defskip = lex.getString();
535 if (defskip == "defskip")
538 pimpl_->defskip = VSpace(defskip);
539 } else if (token == "\\quotes_language") {
542 quotes_language = quoteslangtranslator().find(quotes_lang);
543 } else if (token == "\\papersize") {
546 papersize = papersizetranslator().find(ppsize);
547 } else if (token == "\\use_geometry") {
549 } else if (token == "\\use_amsmath") {
552 use_amsmath = packagetranslator().find(use_ams);
553 } else if (token == "\\use_esint") {
556 use_esint = packagetranslator().find(useesint);
557 } else if (token == "\\cite_engine") {
560 cite_engine_ = citeenginetranslator().find(engine);
561 } else if (token == "\\use_bibtopic") {
563 } else if (token == "\\tracking_changes") {
565 } else if (token == "\\output_changes") {
566 lex >> outputChanges;
567 } else if (token == "\\branch") {
569 docstring branch = lex.getDocString();
570 branchlist().add(branch);
573 string const tok = lex.getString();
574 if (tok == "\\end_branch")
576 Branch * branch_ptr = branchlist().find(branch);
577 if (tok == "\\selected") {
580 branch_ptr->setSelected(lex.getInteger());
582 // not yet operational
583 if (tok == "\\color") {
585 string color = lex.getString();
587 branch_ptr->setColor(color);
588 // Update also the Color table:
590 color = lcolor.getX11Name(Color_background);
592 lcolor.setColor(to_utf8(branch), color);
596 } else if (token == "\\author") {
598 istringstream ss(lex.getString());
601 author_map.push_back(pimpl_->authorlist.record(a));
602 } else if (token == "\\paperorientation") {
605 orientation = paperorientationtranslator().find(orient);
606 } else if (token == "\\paperwidth") {
608 } else if (token == "\\paperheight") {
610 } else if (token == "\\leftmargin") {
612 } else if (token == "\\topmargin") {
614 } else if (token == "\\rightmargin") {
616 } else if (token == "\\bottommargin") {
618 } else if (token == "\\headheight") {
620 } else if (token == "\\headsep") {
622 } else if (token == "\\footskip") {
624 } else if (token == "\\columnsep") {
626 } else if (token == "\\paperfontsize") {
628 } else if (token == "\\papercolumns") {
630 } else if (token == "\\listings_params") {
633 listings_params = InsetListingsParams(par).params();
634 } else if (token == "\\papersides") {
637 sides = sidestranslator().find(psides);
638 } else if (token == "\\paperpagestyle") {
640 } else if (token == "\\bullet") {
642 } else if (token == "\\bulletLaTeX") {
643 readBulletsLaTeX(lex);
644 } else if (token == "\\secnumdepth") {
646 } else if (token == "\\tocdepth") {
648 } else if (token == "\\spacing") {
652 if (nspacing == "other") {
655 spacing().set(spacetranslator().find(nspacing), tmp_val);
656 } else if (token == "\\float_placement") {
657 lex >> float_placement;
659 } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
660 string toktmp = pdfoptions().readToken(lex, token);
661 if (!toktmp.empty()) {
662 lyxerr << "PDFOptions::readToken(): Unknown token: " <<
667 lyxerr << "BufferParams::readToken(): Unknown token: " <<
676 void BufferParams::writeFile(ostream & os) const
678 // The top of the file is written by the buffer.
679 // Prints out the buffer info into the .lyx file given by file
682 os << "\\textclass " << baseClass()->name() << '\n';
685 if (!preamble.empty()) {
686 // remove '\n' from the end of preamble
687 string const tmppreamble = rtrim(preamble, "\n");
688 os << "\\begin_preamble\n"
690 << "\n\\end_preamble\n";
694 if (!options.empty()) {
695 os << "\\options " << options << '\n';
698 // use the class options defined in the layout?
699 os << "\\use_default_options "
700 << convert<string>(use_default_options) << "\n";
702 // the master document
703 if (!master.empty()) {
704 os << "\\master " << master << '\n';
708 if (!removedModules_.empty()) {
709 os << "\\begin_removed_modules" << '\n';
710 set<string>::const_iterator it = removedModules_.begin();
711 set<string>::const_iterator en = removedModules_.end();
712 for (; it != en; it++)
714 os << "\\end_removed_modules" << '\n';
718 if (!layoutModules_.empty()) {
719 os << "\\begin_modules" << '\n';
720 LayoutModuleList::const_iterator it = layoutModules_.begin();
721 LayoutModuleList::const_iterator en = layoutModules_.end();
722 for (; it != en; it++)
724 os << "\\end_modules" << '\n';
727 // local layout information
728 if (!local_layout.empty()) {
729 // remove '\n' from the end
730 string const tmplocal = rtrim(local_layout, "\n");
731 os << "\\begin_local_layout\n"
733 << "\n\\end_local_layout\n";
736 // then the text parameters
737 if (language != ignore_language)
738 os << "\\language " << language->lang() << '\n';
739 os << "\\inputencoding " << inputenc
740 << "\n\\font_roman " << fontsRoman
741 << "\n\\font_sans " << fontsSans
742 << "\n\\font_typewriter " << fontsTypewriter
743 << "\n\\font_default_family " << fontsDefaultFamily
744 << "\n\\font_sc " << convert<string>(fontsSC)
745 << "\n\\font_osf " << convert<string>(fontsOSF)
746 << "\n\\font_sf_scale " << fontsSansScale
747 << "\n\\font_tt_scale " << fontsTypewriterScale
749 if (!fontsCJK.empty()) {
750 os << "\\font_cjk " << fontsCJK << '\n';
752 os << "\n\\graphics " << graphicsDriver << '\n';
754 if (!float_placement.empty()) {
755 os << "\\float_placement " << float_placement << '\n';
757 os << "\\paperfontsize " << fontsize << '\n';
759 spacing().writeFile(os);
760 pdfoptions().writeFile(os);
762 os << "\\papersize " << string_papersize[papersize]
763 << "\n\\use_geometry " << convert<string>(use_geometry)
764 << "\n\\use_amsmath " << use_amsmath
765 << "\n\\use_esint " << use_esint
766 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
767 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
768 << "\n\\paperorientation " << string_orientation[orientation]
771 BranchList::const_iterator it = branchlist().begin();
772 BranchList::const_iterator end = branchlist().end();
773 for (; it != end; ++it) {
774 os << "\\branch " << to_utf8(it->branch())
775 << "\n\\selected " << it->isSelected()
776 << "\n\\color " << lyx::X11hexname(it->color())
781 if (!paperwidth.empty())
782 os << "\\paperwidth "
783 << VSpace(paperwidth).asLyXCommand() << '\n';
784 if (!paperheight.empty())
785 os << "\\paperheight "
786 << VSpace(paperheight).asLyXCommand() << '\n';
787 if (!leftmargin.empty())
788 os << "\\leftmargin "
789 << VSpace(leftmargin).asLyXCommand() << '\n';
790 if (!topmargin.empty())
792 << VSpace(topmargin).asLyXCommand() << '\n';
793 if (!rightmargin.empty())
794 os << "\\rightmargin "
795 << VSpace(rightmargin).asLyXCommand() << '\n';
796 if (!bottommargin.empty())
797 os << "\\bottommargin "
798 << VSpace(bottommargin).asLyXCommand() << '\n';
799 if (!headheight.empty())
800 os << "\\headheight "
801 << VSpace(headheight).asLyXCommand() << '\n';
802 if (!headsep.empty())
804 << VSpace(headsep).asLyXCommand() << '\n';
805 if (!footskip.empty())
807 << VSpace(footskip).asLyXCommand() << '\n';
808 if (!columnsep.empty())
810 << VSpace(columnsep).asLyXCommand() << '\n';
811 os << "\\secnumdepth " << secnumdepth
812 << "\n\\tocdepth " << tocdepth
813 << "\n\\paragraph_separation "
814 << string_paragraph_separation[paragraph_separation]
815 << "\n\\defskip " << getDefSkip().asLyXCommand()
816 << "\n\\quotes_language "
817 << string_quotes_language[quotes_language]
818 << "\n\\papercolumns " << columns
819 << "\n\\papersides " << sides
820 << "\n\\paperpagestyle " << pagestyle << '\n';
821 if (!listings_params.empty())
822 os << "\\listings_params \"" <<
823 InsetListingsParams(listings_params).encodedString() << "\"\n";
824 for (int i = 0; i < 4; ++i) {
825 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
826 if (user_defined_bullet(i).getFont() != -1) {
827 os << "\\bullet " << i << " "
828 << user_defined_bullet(i).getFont() << " "
829 << user_defined_bullet(i).getCharacter() << " "
830 << user_defined_bullet(i).getSize() << "\n";
834 os << "\\bulletLaTeX " << i << " \""
835 << lyx::to_ascii(user_defined_bullet(i).getText())
841 os << "\\tracking_changes " << convert<string>(trackChanges) << "\n";
842 os << "\\output_changes " << convert<string>(outputChanges) << "\n";
844 AuthorList::Authors::const_iterator a_it = pimpl_->authorlist.begin();
845 AuthorList::Authors::const_iterator a_end = pimpl_->authorlist.end();
846 for (; a_it != a_end; ++a_it) {
847 if (a_it->second.used())
848 os << "\\author " << a_it->second << "\n";
850 os << "\\author " << Author() << "\n";
855 void BufferParams::validate(LaTeXFeatures & features) const
857 features.require(documentClass().requires());
860 bool dvipost = LaTeXFeatures::isAvailable("dvipost");
861 bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
862 LaTeXFeatures::isAvailable("xcolor");
864 switch (features.runparams().flavor) {
865 case OutputParams::LATEX:
867 features.require("ct-dvipost");
868 features.require("dvipost");
869 } else if (xcolorsoul) {
870 features.require("ct-xcolor-soul");
871 features.require("soul");
872 features.require("xcolor");
874 features.require("ct-none");
877 case OutputParams::PDFLATEX:
879 features.require("ct-xcolor-soul");
880 features.require("soul");
881 features.require("xcolor");
882 // improves color handling in PDF output
883 features.require("pdfcolmk");
885 features.require("ct-none");
893 // Floats with 'Here definitely' as default setting.
894 if (float_placement.find('H') != string::npos)
895 features.require("float");
897 // AMS Style is at document level
898 if (use_amsmath == package_on
899 || documentClass().provides("amsmath"))
900 features.require("amsmath");
901 if (use_esint == package_on)
902 features.require("esint");
904 // Document-level line spacing
905 if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
906 features.require("setspace");
908 // the bullet shapes are buffer level not paragraph level
909 // so they are tested here
910 for (int i = 0; i < 4; ++i) {
911 if (user_defined_bullet(i) == ITEMIZE_DEFAULTS[i])
913 int const font = user_defined_bullet(i).getFont();
915 int const c = user_defined_bullet(i).getCharacter();
921 features.require("latexsym");
923 } else if (font == 1) {
924 features.require("amssymb");
925 } else if (font >= 2 && font <= 5) {
926 features.require("pifont");
930 if (pdfoptions().use_hyperref) {
931 features.require("hyperref");
932 // due to interferences with babel and hyperref, the color package has to
933 // be loaded after hyperref when hyperref is used with the colorlinks
934 // option, see http://bugzilla.lyx.org/show_bug.cgi?id=5291
935 if (pdfoptions().colorlinks)
936 features.require("color");
939 if (language->lang() == "vietnamese")
940 features.require("vietnamese");
941 else if (language->lang() == "japanese")
942 features.require("japanese");
946 bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
947 TexRow & texrow) const
949 os << "\\documentclass";
951 DocumentClass const & tclass = documentClass();
953 ostringstream clsoptions; // the document class options.
955 if (tokenPos(tclass.opt_fontsize(),
956 '|', fontsize) >= 0) {
957 // only write if existing in list (and not default)
958 clsoptions << fontsize << "pt,";
961 // custom, A3, B3 and B4 paper sizes need geometry
962 bool nonstandard_papersize = papersize == PAPER_B3
963 || papersize == PAPER_B4
964 || papersize == PAPER_A3
965 || papersize == PAPER_CUSTOM;
970 clsoptions << "a4paper,";
973 clsoptions << "letterpaper,";
976 clsoptions << "a5paper,";
979 clsoptions << "b5paper,";
981 case PAPER_USEXECUTIVE:
982 clsoptions << "executivepaper,";
985 clsoptions << "legalpaper,";
997 if (sides != tclass.sides()) {
1000 clsoptions << "oneside,";
1003 clsoptions << "twoside,";
1009 if (columns != tclass.columns()) {
1011 clsoptions << "twocolumn,";
1013 clsoptions << "onecolumn,";
1017 && orientation == ORIENTATION_LANDSCAPE)
1018 clsoptions << "landscape,";
1020 // language should be a parameter to \documentclass
1021 if (language->babel() == "hebrew"
1022 && default_language->babel() != "hebrew")
1023 // This seems necessary
1024 features.useLanguage(default_language);
1026 ostringstream language_options;
1027 bool const use_babel = features.useBabel();
1029 language_options << features.getLanguages();
1030 if (!language->babel().empty()) {
1031 if (!language_options.str().empty())
1032 language_options << ',';
1033 language_options << language->babel();
1035 // if Vietnamese is used, babel must directly be loaded
1036 // with language options, not in the class options, see
1037 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
1038 size_t viet = language_options.str().find("vietnam");
1039 // viet = string::npos when not found
1040 // the same is for all other languages that are not directly supported by
1041 // babel, but where LaTeX-packages add babel support.
1042 // this is currently the case for Latvian, Lithuanian, and Mongolian
1043 size_t latvian = language_options.str().find("latvian");
1044 size_t lithu = language_options.str().find("lithuanian");
1045 size_t mongo = language_options.str().find("mongolian");
1046 // if Japanese is used, babel must directly be loaded
1047 // with language options, not in the class options, see
1048 // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
1049 size_t japan = language_options.str().find("japanese");
1050 if (lyxrc.language_global_options && !language_options.str().empty()
1051 && viet == string::npos && japan == string::npos
1052 && latvian == string::npos && lithu == string::npos
1053 && mongo == string::npos)
1054 clsoptions << language_options.str() << ',';
1057 // the predefined options from the layout
1058 if (use_default_options && !tclass.options().empty())
1059 clsoptions << tclass.options() << ',';
1061 // the user-defined options
1062 if (!options.empty()) {
1063 clsoptions << options << ',';
1066 string strOptions(clsoptions.str());
1067 if (!strOptions.empty()) {
1068 strOptions = rtrim(strOptions, ",");
1070 os << '[' << from_utf8(strOptions) << ']';
1073 os << '{' << from_ascii(tclass.latexname()) << "}\n";
1075 // end of \documentclass defs
1077 // font selection must be done before loading fontenc.sty
1078 string const fonts =
1079 loadFonts(fontsRoman, fontsSans,
1080 fontsTypewriter, fontsSC, fontsOSF,
1081 fontsSansScale, fontsTypewriterScale);
1082 if (!fonts.empty()) {
1083 os << from_ascii(fonts);
1086 if (fontsDefaultFamily != "default")
1087 os << "\\renewcommand{\\familydefault}{\\"
1088 << from_ascii(fontsDefaultFamily) << "}\n";
1090 // set font encoding
1091 // this one is not per buffer
1092 // for arabic_arabi and farsi we also need to load the LAE and
1094 if (lyxrc.fontenc != "default" && language->lang() != "japanese") {
1095 if (language->lang() == "arabic_arabi"
1096 || language->lang() == "farsi") {
1097 os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
1098 << ",LFE,LAE]{fontenc}\n";
1101 os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
1107 // handle inputenc etc.
1108 writeEncodingPreamble(os, features, texrow);
1110 if (!listings_params.empty() || features.isRequired("listings")) {
1111 os << "\\usepackage{listings}\n";
1114 if (!listings_params.empty()) {
1116 // do not test validity because listings_params is
1117 // supposed to be valid
1119 InsetListingsParams(listings_params).separatedParams(true);
1120 // we can't support all packages, but we should load the color package
1121 if (par.find("\\color", 0) != string::npos)
1122 features.require("color");
1123 os << from_utf8(par);
1124 // count the number of newlines
1125 for (size_t i = 0; i < par.size(); ++i)
1131 if (use_geometry || nonstandard_papersize) {
1132 os << "\\usepackage{geometry}\n";
1134 os << "\\geometry{verbose";
1135 if (orientation == ORIENTATION_LANDSCAPE)
1137 switch (papersize) {
1139 if (!paperwidth.empty())
1140 os << ",paperwidth="
1141 << from_ascii(paperwidth);
1142 if (!paperheight.empty())
1143 os << ",paperheight="
1144 << from_ascii(paperheight);
1146 case PAPER_USLETTER:
1147 os << ",letterpaper";
1150 os << ",legalpaper";
1152 case PAPER_USEXECUTIVE:
1153 os << ",executivepaper";
1174 // default papersize ie PAPER_DEFAULT
1175 switch (lyxrc.default_papersize) {
1176 case PAPER_DEFAULT: // keep compiler happy
1177 case PAPER_USLETTER:
1178 os << ",letterpaper";
1181 os << ",legalpaper";
1183 case PAPER_USEXECUTIVE:
1184 os << ",executivepaper";
1204 if (!topmargin.empty())
1205 os << ",tmargin=" << from_ascii(Length(topmargin).asLatexString());
1206 if (!bottommargin.empty())
1207 os << ",bmargin=" << from_ascii(Length(bottommargin).asLatexString());
1208 if (!leftmargin.empty())
1209 os << ",lmargin=" << from_ascii(Length(leftmargin).asLatexString());
1210 if (!rightmargin.empty())
1211 os << ",rmargin=" << from_ascii(Length(rightmargin).asLatexString());
1212 if (!headheight.empty())
1213 os << ",headheight=" << from_ascii(Length(headheight).asLatexString());
1214 if (!headsep.empty())
1215 os << ",headsep=" << from_ascii(Length(headsep).asLatexString());
1216 if (!footskip.empty())
1217 os << ",footskip=" << from_ascii(Length(footskip).asLatexString());
1218 if (!columnsep.empty())
1219 os << ",columnsep=" << from_ascii(Length(columnsep).asLatexString());
1222 } else if (orientation == ORIENTATION_LANDSCAPE) {
1223 features.require("papersize");
1226 if (tokenPos(tclass.opt_pagestyle(),
1227 '|', pagestyle) >= 0) {
1228 if (pagestyle == "fancy") {
1229 os << "\\usepackage{fancyhdr}\n";
1232 os << "\\pagestyle{" << from_ascii(pagestyle) << "}\n";
1236 // Only if class has a ToC hierarchy
1237 if (tclass.hasTocLevels()) {
1238 if (secnumdepth != tclass.secnumdepth()) {
1239 os << "\\setcounter{secnumdepth}{"
1244 if (tocdepth != tclass.tocdepth()) {
1245 os << "\\setcounter{tocdepth}{"
1252 if (paragraph_separation) {
1253 switch (getDefSkip().kind()) {
1254 case VSpace::SMALLSKIP:
1255 os << "\\setlength{\\parskip}{\\smallskipamount}\n";
1257 case VSpace::MEDSKIP:
1258 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1260 case VSpace::BIGSKIP:
1261 os << "\\setlength{\\parskip}{\\bigskipamount}\n";
1263 case VSpace::LENGTH:
1264 os << "\\setlength{\\parskip}{"
1265 << from_utf8(getDefSkip().length().asLatexString())
1268 default: // should never happen // Then delete it.
1269 os << "\\setlength{\\parskip}{\\medskipamount}\n";
1274 os << "\\setlength{\\parindent}{0pt}\n";
1278 // Now insert the LyX specific LaTeX commands...
1279 docstring lyxpreamble;
1281 // due to interferences with babel and hyperref, the color package has to
1282 // be loaded (when it is not already loaded) before babel when hyperref
1283 // is used with the colorlinks option, see
1284 // http://bugzilla.lyx.org/show_bug.cgi?id=5291
1285 // we decided therefore to load color always before babel, see
1286 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
1287 lyxpreamble += from_ascii(features.getColorOptions());
1289 // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them.
1291 && (features.isRequired("jurabib")
1292 || features.isRequired("hyperref")
1293 || features.isRequired("vietnamese")
1294 || features.isRequired("japanese") ) ) {
1296 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1297 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1300 // The optional packages;
1301 lyxpreamble += from_ascii(features.getPackages());
1304 lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
1307 // * Hyperref manual: "Make sure it comes last of your loaded
1308 // packages, to give it a fighting chance of not being over-written,
1309 // since its job is to redefine many LaTeX commands."
1310 // * Email from Heiko Oberdiek: "It is usually better to load babel
1311 // before hyperref. Then hyperref has a chance to detect babel.
1312 // * Has to be loaded before the "LyX specific LaTeX commands" to
1313 // avoid errors with algorithm floats.
1314 // use hyperref explicitely when it is required
1315 if (features.isRequired("hyperref")) {
1316 odocstringstream oss;
1317 pdfoptions().writeLaTeX(oss, documentClass().provides("hyperref"));
1318 lyxpreamble += oss.str();
1321 // Will be surrounded by \makeatletter and \makeatother when needed
1322 docstring atlyxpreamble;
1324 // Some macros LyX will need
1325 docstring tmppreamble(from_ascii(features.getMacros()));
1327 if (!tmppreamble.empty())
1328 atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1329 "LyX specific LaTeX commands.\n"
1330 + tmppreamble + '\n';
1332 // the text class specific preamble
1333 tmppreamble = features.getTClassPreamble();
1334 if (!tmppreamble.empty())
1335 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1336 "Textclass specific LaTeX commands.\n"
1337 + tmppreamble + '\n';
1339 /* the user-defined preamble */
1340 if (!preamble.empty())
1342 atlyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1343 "User specified LaTeX commands.\n"
1344 + from_utf8(preamble) + '\n';
1346 // subfig loads internally the LaTeX package "caption". As
1347 // caption is a very popular package, users will load it in
1348 // the preamble. Therefore we must load subfig behind the
1349 // user-defined preamble and check if the caption package was
1350 // loaded or not. For the case that caption is loaded before
1351 // subfig, there is the subfig option "caption=false". This
1352 // option also works when a koma-script class is used and
1353 // koma's own caption commands are used instead of caption. We
1354 // use \PassOptionsToPackage here because the user could have
1355 // already loaded subfig in the preamble.
1356 if (features.isRequired("subfig")) {
1357 atlyxpreamble += "\\@ifundefined{showcaptionsetup}{}{%\n"
1358 " \\PassOptionsToPackage{caption=false}{subfig}}\n"
1359 "\\usepackage{subfig}\n";
1362 // Itemize bullet settings need to be last in case the user
1363 // defines their own bullets that use a package included
1364 // in the user-defined preamble -- ARRae
1365 // Actually it has to be done much later than that
1366 // since some packages like frenchb make modifications
1367 // at \begin{document} time -- JMarc
1368 docstring bullets_def;
1369 for (int i = 0; i < 4; ++i) {
1370 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1371 if (bullets_def.empty())
1372 bullets_def += "\\AtBeginDocument{\n";
1373 bullets_def += " \\def\\labelitemi";
1375 // `i' is one less than the item to modify
1382 bullets_def += "ii";
1388 bullets_def += '{' +
1389 user_defined_bullet(i).getText()
1394 if (!bullets_def.empty())
1395 atlyxpreamble += bullets_def + "}\n\n";
1397 if (atlyxpreamble.find(from_ascii("@")) != docstring::npos)
1398 lyxpreamble += "\n\\makeatletter\n"
1399 + atlyxpreamble + "\\makeatother\n\n";
1401 lyxpreamble += '\n' + atlyxpreamble;
1403 // We try to load babel late, in case it interferes with other packages.
1404 // Jurabib and Hyperref have to be called after babel, though.
1405 if (use_babel && !features.isRequired("jurabib")
1406 && !features.isRequired("hyperref")
1407 && !features.isRequired("vietnamese")
1408 && !features.isRequired("japanese")) {
1410 lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
1411 lyxpreamble += from_utf8(features.getBabelOptions()) + '\n';
1415 int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1416 for (int j = 0; j != nlines; ++j) {
1425 void BufferParams::useClassDefaults()
1427 DocumentClass const & tclass = documentClass();
1429 sides = tclass.sides();
1430 columns = tclass.columns();
1431 pagestyle = tclass.pagestyle();
1432 use_default_options = true;
1433 // Only if class has a ToC hierarchy
1434 if (tclass.hasTocLevels()) {
1435 secnumdepth = tclass.secnumdepth();
1436 tocdepth = tclass.tocdepth();
1441 bool BufferParams::hasClassDefaults() const
1443 DocumentClass const & tclass = documentClass();
1445 return sides == tclass.sides()
1446 && columns == tclass.columns()
1447 && pagestyle == tclass.pagestyle()
1448 && use_default_options
1449 && secnumdepth == tclass.secnumdepth()
1450 && tocdepth == tclass.tocdepth();
1454 DocumentClass const & BufferParams::documentClass() const
1460 DocumentClass const * BufferParams::documentClassPtr() const {
1465 void BufferParams::setDocumentClass(DocumentClass const * const tc) {
1466 // evil, but this function is evil
1467 doc_class_ = const_cast<DocumentClass *>(tc);
1471 void BufferParams::addDefaultModules()
1473 // add any default modules not already in use
1474 list<string> const & mods = baseClass()->defaultModules();
1475 list<string>::const_iterator mit = mods.begin();
1476 list<string>::const_iterator men = mods.end();
1478 // we want to add these to the front, but in the right order,
1479 // so we collect them here first.
1480 list<string> modulesToAdd;
1482 for (; mit != men; mit++) {
1483 string const & modName = *mit;
1484 // make sure the user hasn't removed it
1485 if (find(removedModules_.begin(), removedModules_.end(), modName) !=
1486 removedModules_.end()) {
1487 LYXERR(Debug::TCLASS, "Default module `" << modName <<
1488 "' not added because removed by user.");
1492 if (moduleCanBeAdded(modName)) {
1493 LYXERR(Debug::TCLASS, "Default module `" << modName << "' added.");
1494 modulesToAdd.push_back(modName);
1496 LYXERR(Debug::TCLASS,
1497 "Default module `" << modName << "' could not be added.");
1500 // OK, now we can add the default modules.
1501 layoutModules_.insert(
1502 layoutModules_.begin(), modulesToAdd.begin(), modulesToAdd.end());
1506 bool BufferParams::setBaseClass(string const & classname)
1508 LYXERR(Debug::TCLASS, "setBaseClass: " << classname);
1509 LayoutFileList & bcl = LayoutFileList::get();
1510 if (!bcl.haveClass(classname)) {
1512 bformat(_("The document class %1$s could not be found. "
1513 "A default textclass with default layouts will be used. "
1514 "LyX might not be able to produce output unless a correct "
1515 "textclass is selected from the document settings dialog."),
1516 from_utf8(classname));
1517 frontend::Alert::error(_("Document class not found"), s);
1518 bcl.addEmptyClass(classname);
1521 bool const success = bcl[classname].load();
1524 bformat(_("The document class %1$s could not be loaded."),
1525 from_utf8(classname));
1526 frontend::Alert::error(_("Could not load class"), s);
1530 pimpl_->baseClass_ = classname;
1531 addDefaultModules();
1537 LayoutFile const * BufferParams::baseClass() const
1539 if (LayoutFileList::get().haveClass(pimpl_->baseClass_))
1540 return &(LayoutFileList::get()[pimpl_->baseClass_]);
1546 LayoutFileIndex const & BufferParams::baseClassID() const
1548 return pimpl_->baseClass_;
1552 void BufferParams::makeDocumentClass()
1557 doc_class_ = &(DocumentClassBundle::get().newClass(*baseClass()));
1559 // FIXME It might be worth loading the children's modules here,
1560 // just as we load their bibliographies and such, instead of just
1561 // doing a check in InsetInclude.
1562 LayoutModuleList::const_iterator it = layoutModules_.begin();
1563 for (; it != layoutModules_.end(); it++) {
1564 string const modName = *it;
1565 LyXModule * lm = moduleList[modName];
1567 docstring const msg =
1568 bformat(_("The module %1$s has been requested by\n"
1569 "this document but has not been found in the list of\n"
1570 "available modules. If you recently installed it, you\n"
1571 "probably need to reconfigure LyX.\n"), from_utf8(modName));
1572 frontend::Alert::warning(_("Module not available"),
1573 msg + _("Some layouts may not be available."));
1574 LYXERR0("BufferParams::makeDocumentClass(): Module " <<
1575 modName << " requested but not found in module list.");
1578 if (!lm->isAvailable()) {
1579 docstring const msg =
1580 bformat(_("The module %1$s requires a package that is\n"
1581 "not available in your LaTeX installation. LaTeX output\n"
1582 "may not be possible.\n"), from_utf8(modName));
1583 frontend::Alert::warning(_("Package not available"), msg);
1585 FileName layout_file = libFileSearch("layouts", lm->getFilename());
1586 if (!doc_class_->read(layout_file, TextClass::MODULE)) {
1587 docstring const msg =
1588 bformat(_("Error reading module %1$s\n"), from_utf8(modName));
1589 frontend::Alert::warning(_("Read Error"), msg);
1592 if (!local_layout.empty()) {
1593 if (!doc_class_->read(local_layout, TextClass::MODULE)) {
1594 docstring const msg = _("Error reading internal layout information");
1595 frontend::Alert::warning(_("Read Error"), msg);
1601 bool BufferParams::moduleCanBeAdded(string const & modName) const
1603 // Is the module already present?
1604 LayoutModuleList::const_iterator it = layoutModules_.begin();
1605 LayoutModuleList::const_iterator end = layoutModules_.end();
1606 for (; it != end; it++)
1610 LyXModule const * const lm = moduleList[modName];
1614 LayoutModuleList::const_iterator mit = getModules().begin();
1615 LayoutModuleList::const_iterator const men = getModules().end();
1616 // Check for conflicts with used modules
1617 for (; mit != men; ++mit)
1618 if (!LyXModule::areCompatible(modName, *mit))
1621 // Check whether some required module is available
1622 vector<string> const reqs = lm->getRequiredModules();
1626 mit = getModules().begin(); // reset
1627 vector<string>::const_iterator rit = reqs.begin();
1628 vector<string>::const_iterator ren = reqs.end();
1629 bool foundOne = false;
1630 for (; rit != ren; ++rit) {
1631 if (find(mit, men, *rit) != men) {
1641 bool BufferParams::addLayoutModule(string const & modName)
1643 LayoutModuleList::const_iterator it = layoutModules_.begin();
1644 LayoutModuleList::const_iterator end = layoutModules_.end();
1645 for (; it != end; it++)
1648 layoutModules_.push_back(modName);
1653 Font const BufferParams::getFont() const
1655 FontInfo f = documentClass().defaultfont();
1656 if (fontsDefaultFamily == "rmdefault")
1657 f.setFamily(ROMAN_FAMILY);
1658 else if (fontsDefaultFamily == "sfdefault")
1659 f.setFamily(SANS_FAMILY);
1660 else if (fontsDefaultFamily == "ttdefault")
1661 f.setFamily(TYPEWRITER_FAMILY);
1662 return Font(f, language);
1666 void BufferParams::readPreamble(Lexer & lex)
1668 if (lex.getString() != "\\begin_preamble")
1669 lyxerr << "Error (BufferParams::readPreamble):"
1670 "consistency check failed." << endl;
1672 preamble = lex.getLongString("\\end_preamble");
1676 void BufferParams::readLocalLayout(Lexer & lex)
1678 if (lex.getString() != "\\begin_local_layout")
1679 lyxerr << "Error (BufferParams::readLocalLayout):"
1680 "consistency check failed." << endl;
1682 local_layout = lex.getLongString("\\end_local_layout");
1686 void BufferParams::readLanguage(Lexer & lex)
1688 if (!lex.next()) return;
1690 string const tmptok = lex.getString();
1692 // check if tmptok is part of tex_babel in tex-defs.h
1693 language = languages.getLanguage(tmptok);
1695 // Language tmptok was not found
1696 language = default_language;
1697 lyxerr << "Warning: Setting language `"
1698 << tmptok << "' to `" << language->lang()
1704 void BufferParams::readGraphicsDriver(Lexer & lex)
1709 string const tmptok = lex.getString();
1710 // check if tmptok is part of tex_graphics in tex_defs.h
1713 string const test = tex_graphics[n++];
1715 if (test == tmptok) {
1716 graphicsDriver = tmptok;
1721 "Warning: graphics driver `$$Token' not recognized!\n"
1722 " Setting graphics driver to `default'.\n");
1723 graphicsDriver = "default";
1730 void BufferParams::readBullets(Lexer & lex)
1735 int const index = lex.getInteger();
1737 int temp_int = lex.getInteger();
1738 user_defined_bullet(index).setFont(temp_int);
1739 temp_bullet(index).setFont(temp_int);
1741 user_defined_bullet(index).setCharacter(temp_int);
1742 temp_bullet(index).setCharacter(temp_int);
1744 user_defined_bullet(index).setSize(temp_int);
1745 temp_bullet(index).setSize(temp_int);
1749 void BufferParams::readBulletsLaTeX(Lexer & lex)
1751 // The bullet class should be able to read this.
1754 int const index = lex.getInteger();
1756 docstring const temp_str = lex.getDocString();
1758 user_defined_bullet(index).setText(temp_str);
1759 temp_bullet(index).setText(temp_str);
1763 void BufferParams::readModules(Lexer & lex)
1765 if (!lex.eatLine()) {
1766 lyxerr << "Error (BufferParams::readModules):"
1767 "Unexpected end of input." << endl;
1771 string mod = lex.getString();
1772 if (mod == "\\end_modules")
1774 addLayoutModule(mod);
1780 void BufferParams::readRemovedModules(Lexer & lex)
1782 if (!lex.eatLine()) {
1783 lyxerr << "Error (BufferParams::readRemovedModules):"
1784 "Unexpected end of input." << endl;
1788 string mod = lex.getString();
1789 if (mod == "\\end_removed_modules")
1791 removedModules_.insert(mod);
1794 // now we want to remove any removed modules that were previously
1795 // added. normally, that will be because default modules were added in
1796 // setBaseClass(), which gets called when \textclass is read at the
1797 // start of the read.
1798 set<string>::const_iterator rit = removedModules_.begin();
1799 set<string>::const_iterator const ren = removedModules_.end();
1800 for (; rit != ren; rit++) {
1801 LayoutModuleList::iterator const mit = layoutModules_.begin();
1802 LayoutModuleList::iterator const men = layoutModules_.end();
1803 LayoutModuleList::iterator found = find(mit, men, *rit);
1806 layoutModules_.erase(found);
1811 string BufferParams::paperSizeName(PapersizePurpose purpose) const
1813 char real_papersize = papersize;
1814 if (real_papersize == PAPER_DEFAULT)
1815 real_papersize = lyxrc.default_papersize;
1817 switch (real_papersize) {
1819 // could be anything, so don't guess
1821 case PAPER_CUSTOM: {
1822 if (purpose == XDVI && !paperwidth.empty() &&
1823 !paperheight.empty()) {
1824 // heightxwidth<unit>
1825 string first = paperwidth;
1826 string second = paperheight;
1827 if (orientation == ORIENTATION_LANDSCAPE)
1830 return first.erase(first.length() - 2)
1842 // dvips and dvipdfm do not know this
1843 if (purpose == DVIPS || purpose == DVIPDFM)
1847 // dvipdfm does not know this
1848 if (purpose == DVIPDFM)
1852 // dvipdfm does not know this
1853 if (purpose == DVIPDFM)
1856 case PAPER_USEXECUTIVE:
1857 // dvipdfm does not know this
1858 if (purpose == DVIPDFM)
1863 case PAPER_USLETTER:
1865 if (purpose == XDVI)
1872 string const BufferParams::dvips_options() const
1877 && papersize == PAPER_CUSTOM
1878 && !lyxrc.print_paper_dimension_flag.empty()
1879 && !paperwidth.empty()
1880 && !paperheight.empty()) {
1881 // using a custom papersize
1882 result = lyxrc.print_paper_dimension_flag;
1883 result += ' ' + paperwidth;
1884 result += ',' + paperheight;
1886 string const paper_option = paperSizeName(DVIPS);
1887 if (!paper_option.empty() && (paper_option != "letter" ||
1888 orientation != ORIENTATION_LANDSCAPE)) {
1889 // dvips won't accept -t letter -t landscape.
1890 // In all other cases, include the paper size
1892 result = lyxrc.print_paper_flag;
1893 result += ' ' + paper_option;
1896 if (orientation == ORIENTATION_LANDSCAPE &&
1897 papersize != PAPER_CUSTOM)
1898 result += ' ' + lyxrc.print_landscape_flag;
1903 string BufferParams::babelCall(string const & lang_opts) const
1905 string lang_pack = lyxrc.language_package;
1906 if (lang_pack != "\\usepackage{babel}")
1908 // suppress the babel call when there is no babel language defined
1909 // for the document language in the lib/languages file and if no
1910 // other languages are used (lang_opts is then empty)
1911 if (lang_opts.empty())
1913 // If Vietnamese is used, babel must directly be loaded with the
1914 // language options, see
1915 // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
1916 size_t viet = lang_opts.find("vietnam");
1917 // viet = string::npos when not found
1918 // the same is for all other languages that are not directly supported by
1919 // babel, but where LaTeX-packages add babel support.
1920 // this is currently the case for Latvian, Lithuanian, and Mongolian
1921 size_t latvian = lang_opts.find("latvian");
1922 size_t lithu = lang_opts.find("lithuanian");
1923 size_t mongo = lang_opts.find("mongolian");
1924 // If Japanese is used, babel must directly be loaded with the
1925 // language options, see
1926 // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
1927 size_t japan = lang_opts.find("japanese");
1928 if (!lyxrc.language_global_options || viet != string::npos
1929 || japan != string::npos || latvian != string::npos
1930 || lithu != string::npos || mongo != string::npos)
1931 return "\\usepackage[" + lang_opts + "]{babel}";
1936 void BufferParams::writeEncodingPreamble(odocstream & os,
1937 LaTeXFeatures & features, TexRow & texrow) const
1939 if (inputenc == "auto") {
1940 string const doc_encoding =
1941 language->encoding()->latexName();
1942 Encoding::Package const package =
1943 language->encoding()->package();
1945 // Create a list with all the input encodings used
1947 set<string> encodings =
1948 features.getEncodingSet(doc_encoding);
1950 // If the "japanese" package (i.e. pLaTeX) is used,
1951 // inputenc must be omitted.
1952 // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
1953 if (package == Encoding::japanese)
1954 features.require("japanese");
1956 if ((!encodings.empty() || package == Encoding::inputenc)
1957 && !features.isRequired("japanese")) {
1958 os << "\\usepackage[";
1959 set<string>::const_iterator it = encodings.begin();
1960 set<string>::const_iterator const end = encodings.end();
1962 os << from_ascii(*it);
1965 for (; it != end; ++it)
1966 os << ',' << from_ascii(*it);
1967 if (package == Encoding::inputenc) {
1968 if (!encodings.empty())
1970 os << from_ascii(doc_encoding);
1972 os << "]{inputenc}\n";
1975 if (package == Encoding::CJK || features.mustProvide("CJK")) {
1976 os << "\\usepackage{CJK}\n";
1979 } else if (inputenc != "default") {
1980 switch (encoding().package()) {
1981 case Encoding::none:
1982 case Encoding::japanese:
1984 case Encoding::inputenc:
1985 // do not load inputenc if japanese is used
1986 if (features.isRequired("japanese"))
1988 os << "\\usepackage[" << from_ascii(inputenc)
1993 os << "\\usepackage{CJK}\n";
1999 // The encoding "armscii8" (for Armenian) is only available when
2000 // the package "armtex" is loaded.
2001 if (language->encoding()->latexName() == "armscii8"
2002 || inputenc == "armscii8") {
2003 os << "\\usepackage{armtex}\n";
2009 string const BufferParams::loadFonts(string const & rm,
2010 string const & sf, string const & tt,
2011 bool const & sc, bool const & osf,
2012 int const & sfscale, int const & ttscale) const
2014 /* The LaTeX font world is in a flux. In the PSNFSS font interface,
2015 several packages have been replaced by others, that might not
2016 be installed on every system. We have to take care for that
2017 (see psnfss.pdf). We try to support all psnfss fonts as well
2018 as the fonts that have become de facto standard in the LaTeX
2019 world (e.g. Latin Modern). We do not support obsolete fonts
2020 (like PSLatex). In general, it should be possible to mix any
2021 rm font with any sf or tt font, respectively. (JSpitzm)
2023 -- separate math fonts.
2026 if (rm == "default" && sf == "default" && tt == "default")
2033 // Computer Modern (must be explicitely selectable -- there might be classes
2034 // that define a different default font!
2036 os << "\\renewcommand{\\rmdefault}{cmr}\n";
2037 // osf for Computer Modern needs eco.sty
2039 os << "\\usepackage{eco}\n";
2041 // Latin Modern Roman
2042 else if (rm == "lmodern")
2043 os << "\\usepackage{lmodern}\n";
2045 else if (rm == "ae") {
2046 // not needed when using OT1 font encoding.
2047 if (lyxrc.fontenc != "default")
2048 os << "\\usepackage{ae,aecompl}\n";
2051 else if (rm == "times") {
2052 // try to load the best available package
2053 if (LaTeXFeatures::isAvailable("mathptmx"))
2054 os << "\\usepackage{mathptmx}\n";
2055 else if (LaTeXFeatures::isAvailable("mathptm"))
2056 os << "\\usepackage{mathptm}\n";
2058 os << "\\usepackage{times}\n";
2061 else if (rm == "palatino") {
2062 // try to load the best available package
2063 if (LaTeXFeatures::isAvailable("mathpazo")) {
2064 os << "\\usepackage";
2070 // "osf" includes "sc"!
2074 os << "{mathpazo}\n";
2076 else if (LaTeXFeatures::isAvailable("mathpple"))
2077 os << "\\usepackage{mathpple}\n";
2079 os << "\\usepackage{palatino}\n";
2082 else if (rm == "utopia") {
2083 // fourier supersedes utopia.sty, but does
2084 // not work with OT1 encoding.
2085 if (LaTeXFeatures::isAvailable("fourier")
2086 && lyxrc.fontenc != "default") {
2087 os << "\\usepackage";
2098 os << "{fourier}\n";
2101 os << "\\usepackage{utopia}\n";
2103 // Bera (complete fontset)
2104 else if (rm == "bera" && sf == "default" && tt == "default")
2105 os << "\\usepackage{bera}\n";
2107 else if (rm != "default")
2108 os << "\\usepackage" << "{" << rm << "}\n";
2111 // Helvetica, Bera Sans
2112 if (sf == "helvet" || sf == "berasans") {
2114 os << "\\usepackage[scaled=" << float(sfscale) / 100
2115 << "]{" << sf << "}\n";
2117 os << "\\usepackage{" << sf << "}\n";
2120 else if (sf == "avant")
2121 os << "\\usepackage{" << sf << "}\n";
2122 // Computer Modern, Latin Modern, CM Bright
2123 else if (sf != "default")
2124 os << "\\renewcommand{\\sfdefault}{" << sf << "}\n";
2126 // monospaced/typewriter
2127 // Courier, LuxiMono
2128 if (tt == "luximono" || tt == "beramono") {
2130 os << "\\usepackage[scaled=" << float(ttscale) / 100
2131 << "]{" << tt << "}\n";
2133 os << "\\usepackage{" << tt << "}\n";
2136 else if (tt == "courier" )
2137 os << "\\usepackage{" << tt << "}\n";
2138 // Computer Modern, Latin Modern, CM Bright
2139 else if (tt != "default")
2140 os << "\\renewcommand{\\ttdefault}{" << tt << "}\n";
2146 Encoding const & BufferParams::encoding() const
2148 if (inputenc == "auto" || inputenc == "default")
2149 return *language->encoding();
2150 Encoding const * const enc = encodings.fromLaTeXName(inputenc);
2153 LYXERR0("Unknown inputenc value `" << inputenc
2154 << "'. Using `auto' instead.");
2155 return *language->encoding();
2159 CiteEngine BufferParams::citeEngine() const
2161 // FIXME the class should provide the numerical/
2162 // authoryear choice
2163 if (documentClass().provides("natbib")
2164 && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
2165 return ENGINE_NATBIB_AUTHORYEAR;
2166 return cite_engine_;
2170 void BufferParams::setCiteEngine(CiteEngine cite_engine)
2172 cite_engine_ = cite_engine;