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<int, InsetQuotes::quote_times> QuotesTimesTranslator;
112 QuotesTimesTranslator const init_quotestimestranslator()
114 QuotesTimesTranslator translator(1, InsetQuotes::SingleQ);
115 translator.addPair(2, InsetQuotes::DoubleQ);
120 QuotesTimesTranslator const & quotestimestranslator()
122 static QuotesTimesTranslator translator = init_quotestimestranslator();
128 typedef Translator<std::string, PAPER_SIZE> PaperSizeTranslator;
131 PaperSizeTranslator const init_papersizetranslator()
133 PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
134 translator.addPair(string_papersize[1], PAPER_CUSTOM);
135 translator.addPair(string_papersize[2], PAPER_USLETTER);
136 translator.addPair(string_papersize[3], PAPER_USLEGAL);
137 translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
138 translator.addPair(string_papersize[5], PAPER_A3);
139 translator.addPair(string_papersize[6], PAPER_A4);
140 translator.addPair(string_papersize[7], PAPER_A5);
141 translator.addPair(string_papersize[8], PAPER_B3);
142 translator.addPair(string_papersize[9], PAPER_B4);
143 translator.addPair(string_papersize[10], PAPER_B5);
148 PaperSizeTranslator const & papersizetranslator()
150 static PaperSizeTranslator translator = init_papersizetranslator();
156 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
159 PaperOrientationTranslator const init_paperorientationtranslator()
161 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
162 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
167 PaperOrientationTranslator const & paperorientationtranslator()
169 static PaperOrientationTranslator translator = init_paperorientationtranslator();
175 typedef Translator<int, LyXTextClass::PageSides> SidesTranslator;
178 SidesTranslator const init_sidestranslator()
180 SidesTranslator translator(1, LyXTextClass::OneSide);
181 translator.addPair(2, LyXTextClass::TwoSides);
186 SidesTranslator const & sidestranslator()
188 static SidesTranslator translator = init_sidestranslator();
195 typedef Translator<int, BufferParams::AMS> AMSTranslator;
198 AMSTranslator const init_amstranslator()
200 AMSTranslator translator(0, BufferParams::AMS_OFF);
201 translator.addPair(1, BufferParams::AMS_AUTO);
202 translator.addPair(2, BufferParams::AMS_ON);
207 AMSTranslator const & amstranslator()
209 static AMSTranslator translator = init_amstranslator();
215 typedef Translator<string, biblio::CiteEngine> CiteEngineTranslator;
218 CiteEngineTranslator const init_citeenginetranslator()
220 CiteEngineTranslator translator("basic", biblio::ENGINE_BASIC);
221 translator.addPair("natbib_numerical", biblio::ENGINE_NATBIB_NUMERICAL);
222 translator.addPair("natbib_authoryear", biblio::ENGINE_NATBIB_AUTHORYEAR);
223 translator.addPair("jurabib", biblio::ENGINE_JURABIB);
228 CiteEngineTranslator const & citeenginetranslator()
230 static CiteEngineTranslator translator = init_citeenginetranslator();
236 typedef Translator<string, Spacing::Space> SpaceTranslator;
239 SpaceTranslator const init_spacetranslator()
241 SpaceTranslator translator("default", Spacing::Default);
242 translator.addPair("single", Spacing::Single);
243 translator.addPair("onehalf", Spacing::Onehalf);
244 translator.addPair("double", Spacing::Double);
245 translator.addPair("other", Spacing::Other);
250 SpaceTranslator const & spacetranslator()
252 static SpaceTranslator translator = init_spacetranslator();
256 // ends annonym namespace
260 class BufferParams::Impl
265 AuthorList authorlist;
266 BranchList branchlist;
267 boost::array<Bullet, 4> temp_bullets;
268 boost::array<Bullet, 4> user_defined_bullets;
270 /** This is the amount of space used for paragraph_separation "skip",
271 * and for detached paragraphs in "indented" documents.
277 BufferParams::Impl::Impl()
278 : defskip(VSpace::MEDSKIP)
280 // set initial author
281 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
286 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
290 return new BufferParams::Impl(*ptr);
294 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
300 BufferParams::BufferParams()
301 : // Initialize textclass to point to article. if `first' is
302 // true in the returned pair, then `second' is the textclass
303 // number; if it is false, second is 0. In both cases, second
305 textclass(textclasslist.NumberOfClass("article").second),
308 paragraph_separation = PARSEP_INDENT;
309 quotes_language = InsetQuotes::EnglishQ;
310 quotes_times = InsetQuotes::DoubleQ;
311 fontsize = "default";
314 papersize = PAPER_DEFAULT;
315 orientation = ORIENTATION_PORTRAIT;
316 use_geometry = false;
317 use_amsmath = AMS_AUTO;
318 cite_engine = biblio::ENGINE_BASIC;
319 use_bibtopic = false;
320 tracking_changes = false;
321 output_changes = false;
324 language = default_language;
327 graphicsDriver = "default";
328 sides = LyXTextClass::OneSide;
330 pagestyle = "default";
332 for (int iter = 0; iter < 4; ++iter) {
333 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
334 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
339 BufferParams::~BufferParams()
343 AuthorList & BufferParams::authors()
345 return pimpl_->authorlist;
349 AuthorList const & BufferParams::authors() const
351 return pimpl_->authorlist;
355 BranchList & BufferParams::branchlist()
357 return pimpl_->branchlist;
361 BranchList const & BufferParams::branchlist() const
363 return pimpl_->branchlist;
367 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
369 BOOST_ASSERT(index < 4);
370 return pimpl_->temp_bullets[index];
374 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
376 BOOST_ASSERT(index < 4);
377 return pimpl_->temp_bullets[index];
381 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
383 BOOST_ASSERT(index < 4);
384 return pimpl_->user_defined_bullets[index];
388 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
390 BOOST_ASSERT(index < 4);
391 return pimpl_->user_defined_bullets[index];
395 Spacing & BufferParams::spacing()
397 return pimpl_->spacing;
401 Spacing const & BufferParams::spacing() const
403 return pimpl_->spacing;
407 VSpace const & BufferParams::getDefSkip() const
409 return pimpl_->defskip;
413 void BufferParams::setDefSkip(VSpace const & vs)
415 pimpl_->defskip = vs;
419 string const BufferParams::readToken(LyXLex & lex, string const & token)
421 if (token == "\\textclass") {
423 string const classname = lex.getString();
424 pair<bool, lyx::textclass_type> pp =
425 textclasslist.NumberOfClass(classname);
427 textclass = pp.second;
432 if (!getLyXTextClass().isTeXClassAvailable()) {
434 bformat(_("The document uses a missing "
435 "TeX class \"%1$s\".\n"), classname);
436 Alert::warning(_("Document class not available"),
437 msg + _("LyX will not be able to produce output."));
439 } else if (token == "\\begin_preamble") {
441 } else if (token == "\\options") {
443 options = lex.getString();
444 } else if (token == "\\language") {
446 } else if (token == "\\inputencoding") {
448 } else if (token == "\\graphics") {
449 readGraphicsDriver(lex);
450 } else if (token == "\\fontscheme") {
452 } else if (token == "\\paragraph_separation") {
455 paragraph_separation = parseptranslator().find(parsep);
456 } else if (token == "\\defskip") {
458 pimpl_->defskip = VSpace(lex.getString());
459 } else if (token == "\\quotes_language") {
462 quotes_language = quoteslangtranslator().find(quotes_lang);
463 } else if (token == "\\quotes_times") {
466 quotes_times = quotestimestranslator().find(qtimes);
467 } else if (token == "\\papersize") {
470 papersize = papersizetranslator().find(ppsize);
471 } else if (token == "\\use_geometry") {
473 } else if (token == "\\use_amsmath") {
476 use_amsmath = amstranslator().find(use_ams);
477 } else if (token == "\\cite_engine") {
480 cite_engine = citeenginetranslator().find(engine);
481 } else if (token == "\\use_bibtopic") {
483 } else if (token == "\\tracking_changes") {
484 lex >> tracking_changes;
485 } else if (token == "\\output_changes") {
486 lex >> output_changes;
487 } else if (token == "\\branch") {
489 string branch = lex.getString();
490 branchlist().add(branch);
493 string const tok = lex.getString();
494 if (tok == "\\end_branch")
496 Branch * branch_ptr = branchlist().find(branch);
497 if (tok == "\\selected") {
500 branch_ptr->setSelected(lex.getInteger());
502 // not yet operational
503 if (tok == "\\color") {
505 string color = lex.getString();
507 branch_ptr->setColor(color);
508 // Update also the LColor table:
510 color = lcolor.getX11Name(LColor::background);
511 lcolor.setColor(branch, color);
515 } else if (token == "\\author") {
517 istringstream ss(lex.getString());
520 author_map.push_back(pimpl_->authorlist.record(a));
521 } else if (token == "\\paperorientation") {
524 orientation = paperorientationtranslator().find(orient);
525 } else if (token == "\\paperwidth") {
527 } else if (token == "\\paperheight") {
529 } else if (token == "\\leftmargin") {
531 } else if (token == "\\topmargin") {
533 } else if (token == "\\rightmargin") {
535 } else if (token == "\\bottommargin") {
537 } else if (token == "\\headheight") {
539 } else if (token == "\\headsep") {
541 } else if (token == "\\footskip") {
543 } else if (token == "\\paperfontsize") {
545 } else if (token == "\\papercolumns") {
547 } else if (token == "\\papersides") {
550 sides = sidestranslator().find(psides);
551 } else if (token == "\\paperpagestyle") {
553 } else if (token == "\\bullet") {
555 } else if (token == "\\bulletLaTeX") {
556 readBulletsLaTeX(lex);
557 } else if (token == "\\secnumdepth") {
559 } else if (token == "\\tocdepth") {
561 } else if (token == "\\spacing") {
565 if (nspacing == "other") {
568 spacing().set(spacetranslator().find(nspacing), tmp_val);
569 } else if (token == "\\float_placement") {
570 lex >> float_placement;
579 void BufferParams::writeFile(ostream & os) const
581 // The top of the file is written by the buffer.
582 // Prints out the buffer info into the .lyx file given by file
585 os << "\\textclass " << textclasslist[textclass].name() << '\n';
587 // then the the preamble
588 if (!preamble.empty()) {
589 // remove '\n' from the end of preamble
590 string const tmppreamble = rtrim(preamble, "\n");
591 os << "\\begin_preamble\n"
593 << "\n\\end_preamble\n";
597 if (!options.empty()) {
598 os << "\\options " << options << '\n';
601 // then the text parameters
602 if (language != ignore_language)
603 os << "\\language " << language->lang() << '\n';
604 os << "\\inputencoding " << inputenc
605 << "\n\\fontscheme " << fonts
606 << "\n\\graphics " << graphicsDriver << '\n';
608 if (!float_placement.empty()) {
609 os << "\\float_placement " << float_placement << '\n';
611 os << "\\paperfontsize " << fontsize << '\n';
613 spacing().writeFile(os);
615 os << "\\papersize " << string_papersize[papersize]
616 << "\n\\use_geometry " << convert<string>(use_geometry)
617 << "\n\\use_amsmath " << use_amsmath
618 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
619 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
620 << "\n\\paperorientation " << string_orientation[orientation]
623 std::list<Branch>::const_iterator it = branchlist().begin();
624 std::list<Branch>::const_iterator end = branchlist().end();
625 for (; it != end; ++it) {
626 os << "\\branch " << it->getBranch()
627 << "\n\\selected " << it->getSelected()
628 << "\n\\color " << it->getColor()
633 if (!paperwidth.empty())
634 os << "\\paperwidth "
635 << VSpace(paperwidth).asLyXCommand() << '\n';
636 if (!paperheight.empty())
637 os << "\\paperheight "
638 << VSpace(paperheight).asLyXCommand() << '\n';
639 if (!leftmargin.empty())
640 os << "\\leftmargin "
641 << VSpace(leftmargin).asLyXCommand() << '\n';
642 if (!topmargin.empty())
644 << VSpace(topmargin).asLyXCommand() << '\n';
645 if (!rightmargin.empty())
646 os << "\\rightmargin "
647 << VSpace(rightmargin).asLyXCommand() << '\n';
648 if (!bottommargin.empty())
649 os << "\\bottommargin "
650 << VSpace(bottommargin).asLyXCommand() << '\n';
651 if (!headheight.empty())
652 os << "\\headheight "
653 << VSpace(headheight).asLyXCommand() << '\n';
654 if (!headsep.empty())
656 << VSpace(headsep).asLyXCommand() << '\n';
657 if (!footskip.empty())
659 << VSpace(footskip).asLyXCommand() << '\n';
660 os << "\\secnumdepth " << secnumdepth
661 << "\n\\tocdepth " << tocdepth
662 << "\n\\paragraph_separation "
663 << string_paragraph_separation[paragraph_separation]
664 << "\n\\defskip " << getDefSkip().asLyXCommand()
665 << "\n\\quotes_language "
666 << string_quotes_language[quotes_language] << '\n'
668 << quotestimestranslator().find(quotes_times)
669 << "\n\\papercolumns " << columns
670 << "\n\\papersides " << sides
671 << "\n\\paperpagestyle " << pagestyle << '\n';
672 for (int i = 0; i < 4; ++i) {
673 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
674 if (user_defined_bullet(i).getFont() != -1) {
675 os << "\\bullet " << i << " "
676 << user_defined_bullet(i).getFont() << " "
677 << user_defined_bullet(i).getCharacter() << " "
678 << user_defined_bullet(i).getSize() << "\n";
681 os << "\\bulletLaTeX " << i << " \""
682 << user_defined_bullet(i).getText()
688 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
689 os << "\\output_changes " << convert<string>(output_changes) << "\n";
691 if (tracking_changes) {
692 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
693 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
694 for (; it != end; ++it) {
695 os << "\\author " << it->second << "\n";
701 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
702 TexRow & texrow) const
704 os << "\\documentclass";
706 LyXTextClass const & tclass = getLyXTextClass();
708 ostringstream clsoptions; // the document class options.
710 if (tokenPos(tclass.opt_fontsize(),
711 '|', fontsize) >= 0) {
712 // only write if existing in list (and not default)
713 clsoptions << fontsize << "pt,";
716 // custom, A3, B3 and B4 paper sizes need geometry
717 bool nonstandard_papersize = (papersize == PAPER_B3) ||
718 (papersize == PAPER_B4) ||
719 (papersize == PAPER_A3) ||
720 (papersize == PAPER_CUSTOM);
725 clsoptions << "a4paper,";
728 clsoptions << "letterpaper,";
731 clsoptions << "a5paper,";
734 clsoptions << "b5paper,";
736 case PAPER_USEXECUTIVE:
737 clsoptions << "executivepaper,";
740 clsoptions << "legalpaper,";
752 if (sides != tclass.sides()) {
754 case LyXTextClass::OneSide:
755 clsoptions << "oneside,";
757 case LyXTextClass::TwoSides:
758 clsoptions << "twoside,";
764 if (columns != tclass.columns()) {
766 clsoptions << "twocolumn,";
768 clsoptions << "onecolumn,";
772 && orientation == ORIENTATION_LANDSCAPE)
773 clsoptions << "landscape,";
775 // language should be a parameter to \documentclass
776 if (language->babel() == "hebrew"
777 && default_language->babel() != "hebrew")
778 // This seems necessary
779 features.useLanguage(default_language);
781 ostringstream language_options;
782 bool const use_babel = features.useBabel();
784 language_options << features.getLanguages();
785 language_options << language->babel();
786 if (lyxrc.language_global_options)
787 clsoptions << language_options.str() << ',';
790 // the user-defined options
791 if (!options.empty()) {
792 clsoptions << options << ',';
795 string strOptions(clsoptions.str());
796 if (!strOptions.empty()) {
797 strOptions = rtrim(strOptions, ",");
798 os << '[' << strOptions << ']';
801 os << '{' << tclass.latexname() << "}\n";
803 // end of \documentclass defs
805 // font selection must be done before loading fontenc.sty
806 // The ae package is not needed when using OT1 font encoding.
807 if (fonts != "default" &&
808 (fonts != "ae" || lyxrc.fontenc != "default")) {
809 os << "\\usepackage{" << fonts << "}\n";
812 os << "\\usepackage{aecompl}\n";
816 // this one is not per buffer
817 if (lyxrc.fontenc != "default") {
818 os << "\\usepackage[" << lyxrc.fontenc
823 if (inputenc == "auto") {
824 string const doc_encoding =
825 language->encoding()->LatexName();
827 // Create a list with all the input encodings used
829 std::set<string> encodings =
830 features.getEncodingSet(doc_encoding);
832 os << "\\usepackage[";
833 std::copy(encodings.begin(), encodings.end(),
834 std::ostream_iterator<string>(os, ","));
835 os << doc_encoding << "]{inputenc}\n";
837 } else if (inputenc != "default") {
838 os << "\\usepackage[" << inputenc
843 if (use_geometry || nonstandard_papersize) {
844 os << "\\usepackage{geometry}\n";
846 os << "\\geometry{verbose";
847 if (orientation == ORIENTATION_LANDSCAPE)
851 if (!paperwidth.empty())
854 if (!paperheight.empty())
855 os << ",paperheight="
859 os << ",letterpaper";
864 case PAPER_USEXECUTIVE:
865 os << ",executivepaper";
886 // default papersize ie PAPER_DEFAULT
887 switch (lyxrc.default_papersize) {
888 case PAPER_DEFAULT: // keep compiler happy
890 os << ",letterpaper";
895 case PAPER_USEXECUTIVE:
896 os << ",executivepaper";
916 if (!topmargin.empty())
917 os << ",tmargin=" << topmargin;
918 if (!bottommargin.empty())
919 os << ",bmargin=" << bottommargin;
920 if (!leftmargin.empty())
921 os << ",lmargin=" << leftmargin;
922 if (!rightmargin.empty())
923 os << ",rmargin=" << rightmargin;
924 if (!headheight.empty())
925 os << ",headheight=" << headheight;
926 if (!headsep.empty())
927 os << ",headsep=" << headsep;
928 if (!footskip.empty())
929 os << ",footskip=" << footskip;
934 if (tokenPos(tclass.opt_pagestyle(),
935 '|', pagestyle) >= 0) {
936 if (pagestyle == "fancy") {
937 os << "\\usepackage{fancyhdr}\n";
940 os << "\\pagestyle{" << pagestyle << "}\n";
944 if (secnumdepth != tclass.secnumdepth()) {
945 os << "\\setcounter{secnumdepth}{"
950 if (tocdepth != tclass.tocdepth()) {
951 os << "\\setcounter{tocdepth}{"
957 if (paragraph_separation) {
958 switch (getDefSkip().kind()) {
959 case VSpace::SMALLSKIP:
960 os << "\\setlength\\parskip{\\smallskipamount}\n";
962 case VSpace::MEDSKIP:
963 os << "\\setlength\\parskip{\\medskipamount}\n";
965 case VSpace::BIGSKIP:
966 os << "\\setlength\\parskip{\\bigskipamount}\n";
969 os << "\\setlength\\parskip{"
970 << getDefSkip().length().asLatexString()
973 default: // should never happen // Then delete it.
974 os << "\\setlength\\parskip{\\medskipamount}\n";
979 os << "\\setlength\\parindent{0pt}\n";
983 // If we use jurabib, we have to call babel here.
984 if (use_babel && features.isRequired("jurabib")) {
985 os << babelCall(language_options.str())
987 << features.getBabelOptions();
991 // Now insert the LyX specific LaTeX commands...
993 // The optional packages;
994 string lyxpreamble(features.getPackages());
996 // this might be useful...
997 lyxpreamble += "\n\\makeatletter\n";
999 // Some macros LyX will need
1000 string tmppreamble(features.getMacros());
1002 if (!tmppreamble.empty()) {
1003 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1004 "LyX specific LaTeX commands.\n"
1005 + tmppreamble + '\n';
1008 // the text class specific preamble
1009 tmppreamble = features.getTClassPreamble();
1010 if (!tmppreamble.empty()) {
1011 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1012 "Textclass specific LaTeX commands.\n"
1013 + tmppreamble + '\n';
1016 /* the user-defined preamble */
1017 if (!preamble.empty()) {
1018 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1019 "User specified LaTeX commands.\n"
1023 // Itemize bullet settings need to be last in case the user
1024 // defines their own bullets that use a package included
1025 // in the user-defined preamble -- ARRae
1026 // Actually it has to be done much later than that
1027 // since some packages like frenchb make modifications
1028 // at \begin{document} time -- JMarc
1030 for (int i = 0; i < 4; ++i) {
1031 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1032 if (bullets_def.empty())
1033 bullets_def="\\AtBeginDocument{\n";
1034 bullets_def += " \\renewcommand{\\labelitemi";
1036 // `i' is one less than the item to modify
1043 bullets_def += "ii";
1049 bullets_def += "}{" +
1050 user_defined_bullet(i).getText()
1055 if (!bullets_def.empty())
1056 lyxpreamble += bullets_def + "}\n\n";
1058 // We try to load babel late, in case it interferes
1059 // with other packages.
1060 // Jurabib has to be called after babel, though.
1061 if (use_babel && !features.isRequired("jurabib")) {
1062 lyxpreamble += babelCall(language_options.str()) + '\n';
1063 lyxpreamble += features.getBabelOptions();
1066 lyxpreamble += "\\makeatother\n";
1068 // dvipost settings come after everything else
1069 if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
1072 "\\dvipost{osstart color push Red}\n"
1073 "\\dvipost{osend color pop}\n"
1074 "\\dvipost{cbstart color push Blue}\n"
1075 "\\dvipost{cbend color pop}\n";
1079 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1080 for (int j = 0; j != nlines; ++j) {
1089 void BufferParams::useClassDefaults()
1091 LyXTextClass const & tclass = textclasslist[textclass];
1093 sides = tclass.sides();
1094 columns = tclass.columns();
1095 pagestyle = tclass.pagestyle();
1096 options = tclass.options();
1097 secnumdepth = tclass.secnumdepth();
1098 tocdepth = tclass.tocdepth();
1102 bool BufferParams::hasClassDefaults() const
1104 LyXTextClass const & tclass = textclasslist[textclass];
1106 return (sides == tclass.sides()
1107 && columns == tclass.columns()
1108 && pagestyle == tclass.pagestyle()
1109 && options == tclass.options()
1110 && secnumdepth == tclass.secnumdepth()
1111 && tocdepth == tclass.tocdepth());
1115 LyXTextClass const & BufferParams::getLyXTextClass() const
1117 return textclasslist[textclass];
1121 void BufferParams::readPreamble(LyXLex & lex)
1123 if (lex.getString() != "\\begin_preamble")
1124 lyxerr << "Error (BufferParams::readPreamble):"
1125 "consistency check failed." << endl;
1127 preamble = lex.getLongString("\\end_preamble");
1131 void BufferParams::readLanguage(LyXLex & lex)
1133 if (!lex.next()) return;
1135 string const tmptok = lex.getString();
1137 // check if tmptok is part of tex_babel in tex-defs.h
1138 language = languages.getLanguage(tmptok);
1140 // Language tmptok was not found
1141 language = default_language;
1142 lyxerr << "Warning: Setting language `"
1143 << tmptok << "' to `" << language->lang()
1149 void BufferParams::readGraphicsDriver(LyXLex & lex)
1151 if (!lex.next()) return;
1153 string const tmptok = lex.getString();
1154 // check if tmptok is part of tex_graphics in tex_defs.h
1157 string const test = tex_graphics[n++];
1159 if (test == tmptok) {
1160 graphicsDriver = tmptok;
1162 } else if (test == "") {
1164 "Warning: graphics driver `$$Token' not recognized!\n"
1165 " Setting graphics driver to `default'.\n");
1166 graphicsDriver = "default";
1173 void BufferParams::readBullets(LyXLex & lex)
1175 if (!lex.next()) return;
1177 int const index = lex.getInteger();
1179 int temp_int = lex.getInteger();
1180 user_defined_bullet(index).setFont(temp_int);
1181 temp_bullet(index).setFont(temp_int);
1183 user_defined_bullet(index).setCharacter(temp_int);
1184 temp_bullet(index).setCharacter(temp_int);
1186 user_defined_bullet(index).setSize(temp_int);
1187 temp_bullet(index).setSize(temp_int);
1191 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1193 // The bullet class should be able to read this.
1194 if (!lex.next()) return;
1195 int const index = lex.getInteger();
1197 string const temp_str = lex.getString();
1199 user_defined_bullet(index).setText(temp_str);
1200 temp_bullet(index).setText(temp_str);
1204 string const BufferParams::paperSizeName() const
1206 char real_papersize = papersize;
1207 if (real_papersize == PAPER_DEFAULT)
1208 real_papersize = lyxrc.default_papersize;
1210 switch (real_papersize) {
1219 case PAPER_USEXECUTIVE:
1223 case PAPER_USLETTER:
1230 string const BufferParams::dvips_options() const
1235 && papersize == PAPER_CUSTOM
1236 && !lyxrc.print_paper_dimension_flag.empty()
1237 && !paperwidth.empty()
1238 && !paperheight.empty()) {
1239 // using a custom papersize
1240 result = lyxrc.print_paper_dimension_flag;
1241 result += ' ' + paperwidth;
1242 result += ',' + paperheight;
1244 string const paper_option = paperSizeName();
1245 if (paper_option != "letter" ||
1246 orientation != ORIENTATION_LANDSCAPE) {
1247 // dvips won't accept -t letter -t landscape.
1248 // In all other cases, include the paper size
1250 result = lyxrc.print_paper_flag;
1251 result += ' ' + paper_option;
1254 if (orientation == ORIENTATION_LANDSCAPE &&
1255 papersize != PAPER_CUSTOM)
1256 result += ' ' + lyxrc.print_landscape_flag;
1261 string const BufferParams::babelCall(string const & lang_opts) const
1263 string tmp = lyxrc.language_package;
1264 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1265 tmp = string("\\usepackage[") + lang_opts + "]{babel}";