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;
412 if (!getLyXTextClass().isTeXClassAvailable()) {
414 bformat(_("The document uses a missing "
415 "TeX class \"%1$s\".\n"), classname);
416 Alert::warning(_("Document class not available"),
417 msg + _("LyX will not be able to produce output."));
419 } else if (token == "\\begin_preamble") {
421 } else if (token == "\\options") {
423 options = lex.getString();
424 } else if (token == "\\language") {
426 } else if (token == "\\inputencoding") {
428 } else if (token == "\\graphics") {
429 readGraphicsDriver(lex);
430 } else if (token == "\\fontscheme") {
432 } else if (token == "\\paragraph_separation") {
435 paragraph_separation = parseptranslator().find(parsep);
436 } else if (token == "\\defskip") {
438 pimpl_->defskip = VSpace(lex.getString());
439 } else if (token == "\\quotes_language") {
442 quotes_language = quoteslangtranslator().find(quotes_lang);
443 } else if (token == "\\papersize") {
446 papersize = papersizetranslator().find(ppsize);
447 } else if (token == "\\use_geometry") {
449 } else if (token == "\\use_amsmath") {
452 use_amsmath = amstranslator().find(use_ams);
453 } else if (token == "\\cite_engine") {
456 cite_engine = citeenginetranslator().find(engine);
457 } else if (token == "\\use_bibtopic") {
459 } else if (token == "\\tracking_changes") {
460 lex >> tracking_changes;
461 } else if (token == "\\output_changes") {
462 lex >> output_changes;
463 } else if (token == "\\branch") {
465 string branch = lex.getString();
466 branchlist().add(branch);
469 string const tok = lex.getString();
470 if (tok == "\\end_branch")
472 Branch * branch_ptr = branchlist().find(branch);
473 if (tok == "\\selected") {
476 branch_ptr->setSelected(lex.getInteger());
478 // not yet operational
479 if (tok == "\\color") {
481 string color = lex.getString();
483 branch_ptr->setColor(color);
484 // Update also the LColor table:
486 color = lcolor.getX11Name(LColor::background);
487 lcolor.setColor(branch, color);
491 } else if (token == "\\author") {
493 istringstream ss(lex.getString());
496 author_map.push_back(pimpl_->authorlist.record(a));
497 } else if (token == "\\paperorientation") {
500 orientation = paperorientationtranslator().find(orient);
501 } else if (token == "\\paperwidth") {
503 } else if (token == "\\paperheight") {
505 } else if (token == "\\leftmargin") {
507 } else if (token == "\\topmargin") {
509 } else if (token == "\\rightmargin") {
511 } else if (token == "\\bottommargin") {
513 } else if (token == "\\headheight") {
515 } else if (token == "\\headsep") {
517 } else if (token == "\\footskip") {
519 } else if (token == "\\paperfontsize") {
521 } else if (token == "\\papercolumns") {
523 } else if (token == "\\papersides") {
526 sides = sidestranslator().find(psides);
527 } else if (token == "\\paperpagestyle") {
529 } else if (token == "\\bullet") {
531 } else if (token == "\\bulletLaTeX") {
532 readBulletsLaTeX(lex);
533 } else if (token == "\\secnumdepth") {
535 } else if (token == "\\tocdepth") {
537 } else if (token == "\\spacing") {
541 if (nspacing == "other") {
544 spacing().set(spacetranslator().find(nspacing), tmp_val);
545 } else if (token == "\\float_placement") {
546 lex >> float_placement;
555 void BufferParams::writeFile(ostream & os) const
557 // The top of the file is written by the buffer.
558 // Prints out the buffer info into the .lyx file given by file
561 os << "\\textclass " << textclasslist[textclass].name() << '\n';
563 // then the the preamble
564 if (!preamble.empty()) {
565 // remove '\n' from the end of preamble
566 string const tmppreamble = rtrim(preamble, "\n");
567 os << "\\begin_preamble\n"
569 << "\n\\end_preamble\n";
573 if (!options.empty()) {
574 os << "\\options " << options << '\n';
577 // then the text parameters
578 if (language != ignore_language)
579 os << "\\language " << language->lang() << '\n';
580 os << "\\inputencoding " << inputenc
581 << "\n\\fontscheme " << fonts
582 << "\n\\graphics " << graphicsDriver << '\n';
584 if (!float_placement.empty()) {
585 os << "\\float_placement " << float_placement << '\n';
587 os << "\\paperfontsize " << fontsize << '\n';
589 spacing().writeFile(os);
591 os << "\\papersize " << string_papersize[papersize]
592 << "\n\\use_geometry " << convert<string>(use_geometry)
593 << "\n\\use_amsmath " << use_amsmath
594 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
595 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
596 << "\n\\paperorientation " << string_orientation[orientation]
599 std::list<Branch>::const_iterator it = branchlist().begin();
600 std::list<Branch>::const_iterator end = branchlist().end();
601 for (; it != end; ++it) {
602 os << "\\branch " << it->getBranch()
603 << "\n\\selected " << it->getSelected()
604 << "\n\\color " << it->getColor()
609 if (!paperwidth.empty())
610 os << "\\paperwidth "
611 << VSpace(paperwidth).asLyXCommand() << '\n';
612 if (!paperheight.empty())
613 os << "\\paperheight "
614 << VSpace(paperheight).asLyXCommand() << '\n';
615 if (!leftmargin.empty())
616 os << "\\leftmargin "
617 << VSpace(leftmargin).asLyXCommand() << '\n';
618 if (!topmargin.empty())
620 << VSpace(topmargin).asLyXCommand() << '\n';
621 if (!rightmargin.empty())
622 os << "\\rightmargin "
623 << VSpace(rightmargin).asLyXCommand() << '\n';
624 if (!bottommargin.empty())
625 os << "\\bottommargin "
626 << VSpace(bottommargin).asLyXCommand() << '\n';
627 if (!headheight.empty())
628 os << "\\headheight "
629 << VSpace(headheight).asLyXCommand() << '\n';
630 if (!headsep.empty())
632 << VSpace(headsep).asLyXCommand() << '\n';
633 if (!footskip.empty())
635 << VSpace(footskip).asLyXCommand() << '\n';
636 os << "\\secnumdepth " << secnumdepth
637 << "\n\\tocdepth " << tocdepth
638 << "\n\\paragraph_separation "
639 << string_paragraph_separation[paragraph_separation]
640 << "\n\\defskip " << getDefSkip().asLyXCommand()
641 << "\n\\quotes_language "
642 << string_quotes_language[quotes_language]
643 << "\n\\papercolumns " << columns
644 << "\n\\papersides " << sides
645 << "\n\\paperpagestyle " << pagestyle << '\n';
646 for (int i = 0; i < 4; ++i) {
647 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
648 if (user_defined_bullet(i).getFont() != -1) {
649 os << "\\bullet " << i << " "
650 << user_defined_bullet(i).getFont() << " "
651 << user_defined_bullet(i).getCharacter() << " "
652 << user_defined_bullet(i).getSize() << "\n";
655 os << "\\bulletLaTeX " << i << " \""
656 << user_defined_bullet(i).getText()
662 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
663 os << "\\output_changes " << convert<string>(output_changes) << "\n";
665 if (tracking_changes) {
666 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
667 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
668 for (; it != end; ++it) {
669 os << "\\author " << it->second << "\n";
675 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
676 TexRow & texrow) const
678 os << "\\documentclass";
680 LyXTextClass const & tclass = getLyXTextClass();
682 ostringstream clsoptions; // the document class options.
684 if (tokenPos(tclass.opt_fontsize(),
685 '|', fontsize) >= 0) {
686 // only write if existing in list (and not default)
687 clsoptions << fontsize << "pt,";
690 // custom, A3, B3 and B4 paper sizes need geometry
691 bool nonstandard_papersize = (papersize == PAPER_B3) ||
692 (papersize == PAPER_B4) ||
693 (papersize == PAPER_A3) ||
694 (papersize == PAPER_CUSTOM);
699 clsoptions << "a4paper,";
702 clsoptions << "letterpaper,";
705 clsoptions << "a5paper,";
708 clsoptions << "b5paper,";
710 case PAPER_USEXECUTIVE:
711 clsoptions << "executivepaper,";
714 clsoptions << "legalpaper,";
726 if (sides != tclass.sides()) {
728 case LyXTextClass::OneSide:
729 clsoptions << "oneside,";
731 case LyXTextClass::TwoSides:
732 clsoptions << "twoside,";
738 if (columns != tclass.columns()) {
740 clsoptions << "twocolumn,";
742 clsoptions << "onecolumn,";
746 && orientation == ORIENTATION_LANDSCAPE)
747 clsoptions << "landscape,";
749 // language should be a parameter to \documentclass
750 if (language->babel() == "hebrew"
751 && default_language->babel() != "hebrew")
752 // This seems necessary
753 features.useLanguage(default_language);
755 ostringstream language_options;
756 bool const use_babel = features.useBabel();
758 language_options << features.getLanguages();
759 language_options << language->babel();
760 if (lyxrc.language_global_options)
761 clsoptions << language_options.str() << ',';
764 // the user-defined options
765 if (!options.empty()) {
766 clsoptions << options << ',';
769 string strOptions(clsoptions.str());
770 if (!strOptions.empty()) {
771 strOptions = rtrim(strOptions, ",");
772 os << '[' << strOptions << ']';
775 os << '{' << tclass.latexname() << "}\n";
777 // end of \documentclass defs
779 // font selection must be done before loading fontenc.sty
780 // The ae package is not needed when using OT1 font encoding.
781 if (fonts != "default" &&
782 (fonts != "ae" || lyxrc.fontenc != "default")) {
783 os << "\\usepackage{" << fonts << "}\n";
786 os << "\\usepackage{aecompl}\n";
790 // this one is not per buffer
791 if (lyxrc.fontenc != "default") {
792 os << "\\usepackage[" << lyxrc.fontenc
797 if (inputenc == "auto") {
798 string const doc_encoding =
799 language->encoding()->LatexName();
801 // Create a list with all the input encodings used
803 std::set<string> encodings =
804 features.getEncodingSet(doc_encoding);
806 os << "\\usepackage[";
807 std::copy(encodings.begin(), encodings.end(),
808 std::ostream_iterator<string>(os, ","));
809 os << doc_encoding << "]{inputenc}\n";
811 } else if (inputenc != "default") {
812 os << "\\usepackage[" << inputenc
817 if (use_geometry || nonstandard_papersize) {
818 os << "\\usepackage{geometry}\n";
820 os << "\\geometry{verbose";
821 if (orientation == ORIENTATION_LANDSCAPE)
825 if (!paperwidth.empty())
828 if (!paperheight.empty())
829 os << ",paperheight="
833 os << ",letterpaper";
838 case PAPER_USEXECUTIVE:
839 os << ",executivepaper";
860 // default papersize ie PAPER_DEFAULT
861 switch (lyxrc.default_papersize) {
862 case PAPER_DEFAULT: // keep compiler happy
864 os << ",letterpaper";
869 case PAPER_USEXECUTIVE:
870 os << ",executivepaper";
890 if (!topmargin.empty())
891 os << ",tmargin=" << topmargin;
892 if (!bottommargin.empty())
893 os << ",bmargin=" << bottommargin;
894 if (!leftmargin.empty())
895 os << ",lmargin=" << leftmargin;
896 if (!rightmargin.empty())
897 os << ",rmargin=" << rightmargin;
898 if (!headheight.empty())
899 os << ",headheight=" << headheight;
900 if (!headsep.empty())
901 os << ",headsep=" << headsep;
902 if (!footskip.empty())
903 os << ",footskip=" << footskip;
908 if (tokenPos(tclass.opt_pagestyle(),
909 '|', pagestyle) >= 0) {
910 if (pagestyle == "fancy") {
911 os << "\\usepackage{fancyhdr}\n";
914 os << "\\pagestyle{" << pagestyle << "}\n";
918 if (secnumdepth != tclass.secnumdepth()) {
919 os << "\\setcounter{secnumdepth}{"
924 if (tocdepth != tclass.tocdepth()) {
925 os << "\\setcounter{tocdepth}{"
931 if (paragraph_separation) {
932 switch (getDefSkip().kind()) {
933 case VSpace::SMALLSKIP:
934 os << "\\setlength\\parskip{\\smallskipamount}\n";
936 case VSpace::MEDSKIP:
937 os << "\\setlength\\parskip{\\medskipamount}\n";
939 case VSpace::BIGSKIP:
940 os << "\\setlength\\parskip{\\bigskipamount}\n";
943 os << "\\setlength\\parskip{"
944 << getDefSkip().length().asLatexString()
947 default: // should never happen // Then delete it.
948 os << "\\setlength\\parskip{\\medskipamount}\n";
953 os << "\\setlength\\parindent{0pt}\n";
957 // If we use jurabib, we have to call babel here.
958 if (use_babel && features.isRequired("jurabib")) {
959 os << babelCall(language_options.str())
961 << features.getBabelOptions();
965 // Now insert the LyX specific LaTeX commands...
967 // The optional packages;
968 string lyxpreamble(features.getPackages());
970 // this might be useful...
971 lyxpreamble += "\n\\makeatletter\n";
973 // Some macros LyX will need
974 string tmppreamble(features.getMacros());
976 if (!tmppreamble.empty()) {
977 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
978 "LyX specific LaTeX commands.\n"
979 + tmppreamble + '\n';
982 // the text class specific preamble
983 tmppreamble = features.getTClassPreamble();
984 if (!tmppreamble.empty()) {
985 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
986 "Textclass specific LaTeX commands.\n"
987 + tmppreamble + '\n';
990 /* the user-defined preamble */
991 if (!preamble.empty()) {
992 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
993 "User specified LaTeX commands.\n"
997 // Itemize bullet settings need to be last in case the user
998 // defines their own bullets that use a package included
999 // in the user-defined preamble -- ARRae
1000 // Actually it has to be done much later than that
1001 // since some packages like frenchb make modifications
1002 // at \begin{document} time -- JMarc
1004 for (int i = 0; i < 4; ++i) {
1005 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1006 if (bullets_def.empty())
1007 bullets_def="\\AtBeginDocument{\n";
1008 bullets_def += " \\renewcommand{\\labelitemi";
1010 // `i' is one less than the item to modify
1017 bullets_def += "ii";
1023 bullets_def += "}{" +
1024 user_defined_bullet(i).getText()
1029 if (!bullets_def.empty())
1030 lyxpreamble += bullets_def + "}\n\n";
1032 // We try to load babel late, in case it interferes
1033 // with other packages.
1034 // Jurabib has to be called after babel, though.
1035 if (use_babel && !features.isRequired("jurabib")) {
1036 lyxpreamble += babelCall(language_options.str()) + '\n';
1037 lyxpreamble += features.getBabelOptions();
1040 lyxpreamble += "\\makeatother\n";
1042 // dvipost settings come after everything else
1043 if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
1046 "\\dvipost{osstart color push Red}\n"
1047 "\\dvipost{osend color pop}\n"
1048 "\\dvipost{cbstart color push Blue}\n"
1049 "\\dvipost{cbend color pop}\n";
1053 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1054 for (int j = 0; j != nlines; ++j) {
1063 void BufferParams::useClassDefaults()
1065 LyXTextClass const & tclass = textclasslist[textclass];
1067 sides = tclass.sides();
1068 columns = tclass.columns();
1069 pagestyle = tclass.pagestyle();
1070 options = tclass.options();
1071 secnumdepth = tclass.secnumdepth();
1072 tocdepth = tclass.tocdepth();
1076 bool BufferParams::hasClassDefaults() const
1078 LyXTextClass const & tclass = textclasslist[textclass];
1080 return (sides == tclass.sides()
1081 && columns == tclass.columns()
1082 && pagestyle == tclass.pagestyle()
1083 && options == tclass.options()
1084 && secnumdepth == tclass.secnumdepth()
1085 && tocdepth == tclass.tocdepth());
1089 LyXTextClass const & BufferParams::getLyXTextClass() const
1091 return textclasslist[textclass];
1095 void BufferParams::readPreamble(LyXLex & lex)
1097 if (lex.getString() != "\\begin_preamble")
1098 lyxerr << "Error (BufferParams::readPreamble):"
1099 "consistency check failed." << endl;
1101 preamble = lex.getLongString("\\end_preamble");
1105 void BufferParams::readLanguage(LyXLex & lex)
1107 if (!lex.next()) return;
1109 string const tmptok = lex.getString();
1111 // check if tmptok is part of tex_babel in tex-defs.h
1112 language = languages.getLanguage(tmptok);
1114 // Language tmptok was not found
1115 language = default_language;
1116 lyxerr << "Warning: Setting language `"
1117 << tmptok << "' to `" << language->lang()
1123 void BufferParams::readGraphicsDriver(LyXLex & lex)
1125 if (!lex.next()) return;
1127 string const tmptok = lex.getString();
1128 // check if tmptok is part of tex_graphics in tex_defs.h
1131 string const test = tex_graphics[n++];
1133 if (test == tmptok) {
1134 graphicsDriver = tmptok;
1136 } else if (test == "") {
1138 "Warning: graphics driver `$$Token' not recognized!\n"
1139 " Setting graphics driver to `default'.\n");
1140 graphicsDriver = "default";
1147 void BufferParams::readBullets(LyXLex & lex)
1149 if (!lex.next()) return;
1151 int const index = lex.getInteger();
1153 int temp_int = lex.getInteger();
1154 user_defined_bullet(index).setFont(temp_int);
1155 temp_bullet(index).setFont(temp_int);
1157 user_defined_bullet(index).setCharacter(temp_int);
1158 temp_bullet(index).setCharacter(temp_int);
1160 user_defined_bullet(index).setSize(temp_int);
1161 temp_bullet(index).setSize(temp_int);
1165 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1167 // The bullet class should be able to read this.
1168 if (!lex.next()) return;
1169 int const index = lex.getInteger();
1171 string const temp_str = lex.getString();
1173 user_defined_bullet(index).setText(temp_str);
1174 temp_bullet(index).setText(temp_str);
1178 string const BufferParams::paperSizeName() const
1180 char real_papersize = papersize;
1181 if (real_papersize == PAPER_DEFAULT)
1182 real_papersize = lyxrc.default_papersize;
1184 switch (real_papersize) {
1193 case PAPER_USEXECUTIVE:
1197 case PAPER_USLETTER:
1204 string const BufferParams::dvips_options() const
1209 && papersize == PAPER_CUSTOM
1210 && !lyxrc.print_paper_dimension_flag.empty()
1211 && !paperwidth.empty()
1212 && !paperheight.empty()) {
1213 // using a custom papersize
1214 result = lyxrc.print_paper_dimension_flag;
1215 result += ' ' + paperwidth;
1216 result += ',' + paperheight;
1218 string const paper_option = paperSizeName();
1219 if (paper_option != "letter" ||
1220 orientation != ORIENTATION_LANDSCAPE) {
1221 // dvips won't accept -t letter -t landscape.
1222 // In all other cases, include the paper size
1224 result = lyxrc.print_paper_flag;
1225 result += ' ' + paper_option;
1228 if (orientation == ORIENTATION_LANDSCAPE &&
1229 papersize != PAPER_CUSTOM)
1230 result += ' ' + lyxrc.print_landscape_flag;
1235 string const BufferParams::babelCall(string const & lang_opts) const
1237 string tmp = lyxrc.language_package;
1238 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1239 tmp = string("\\usepackage[") + lang_opts + "]{babel}";