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 "BranchList.h"
27 #include "LaTeXFeatures.h"
31 #include "lyxtextclasslist.h"
32 #include "outputparams.h"
33 #include "tex-strings.h"
38 #include "frontends/Alert.h"
40 #include "support/lyxalgo.h" // for lyx::count
41 #include "support/convert.h"
42 #include "support/translator.h"
44 #include <boost/array.hpp>
48 namespace support = lyx::support;
49 using lyx::support::bformat;
50 using lyx::support::rtrim;
51 using lyx::support::tokenPos;
55 using std::istringstream;
57 using std::ostringstream;
60 namespace biblio = lyx::biblio;
66 // Paragraph separation
67 typedef Translator<string, BufferParams::PARSEP> ParSepTranslator;
70 ParSepTranslator const init_parseptranslator()
72 ParSepTranslator translator(string_paragraph_separation[0], BufferParams::PARSEP_INDENT);
73 translator.addPair(string_paragraph_separation[1], BufferParams::PARSEP_SKIP);
78 ParSepTranslator const & parseptranslator()
80 static ParSepTranslator translator = init_parseptranslator();
86 typedef Translator<string, InsetQuotes::quote_language> QuotesLangTranslator;
89 QuotesLangTranslator const init_quoteslangtranslator()
91 QuotesLangTranslator translator(string_quotes_language[0], InsetQuotes::EnglishQ);
92 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQ);
93 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQ);
94 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQ);
95 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQ);
96 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQ);
101 QuotesLangTranslator const & quoteslangtranslator()
103 static QuotesLangTranslator translator = init_quoteslangtranslator();
109 typedef Translator<std::string, PAPER_SIZE> PaperSizeTranslator;
112 PaperSizeTranslator const init_papersizetranslator()
114 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
115 translator.addPair(string_papersize[1], PAPER_CUSTOM);
116 translator.addPair(string_papersize[2], PAPER_USLETTER);
117 translator.addPair(string_papersize[3], PAPER_USLEGAL);
118 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
119 translator.addPair(string_papersize[5], PAPER_A3);
120 translator.addPair(string_papersize[6], PAPER_A4);
121 translator.addPair(string_papersize[7], PAPER_A5);
122 translator.addPair(string_papersize[8], PAPER_B3);
123 translator.addPair(string_papersize[9], PAPER_B4);
124 translator.addPair(string_papersize[10], PAPER_B5);
129 PaperSizeTranslator const & papersizetranslator()
131 static PaperSizeTranslator translator = init_papersizetranslator();
137 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
140 PaperOrientationTranslator const init_paperorientationtranslator()
142 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
143 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
148 PaperOrientationTranslator const & paperorientationtranslator()
150 static PaperOrientationTranslator translator = init_paperorientationtranslator();
156 typedef Translator<int, LyXTextClass::PageSides> SidesTranslator;
159 SidesTranslator const init_sidestranslator()
161 SidesTranslator translator(1, LyXTextClass::OneSide);
162 translator.addPair(2, LyXTextClass::TwoSides);
167 SidesTranslator const & sidestranslator()
169 static SidesTranslator translator = init_sidestranslator();
176 typedef Translator<int, BufferParams::AMS> AMSTranslator;
179 AMSTranslator const init_amstranslator()
181 AMSTranslator translator(0, BufferParams::AMS_OFF);
182 translator.addPair(1, BufferParams::AMS_AUTO);
183 translator.addPair(2, BufferParams::AMS_ON);
188 AMSTranslator const & amstranslator()
190 static AMSTranslator translator = init_amstranslator();
196 typedef Translator<string, biblio::CiteEngine> CiteEngineTranslator;
199 CiteEngineTranslator const init_citeenginetranslator()
201 CiteEngineTranslator translator("basic", biblio::ENGINE_BASIC);
202 translator.addPair("natbib_numerical", biblio::ENGINE_NATBIB_NUMERICAL);
203 translator.addPair("natbib_authoryear", biblio::ENGINE_NATBIB_AUTHORYEAR);
204 translator.addPair("jurabib", biblio::ENGINE_JURABIB);
209 CiteEngineTranslator const & citeenginetranslator()
211 static CiteEngineTranslator translator = init_citeenginetranslator();
217 typedef Translator<string, Spacing::Space> SpaceTranslator;
220 SpaceTranslator const init_spacetranslator()
222 SpaceTranslator translator("default", Spacing::Default);
223 translator.addPair("single", Spacing::Single);
224 translator.addPair("onehalf", Spacing::Onehalf);
225 translator.addPair("double", Spacing::Double);
226 translator.addPair("other", Spacing::Other);
231 SpaceTranslator const & spacetranslator()
233 static SpaceTranslator translator = init_spacetranslator();
237 // ends annonym namespace
241 class BufferParams::Impl
246 AuthorList authorlist;
247 BranchList branchlist;
248 boost::array<Bullet, 4> temp_bullets;
249 boost::array<Bullet, 4> user_defined_bullets;
251 /** This is the amount of space used for paragraph_separation "skip",
252 * and for detached paragraphs in "indented" documents.
258 BufferParams::Impl::Impl()
259 : defskip(VSpace::MEDSKIP)
261 // set initial author
262 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
267 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
271 return new BufferParams::Impl(*ptr);
275 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
281 BufferParams::BufferParams()
282 : // Initialize textclass to point to article. if `first' is
283 // true in the returned pair, then `second' is the textclass
284 // number; if it is false, second is 0. In both cases, second
286 textclass(textclasslist.numberOfClass("article").second),
289 paragraph_separation = PARSEP_INDENT;
290 quotes_language = InsetQuotes::EnglishQ;
291 fontsize = "default";
294 papersize = PAPER_DEFAULT;
295 orientation = ORIENTATION_PORTRAIT;
296 use_geometry = false;
297 use_amsmath = AMS_AUTO;
298 cite_engine = biblio::ENGINE_BASIC;
299 use_bibtopic = false;
300 tracking_changes = false;
301 output_changes = false;
304 language = default_language;
307 graphicsDriver = "default";
308 sides = LyXTextClass::OneSide;
310 pagestyle = "default";
312 for (int iter = 0; iter < 4; ++iter) {
313 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
314 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
319 BufferParams::~BufferParams()
323 AuthorList & BufferParams::authors()
325 return pimpl_->authorlist;
329 AuthorList const & BufferParams::authors() const
331 return pimpl_->authorlist;
335 BranchList & BufferParams::branchlist()
337 return pimpl_->branchlist;
341 BranchList const & BufferParams::branchlist() const
343 return pimpl_->branchlist;
347 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
349 BOOST_ASSERT(index < 4);
350 return pimpl_->temp_bullets[index];
354 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
356 BOOST_ASSERT(index < 4);
357 return pimpl_->temp_bullets[index];
361 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
363 BOOST_ASSERT(index < 4);
364 return pimpl_->user_defined_bullets[index];
368 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
370 BOOST_ASSERT(index < 4);
371 return pimpl_->user_defined_bullets[index];
375 Spacing & BufferParams::spacing()
377 return pimpl_->spacing;
381 Spacing const & BufferParams::spacing() const
383 return pimpl_->spacing;
387 VSpace const & BufferParams::getDefSkip() const
389 return pimpl_->defskip;
393 void BufferParams::setDefSkip(VSpace const & vs)
395 pimpl_->defskip = vs;
399 string const BufferParams::readToken(LyXLex & lex, string const & token)
401 if (token == "\\textclass") {
403 string const classname = lex.getString();
404 pair<bool, lyx::textclass_type> pp =
405 textclasslist.numberOfClass(classname);
407 textclass = pp.second;
409 // if text class does not exist, try to load it from filepath
410 pp = textclasslist.addTextClass(classname, filepath);
412 textclass = pp.second;
418 // FIXME: isTeXClassAvailable will try to load the layout file, but will
419 // fail because of the lack of path info. Warnings will be given although
420 // the layout file will be correctly loaded later.
421 if (!getLyXTextClass().isTeXClassAvailable()) {
423 bformat(_("The document uses a missing "
424 "TeX class \"%1$s\".\n"), classname);
425 Alert::warning(_("Document class not available"),
426 msg + _("LyX will not be able to produce output."));
428 } else if (token == "\\begin_preamble") {
430 } else if (token == "\\options") {
432 options = lex.getString();
433 } else if (token == "\\language") {
435 } else if (token == "\\inputencoding") {
437 } else if (token == "\\graphics") {
438 readGraphicsDriver(lex);
439 } else if (token == "\\fontscheme") {
441 } else if (token == "\\paragraph_separation") {
444 paragraph_separation = parseptranslator().find(parsep);
445 } else if (token == "\\defskip") {
447 pimpl_->defskip = VSpace(lex.getString());
448 } else if (token == "\\quotes_language") {
451 quotes_language = quoteslangtranslator().find(quotes_lang);
452 } else if (token == "\\papersize") {
455 papersize = papersizetranslator().find(ppsize);
456 } else if (token == "\\use_geometry") {
458 } else if (token == "\\use_amsmath") {
461 use_amsmath = amstranslator().find(use_ams);
462 } else if (token == "\\cite_engine") {
465 cite_engine = citeenginetranslator().find(engine);
466 } else if (token == "\\use_bibtopic") {
468 } else if (token == "\\tracking_changes") {
469 lex >> tracking_changes;
470 } else if (token == "\\output_changes") {
471 lex >> output_changes;
472 } else if (token == "\\branch") {
474 string branch = lex.getString();
475 branchlist().add(branch);
478 string const tok = lex.getString();
479 if (tok == "\\end_branch")
481 Branch * branch_ptr = branchlist().find(branch);
482 if (tok == "\\selected") {
485 branch_ptr->setSelected(lex.getInteger());
487 // not yet operational
488 if (tok == "\\color") {
490 string color = lex.getString();
492 branch_ptr->setColor(color);
493 // Update also the LColor table:
495 color = lcolor.getX11Name(LColor::background);
496 lcolor.setColor(branch, color);
500 } else if (token == "\\author") {
502 istringstream ss(lex.getString());
505 author_map.push_back(pimpl_->authorlist.record(a));
506 } else if (token == "\\paperorientation") {
509 orientation = paperorientationtranslator().find(orient);
510 } else if (token == "\\paperwidth") {
512 } else if (token == "\\paperheight") {
514 } else if (token == "\\leftmargin") {
516 } else if (token == "\\topmargin") {
518 } else if (token == "\\rightmargin") {
520 } else if (token == "\\bottommargin") {
522 } else if (token == "\\headheight") {
524 } else if (token == "\\headsep") {
526 } else if (token == "\\footskip") {
528 } else if (token == "\\paperfontsize") {
530 } else if (token == "\\papercolumns") {
532 } else if (token == "\\papersides") {
535 sides = sidestranslator().find(psides);
536 } else if (token == "\\paperpagestyle") {
538 } else if (token == "\\bullet") {
540 } else if (token == "\\bulletLaTeX") {
541 readBulletsLaTeX(lex);
542 } else if (token == "\\secnumdepth") {
544 } else if (token == "\\tocdepth") {
546 } else if (token == "\\spacing") {
550 if (nspacing == "other") {
553 spacing().set(spacetranslator().find(nspacing), tmp_val);
554 } else if (token == "\\float_placement") {
555 lex >> float_placement;
564 void BufferParams::writeFile(ostream & os) const
566 // The top of the file is written by the buffer.
567 // Prints out the buffer info into the .lyx file given by file
570 os << "\\textclass " << textclasslist[textclass].name() << '\n';
572 // then the the preamble
573 if (!preamble.empty()) {
574 // remove '\n' from the end of preamble
575 string const tmppreamble = rtrim(preamble, "\n");
576 os << "\\begin_preamble\n"
578 << "\n\\end_preamble\n";
582 if (!options.empty()) {
583 os << "\\options " << options << '\n';
586 // then the text parameters
587 if (language != ignore_language)
588 os << "\\language " << language->lang() << '\n';
589 os << "\\inputencoding " << inputenc
590 << "\n\\fontscheme " << fonts
591 << "\n\\graphics " << graphicsDriver << '\n';
593 if (!float_placement.empty()) {
594 os << "\\float_placement " << float_placement << '\n';
596 os << "\\paperfontsize " << fontsize << '\n';
598 spacing().writeFile(os);
600 os << "\\papersize " << string_papersize[papersize]
601 << "\n\\use_geometry " << convert<string>(use_geometry)
602 << "\n\\use_amsmath " << use_amsmath
603 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
604 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
605 << "\n\\paperorientation " << string_orientation[orientation]
608 BranchList::const_iterator it = branchlist().begin();
609 BranchList::const_iterator end = branchlist().end();
610 for (; it != end; ++it) {
611 os << "\\branch " << it->getBranch()
612 << "\n\\selected " << it->getSelected()
613 << "\n\\color " << lyx::X11hexname(it->getColor())
618 if (!paperwidth.empty())
619 os << "\\paperwidth "
620 << VSpace(paperwidth).asLyXCommand() << '\n';
621 if (!paperheight.empty())
622 os << "\\paperheight "
623 << VSpace(paperheight).asLyXCommand() << '\n';
624 if (!leftmargin.empty())
625 os << "\\leftmargin "
626 << VSpace(leftmargin).asLyXCommand() << '\n';
627 if (!topmargin.empty())
629 << VSpace(topmargin).asLyXCommand() << '\n';
630 if (!rightmargin.empty())
631 os << "\\rightmargin "
632 << VSpace(rightmargin).asLyXCommand() << '\n';
633 if (!bottommargin.empty())
634 os << "\\bottommargin "
635 << VSpace(bottommargin).asLyXCommand() << '\n';
636 if (!headheight.empty())
637 os << "\\headheight "
638 << VSpace(headheight).asLyXCommand() << '\n';
639 if (!headsep.empty())
641 << VSpace(headsep).asLyXCommand() << '\n';
642 if (!footskip.empty())
644 << VSpace(footskip).asLyXCommand() << '\n';
645 os << "\\secnumdepth " << secnumdepth
646 << "\n\\tocdepth " << tocdepth
647 << "\n\\paragraph_separation "
648 << string_paragraph_separation[paragraph_separation]
649 << "\n\\defskip " << getDefSkip().asLyXCommand()
650 << "\n\\quotes_language "
651 << string_quotes_language[quotes_language]
652 << "\n\\papercolumns " << columns
653 << "\n\\papersides " << sides
654 << "\n\\paperpagestyle " << pagestyle << '\n';
655 for (int i = 0; i < 4; ++i) {
656 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
657 if (user_defined_bullet(i).getFont() != -1) {
658 os << "\\bullet " << i << " "
659 << user_defined_bullet(i).getFont() << " "
660 << user_defined_bullet(i).getCharacter() << " "
661 << user_defined_bullet(i).getSize() << "\n";
664 os << "\\bulletLaTeX " << i << " \""
665 << user_defined_bullet(i).getText()
671 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
672 os << "\\output_changes " << convert<string>(output_changes) << "\n";
674 if (tracking_changes) {
675 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
676 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
677 for (; it != end; ++it) {
678 os << "\\author " << it->second << "\n";
684 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
685 TexRow & texrow) const
687 os << "\\documentclass";
689 LyXTextClass const & tclass = getLyXTextClass();
691 ostringstream clsoptions; // the document class options.
693 if (tokenPos(tclass.opt_fontsize(),
694 '|', fontsize) >= 0) {
695 // only write if existing in list (and not default)
696 clsoptions << fontsize << "pt,";
699 // custom, A3, B3 and B4 paper sizes need geometry
700 bool nonstandard_papersize = (papersize == PAPER_B3) ||
701 (papersize == PAPER_B4) ||
702 (papersize == PAPER_A3) ||
703 (papersize == PAPER_CUSTOM);
708 clsoptions << "a4paper,";
711 clsoptions << "letterpaper,";
714 clsoptions << "a5paper,";
717 clsoptions << "b5paper,";
719 case PAPER_USEXECUTIVE:
720 clsoptions << "executivepaper,";
723 clsoptions << "legalpaper,";
735 if (sides != tclass.sides()) {
737 case LyXTextClass::OneSide:
738 clsoptions << "oneside,";
740 case LyXTextClass::TwoSides:
741 clsoptions << "twoside,";
747 if (columns != tclass.columns()) {
749 clsoptions << "twocolumn,";
751 clsoptions << "onecolumn,";
755 && orientation == ORIENTATION_LANDSCAPE)
756 clsoptions << "landscape,";
758 // language should be a parameter to \documentclass
759 if (language->babel() == "hebrew"
760 && default_language->babel() != "hebrew")
761 // This seems necessary
762 features.useLanguage(default_language);
764 ostringstream language_options;
765 bool const use_babel = features.useBabel();
767 language_options << features.getLanguages();
768 language_options << language->babel();
769 if (lyxrc.language_global_options)
770 clsoptions << language_options.str() << ',';
773 // the user-defined options
774 if (!options.empty()) {
775 clsoptions << options << ',';
778 string strOptions(clsoptions.str());
779 if (!strOptions.empty()) {
780 strOptions = rtrim(strOptions, ",");
781 os << '[' << strOptions << ']';
784 os << '{' << tclass.latexname() << "}\n";
786 // end of \documentclass defs
788 // font selection must be done before loading fontenc.sty
789 // The ae package is not needed when using OT1 font encoding.
790 if (fonts != "default" &&
791 (fonts != "ae" || lyxrc.fontenc != "default")) {
792 os << "\\usepackage{" << fonts << "}\n";
795 os << "\\usepackage{aecompl}\n";
799 // this one is not per buffer
800 if (lyxrc.fontenc != "default") {
801 os << "\\usepackage[" << lyxrc.fontenc
806 if (inputenc == "auto") {
807 string const doc_encoding =
808 language->encoding()->latexName();
810 // Create a list with all the input encodings used
812 std::set<string> encodings =
813 features.getEncodingSet(doc_encoding);
815 os << "\\usepackage[";
816 std::copy(encodings.begin(), encodings.end(),
817 std::ostream_iterator<string>(os, ","));
818 os << doc_encoding << "]{inputenc}\n";
820 } else if (inputenc != "default") {
821 os << "\\usepackage[" << inputenc
826 if (use_geometry || nonstandard_papersize) {
827 os << "\\usepackage{geometry}\n";
829 os << "\\geometry{verbose";
830 if (orientation == ORIENTATION_LANDSCAPE)
834 if (!paperwidth.empty())
837 if (!paperheight.empty())
838 os << ",paperheight="
842 os << ",letterpaper";
847 case PAPER_USEXECUTIVE:
848 os << ",executivepaper";
869 // default papersize ie PAPER_DEFAULT
870 switch (lyxrc.default_papersize) {
871 case PAPER_DEFAULT: // keep compiler happy
873 os << ",letterpaper";
878 case PAPER_USEXECUTIVE:
879 os << ",executivepaper";
899 if (!topmargin.empty())
900 os << ",tmargin=" << topmargin;
901 if (!bottommargin.empty())
902 os << ",bmargin=" << bottommargin;
903 if (!leftmargin.empty())
904 os << ",lmargin=" << leftmargin;
905 if (!rightmargin.empty())
906 os << ",rmargin=" << rightmargin;
907 if (!headheight.empty())
908 os << ",headheight=" << headheight;
909 if (!headsep.empty())
910 os << ",headsep=" << headsep;
911 if (!footskip.empty())
912 os << ",footskip=" << footskip;
917 if (tokenPos(tclass.opt_pagestyle(),
918 '|', pagestyle) >= 0) {
919 if (pagestyle == "fancy") {
920 os << "\\usepackage{fancyhdr}\n";
923 os << "\\pagestyle{" << pagestyle << "}\n";
927 // Only if class has a ToC hierarchy
928 if (tclass.hasTocLevels()) {
929 if (secnumdepth != tclass.secnumdepth()) {
930 os << "\\setcounter{secnumdepth}{"
935 if (tocdepth != tclass.tocdepth()) {
936 os << "\\setcounter{tocdepth}{"
943 if (paragraph_separation) {
944 switch (getDefSkip().kind()) {
945 case VSpace::SMALLSKIP:
946 os << "\\setlength\\parskip{\\smallskipamount}\n";
948 case VSpace::MEDSKIP:
949 os << "\\setlength\\parskip{\\medskipamount}\n";
951 case VSpace::BIGSKIP:
952 os << "\\setlength\\parskip{\\bigskipamount}\n";
955 os << "\\setlength\\parskip{"
956 << getDefSkip().length().asLatexString()
959 default: // should never happen // Then delete it.
960 os << "\\setlength\\parskip{\\medskipamount}\n";
965 os << "\\setlength\\parindent{0pt}\n";
969 // If we use jurabib, we have to call babel here.
970 if (use_babel && features.isRequired("jurabib")) {
971 os << babelCall(language_options.str())
973 << features.getBabelOptions();
977 // Now insert the LyX specific LaTeX commands...
979 // The optional packages;
980 string lyxpreamble(features.getPackages());
982 // this might be useful...
983 lyxpreamble += "\n\\makeatletter\n";
985 // Some macros LyX will need
986 string tmppreamble(features.getMacros());
988 if (!tmppreamble.empty()) {
989 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
990 "LyX specific LaTeX commands.\n"
991 + tmppreamble + '\n';
994 // the text class specific preamble
995 tmppreamble = features.getTClassPreamble();
996 if (!tmppreamble.empty()) {
997 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
998 "Textclass specific LaTeX commands.\n"
999 + tmppreamble + '\n';
1002 /* the user-defined preamble */
1003 if (!preamble.empty()) {
1004 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1005 "User specified LaTeX commands.\n"
1009 // Itemize bullet settings need to be last in case the user
1010 // defines their own bullets that use a package included
1011 // in the user-defined preamble -- ARRae
1012 // Actually it has to be done much later than that
1013 // since some packages like frenchb make modifications
1014 // at \begin{document} time -- JMarc
1016 for (int i = 0; i < 4; ++i) {
1017 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1018 if (bullets_def.empty())
1019 bullets_def="\\AtBeginDocument{\n";
1020 bullets_def += " \\def\\labelitemi";
1022 // `i' is one less than the item to modify
1029 bullets_def += "ii";
1035 bullets_def += '{' +
1036 user_defined_bullet(i).getText()
1041 if (!bullets_def.empty())
1042 lyxpreamble += bullets_def + "}\n\n";
1044 // We try to load babel late, in case it interferes
1045 // with other packages.
1046 // Jurabib has to be called after babel, though.
1047 if (use_babel && !features.isRequired("jurabib")) {
1048 lyxpreamble += babelCall(language_options.str()) + '\n';
1049 lyxpreamble += features.getBabelOptions();
1052 lyxpreamble += "\\makeatother\n";
1054 // dvipost settings come after everything else
1055 if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
1058 "\\dvipost{osstart color push Red}\n"
1059 "\\dvipost{osend color pop}\n"
1060 "\\dvipost{cbstart color push Blue}\n"
1061 "\\dvipost{cbend color pop}\n";
1065 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1066 for (int j = 0; j != nlines; ++j) {
1075 void BufferParams::useClassDefaults()
1077 LyXTextClass const & tclass = textclasslist[textclass];
1079 sides = tclass.sides();
1080 columns = tclass.columns();
1081 pagestyle = tclass.pagestyle();
1082 options = tclass.options();
1083 // Only if class has a ToC hierarchy
1084 if (tclass.hasTocLevels()) {
1085 secnumdepth = tclass.secnumdepth();
1086 tocdepth = tclass.tocdepth();
1091 bool BufferParams::hasClassDefaults() const
1093 LyXTextClass const & tclass = textclasslist[textclass];
1095 return (sides == tclass.sides()
1096 && columns == tclass.columns()
1097 && pagestyle == tclass.pagestyle()
1098 && options == tclass.options()
1099 && secnumdepth == tclass.secnumdepth()
1100 && tocdepth == tclass.tocdepth());
1104 LyXTextClass const & BufferParams::getLyXTextClass() const
1106 return textclasslist[textclass];
1110 LyXFont const BufferParams::getFont() const
1112 LyXFont f = getLyXTextClass().defaultfont();
1113 f.setLanguage(language);
1118 void BufferParams::readPreamble(LyXLex & lex)
1120 if (lex.getString() != "\\begin_preamble")
1121 lyxerr << "Error (BufferParams::readPreamble):"
1122 "consistency check failed." << endl;
1124 preamble = lex.getLongString("\\end_preamble");
1128 void BufferParams::readLanguage(LyXLex & lex)
1130 if (!lex.next()) return;
1132 string const tmptok = lex.getString();
1134 // check if tmptok is part of tex_babel in tex-defs.h
1135 language = languages.getLanguage(tmptok);
1137 // Language tmptok was not found
1138 language = default_language;
1139 lyxerr << "Warning: Setting language `"
1140 << tmptok << "' to `" << language->lang()
1146 void BufferParams::readGraphicsDriver(LyXLex & lex)
1148 if (!lex.next()) return;
1150 string const tmptok = lex.getString();
1151 // check if tmptok is part of tex_graphics in tex_defs.h
1154 string const test = tex_graphics[n++];
1156 if (test == tmptok) {
1157 graphicsDriver = tmptok;
1159 } else if (test == "") {
1161 "Warning: graphics driver `$$Token' not recognized!\n"
1162 " Setting graphics driver to `default'.\n");
1163 graphicsDriver = "default";
1170 void BufferParams::readBullets(LyXLex & lex)
1172 if (!lex.next()) return;
1174 int const index = lex.getInteger();
1176 int temp_int = lex.getInteger();
1177 user_defined_bullet(index).setFont(temp_int);
1178 temp_bullet(index).setFont(temp_int);
1180 user_defined_bullet(index).setCharacter(temp_int);
1181 temp_bullet(index).setCharacter(temp_int);
1183 user_defined_bullet(index).setSize(temp_int);
1184 temp_bullet(index).setSize(temp_int);
1188 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1190 // The bullet class should be able to read this.
1191 if (!lex.next()) return;
1192 int const index = lex.getInteger();
1194 string const temp_str = lex.getString();
1196 user_defined_bullet(index).setText(temp_str);
1197 temp_bullet(index).setText(temp_str);
1201 string const BufferParams::paperSizeName() const
1203 char real_papersize = papersize;
1204 if (real_papersize == PAPER_DEFAULT)
1205 real_papersize = lyxrc.default_papersize;
1207 switch (real_papersize) {
1216 case PAPER_USEXECUTIVE:
1220 case PAPER_USLETTER:
1227 string const BufferParams::dvips_options() const
1232 && papersize == PAPER_CUSTOM
1233 && !lyxrc.print_paper_dimension_flag.empty()
1234 && !paperwidth.empty()
1235 && !paperheight.empty()) {
1236 // using a custom papersize
1237 result = lyxrc.print_paper_dimension_flag;
1238 result += ' ' + paperwidth;
1239 result += ',' + paperheight;
1241 string const paper_option = paperSizeName();
1242 if (paper_option != "letter" ||
1243 orientation != ORIENTATION_LANDSCAPE) {
1244 // dvips won't accept -t letter -t landscape.
1245 // In all other cases, include the paper size
1247 result = lyxrc.print_paper_flag;
1248 result += ' ' + paper_option;
1251 if (orientation == ORIENTATION_LANDSCAPE &&
1252 papersize != PAPER_CUSTOM)
1253 result += ' ' + lyxrc.print_landscape_flag;
1258 string const BufferParams::babelCall(string const & lang_opts) const
1260 string tmp = lyxrc.language_package;
1261 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1262 tmp = string("\\usepackage[") + lang_opts + "]{babel}";