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_PACKAGES> PaperPackagesTranslator;
159 PaperPackagesTranslator const init_paperpackagestranslator()
161 PaperPackagesTranslator translator(string_paperpackages[0], PACKAGE_NONE);
162 translator.addPair(string_paperpackages[1], PACKAGE_A4);
163 translator.addPair(string_paperpackages[2], PACKAGE_A4WIDE);
164 translator.addPair(string_paperpackages[3], PACKAGE_WIDEMARGINSA4);
169 PaperPackagesTranslator const & paperpackagestranslator()
171 static PaperPackagesTranslator translator = init_paperpackagestranslator();
177 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
180 PaperOrientationTranslator const init_paperorientationtranslator()
182 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
183 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
188 PaperOrientationTranslator const & paperorientationtranslator()
190 static PaperOrientationTranslator translator = init_paperorientationtranslator();
196 typedef Translator<int, LyXTextClass::PageSides> SidesTranslator;
199 SidesTranslator const init_sidestranslator()
201 SidesTranslator translator(1, LyXTextClass::OneSide);
202 translator.addPair(2, LyXTextClass::TwoSides);
207 SidesTranslator const & sidestranslator()
209 static SidesTranslator translator = init_sidestranslator();
216 typedef Translator<int, BufferParams::AMS> AMSTranslator;
219 AMSTranslator const init_amstranslator()
221 AMSTranslator translator(0, BufferParams::AMS_OFF);
222 translator.addPair(1, BufferParams::AMS_AUTO);
223 translator.addPair(2, BufferParams::AMS_ON);
228 AMSTranslator const & amstranslator()
230 static AMSTranslator translator = init_amstranslator();
236 typedef Translator<string, biblio::CiteEngine> CiteEngineTranslator;
239 CiteEngineTranslator const init_citeenginetranslator()
241 CiteEngineTranslator translator("basic", biblio::ENGINE_BASIC);
242 translator.addPair("natbib_numerical", biblio::ENGINE_NATBIB_NUMERICAL);
243 translator.addPair("natbib_authoryear", biblio::ENGINE_NATBIB_AUTHORYEAR);
244 translator.addPair("jurabib", biblio::ENGINE_JURABIB);
249 CiteEngineTranslator const & citeenginetranslator()
251 static CiteEngineTranslator translator = init_citeenginetranslator();
257 typedef Translator<string, Spacing::Space> SpaceTranslator;
260 SpaceTranslator const init_spacetranslator()
262 SpaceTranslator translator("default", Spacing::Default);
263 translator.addPair("single", Spacing::Single);
264 translator.addPair("onehalf", Spacing::Onehalf);
265 translator.addPair("double", Spacing::Double);
266 translator.addPair("other", Spacing::Other);
271 SpaceTranslator const & spacetranslator()
273 static SpaceTranslator translator = init_spacetranslator();
277 // ends annonym namespace
281 class BufferParams::Impl
286 AuthorList authorlist;
287 BranchList branchlist;
288 boost::array<Bullet, 4> temp_bullets;
289 boost::array<Bullet, 4> user_defined_bullets;
291 /** This is the amount of space used for paragraph_separation "skip",
292 * and for detached paragraphs in "indented" documents.
298 BufferParams::Impl::Impl()
299 : defskip(VSpace::MEDSKIP)
301 // set initial author
302 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
307 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
311 return new BufferParams::Impl(*ptr);
315 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
321 BufferParams::BufferParams()
322 : // Initialize textclass to point to article. if `first' is
323 // true in the returned pair, then `second' is the textclass
324 // number; if it is false, second is 0. In both cases, second
326 textclass(textclasslist.NumberOfClass("article").second),
329 paragraph_separation = PARSEP_INDENT;
330 quotes_language = InsetQuotes::EnglishQ;
331 quotes_times = InsetQuotes::DoubleQ;
332 fontsize = "default";
335 papersize = PAPER_DEFAULT;
336 paperpackage = PACKAGE_NONE;
337 orientation = ORIENTATION_PORTRAIT;
338 use_geometry = false;
339 use_amsmath = AMS_AUTO;
340 cite_engine = biblio::ENGINE_BASIC;
341 use_bibtopic = false;
342 tracking_changes = false;
343 output_changes = false;
346 language = default_language;
349 graphicsDriver = "default";
350 sides = LyXTextClass::OneSide;
352 pagestyle = "default";
354 for (int iter = 0; iter < 4; ++iter) {
355 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
356 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
361 BufferParams::~BufferParams()
365 AuthorList & BufferParams::authors()
367 return pimpl_->authorlist;
371 AuthorList const & BufferParams::authors() const
373 return pimpl_->authorlist;
377 BranchList & BufferParams::branchlist()
379 return pimpl_->branchlist;
383 BranchList const & BufferParams::branchlist() const
385 return pimpl_->branchlist;
389 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
391 BOOST_ASSERT(index < 4);
392 return pimpl_->temp_bullets[index];
396 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
398 BOOST_ASSERT(index < 4);
399 return pimpl_->temp_bullets[index];
403 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
405 BOOST_ASSERT(index < 4);
406 return pimpl_->user_defined_bullets[index];
410 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
412 BOOST_ASSERT(index < 4);
413 return pimpl_->user_defined_bullets[index];
417 Spacing & BufferParams::spacing()
419 return pimpl_->spacing;
423 Spacing const & BufferParams::spacing() const
425 return pimpl_->spacing;
429 VSpace const & BufferParams::getDefSkip() const
431 return pimpl_->defskip;
435 void BufferParams::setDefSkip(VSpace const & vs)
437 pimpl_->defskip = vs;
441 string const BufferParams::readToken(LyXLex & lex, string const & token)
443 if (token == "\\textclass") {
445 string const classname = lex.getString();
446 pair<bool, lyx::textclass_type> pp =
447 textclasslist.NumberOfClass(classname);
449 textclass = pp.second;
454 if (!getLyXTextClass().isTeXClassAvailable()) {
456 bformat(_("The document uses a missing "
457 "TeX class \"%1$s\".\n"), classname);
458 Alert::warning(_("Document class not available"),
459 msg + _("LyX will not be able to produce output."));
461 } else if (token == "\\begin_preamble") {
463 } else if (token == "\\options") {
465 options = lex.getString();
466 } else if (token == "\\language") {
468 } else if (token == "\\inputencoding") {
470 } else if (token == "\\graphics") {
471 readGraphicsDriver(lex);
472 } else if (token == "\\fontscheme") {
474 } else if (token == "\\paragraph_separation") {
477 paragraph_separation = parseptranslator().find(parsep);
478 } else if (token == "\\defskip") {
480 pimpl_->defskip = VSpace(lex.getString());
481 } else if (token == "\\quotes_language") {
484 quotes_language = quoteslangtranslator().find(quotes_lang);
485 } else if (token == "\\quotes_times") {
488 quotes_times = quotestimestranslator().find(qtimes);
489 } else if (token == "\\papersize") {
492 papersize = papersizetranslator().find(ppsize);
493 } else if (token == "\\paperpackage") {
496 paperpackage = paperpackagestranslator().find(ppackage);
497 } else if (token == "\\use_geometry") {
499 } else if (token == "\\use_amsmath") {
502 use_amsmath = amstranslator().find(use_ams);
503 } else if (token == "\\cite_engine") {
506 cite_engine = citeenginetranslator().find(engine);
507 } else if (token == "\\use_bibtopic") {
509 } else if (token == "\\tracking_changes") {
510 lex >> tracking_changes;
511 } else if (token == "\\output_changes") {
512 lex >> output_changes;
513 } else if (token == "\\branch") {
515 string branch = lex.getString();
516 branchlist().add(branch);
519 string const tok = lex.getString();
520 if (tok == "\\end_branch")
522 Branch * branch_ptr = branchlist().find(branch);
523 if (tok == "\\selected") {
526 branch_ptr->setSelected(lex.getInteger());
528 // not yet operational
529 if (tok == "\\color") {
531 string color = lex.getString();
533 branch_ptr->setColor(color);
534 // Update also the LColor table:
536 color = lcolor.getX11Name(LColor::background);
537 lcolor.setColor(branch, color);
541 } else if (token == "\\author") {
543 istringstream ss(lex.getString());
546 author_map.push_back(pimpl_->authorlist.record(a));
547 } else if (token == "\\paperorientation") {
550 orientation = paperorientationtranslator().find(orient);
551 } else if (token == "\\paperwidth") {
553 } else if (token == "\\paperheight") {
555 } else if (token == "\\leftmargin") {
557 } else if (token == "\\topmargin") {
559 } else if (token == "\\rightmargin") {
561 } else if (token == "\\bottommargin") {
563 } else if (token == "\\headheight") {
565 } else if (token == "\\headsep") {
567 } else if (token == "\\footskip") {
569 } else if (token == "\\paperfontsize") {
571 } else if (token == "\\papercolumns") {
573 } else if (token == "\\papersides") {
576 sides = sidestranslator().find(psides);
577 } else if (token == "\\paperpagestyle") {
579 } else if (token == "\\bullet") {
581 } else if (token == "\\bulletLaTeX") {
582 readBulletsLaTeX(lex);
583 } else if (token == "\\secnumdepth") {
585 } else if (token == "\\tocdepth") {
587 } else if (token == "\\spacing") {
591 if (nspacing == "other") {
594 spacing().set(spacetranslator().find(nspacing), tmp_val);
595 } else if (token == "\\float_placement") {
596 lex >> float_placement;
605 void BufferParams::writeFile(ostream & os) const
607 // The top of the file is written by the buffer.
608 // Prints out the buffer info into the .lyx file given by file
611 os << "\\textclass " << textclasslist[textclass].name() << '\n';
613 // then the the preamble
614 if (!preamble.empty()) {
615 // remove '\n' from the end of preamble
616 string const tmppreamble = rtrim(preamble, "\n");
617 os << "\\begin_preamble\n"
619 << "\n\\end_preamble\n";
623 if (!options.empty()) {
624 os << "\\options " << options << '\n';
627 // then the text parameters
628 if (language != ignore_language)
629 os << "\\language " << language->lang() << '\n';
630 os << "\\inputencoding " << inputenc
631 << "\n\\fontscheme " << fonts
632 << "\n\\graphics " << graphicsDriver << '\n';
634 if (!float_placement.empty()) {
635 os << "\\float_placement " << float_placement << '\n';
637 os << "\\paperfontsize " << fontsize << '\n';
639 spacing().writeFile(os);
641 os << "\\papersize " << string_papersize[papersize]
642 << "\n\\paperpackage " << string_paperpackages[paperpackage]
643 << "\n\\use_geometry " << convert<string>(use_geometry)
644 << "\n\\use_amsmath " << use_amsmath
645 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
646 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
647 << "\n\\paperorientation " << string_orientation[orientation]
650 std::list<Branch>::const_iterator it = branchlist().begin();
651 std::list<Branch>::const_iterator end = branchlist().end();
652 for (; it != end; ++it) {
653 os << "\\branch " << it->getBranch()
654 << "\n\\selected " << it->getSelected()
655 << "\n\\color " << it->getColor()
660 if (!paperwidth.empty())
661 os << "\\paperwidth "
662 << VSpace(paperwidth).asLyXCommand() << '\n';
663 if (!paperheight.empty())
664 os << "\\paperheight "
665 << VSpace(paperheight).asLyXCommand() << '\n';
666 if (!leftmargin.empty())
667 os << "\\leftmargin "
668 << VSpace(leftmargin).asLyXCommand() << '\n';
669 if (!topmargin.empty())
671 << VSpace(topmargin).asLyXCommand() << '\n';
672 if (!rightmargin.empty())
673 os << "\\rightmargin "
674 << VSpace(rightmargin).asLyXCommand() << '\n';
675 if (!bottommargin.empty())
676 os << "\\bottommargin "
677 << VSpace(bottommargin).asLyXCommand() << '\n';
678 if (!headheight.empty())
679 os << "\\headheight "
680 << VSpace(headheight).asLyXCommand() << '\n';
681 if (!headsep.empty())
683 << VSpace(headsep).asLyXCommand() << '\n';
684 if (!footskip.empty())
686 << VSpace(footskip).asLyXCommand() << '\n';
687 os << "\\secnumdepth " << secnumdepth
688 << "\n\\tocdepth " << tocdepth
689 << "\n\\paragraph_separation "
690 << string_paragraph_separation[paragraph_separation]
691 << "\n\\defskip " << getDefSkip().asLyXCommand()
692 << "\n\\quotes_language "
693 << string_quotes_language[quotes_language] << '\n'
695 << quotestimestranslator().find(quotes_times)
696 << "\n\\papercolumns " << columns
697 << "\n\\papersides " << sides
698 << "\n\\paperpagestyle " << pagestyle << '\n';
699 for (int i = 0; i < 4; ++i) {
700 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
701 if (user_defined_bullet(i).getFont() != -1) {
702 os << "\\bullet " << i << " "
703 << user_defined_bullet(i).getFont() << " "
704 << user_defined_bullet(i).getCharacter() << " "
705 << user_defined_bullet(i).getSize() << "\n";
708 os << "\\bulletLaTeX " << i << " \""
709 << user_defined_bullet(i).getText()
715 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
716 os << "\\output_changes " << convert<string>(output_changes) << "\n";
718 if (tracking_changes) {
719 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
720 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
721 for (; it != end; ++it) {
722 os << "\\author " << it->second << "\n";
728 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
729 TexRow & texrow) const
731 os << "\\documentclass";
733 LyXTextClass const & tclass = getLyXTextClass();
735 ostringstream clsoptions; // the document class options.
737 if (tokenPos(tclass.opt_fontsize(),
738 '|', fontsize) >= 0) {
739 // only write if existing in list (and not default)
740 clsoptions << fontsize << "pt,";
743 // custom, A3, B3 and B4 paper sizes need geometry
744 bool nonstandard_papersize = (papersize == PAPER_B3) ||
745 (papersize == PAPER_B4) ||
746 (papersize == PAPER_A3) ||
747 (papersize == PAPER_CUSTOM);
749 if (!use_geometry && (paperpackage == PACKAGE_NONE)) {
752 clsoptions << "a4paper,";
755 clsoptions << "letterpaper,";
758 clsoptions << "a5paper,";
761 clsoptions << "b5paper,";
763 case PAPER_USEXECUTIVE:
764 clsoptions << "executivepaper,";
767 clsoptions << "legalpaper,";
779 if (sides != tclass.sides()) {
781 case LyXTextClass::OneSide:
782 clsoptions << "oneside,";
784 case LyXTextClass::TwoSides:
785 clsoptions << "twoside,";
791 if (columns != tclass.columns()) {
793 clsoptions << "twocolumn,";
795 clsoptions << "onecolumn,";
799 && orientation == ORIENTATION_LANDSCAPE)
800 clsoptions << "landscape,";
802 // language should be a parameter to \documentclass
803 if (language->babel() == "hebrew"
804 && default_language->babel() != "hebrew")
805 // This seems necessary
806 features.useLanguage(default_language);
808 ostringstream language_options;
809 bool const use_babel = features.useBabel();
811 language_options << features.getLanguages();
812 language_options << language->babel();
813 if (lyxrc.language_global_options)
814 clsoptions << language_options.str() << ',';
817 // the user-defined options
818 if (!options.empty()) {
819 clsoptions << options << ',';
822 string strOptions(clsoptions.str());
823 if (!strOptions.empty()) {
824 strOptions = rtrim(strOptions, ",");
825 os << '[' << strOptions << ']';
828 os << '{' << tclass.latexname() << "}\n";
830 // end of \documentclass defs
832 // font selection must be done before loading fontenc.sty
833 // The ae package is not needed when using OT1 font encoding.
834 if (fonts != "default" &&
835 (fonts != "ae" || lyxrc.fontenc != "default")) {
836 os << "\\usepackage{" << fonts << "}\n";
839 os << "\\usepackage{aecompl}\n";
843 // this one is not per buffer
844 if (lyxrc.fontenc != "default") {
845 os << "\\usepackage[" << lyxrc.fontenc
850 if (inputenc == "auto") {
851 string const doc_encoding =
852 language->encoding()->LatexName();
854 // Create a list with all the input encodings used
856 std::set<string> encodings =
857 features.getEncodingSet(doc_encoding);
859 os << "\\usepackage[";
860 std::copy(encodings.begin(), encodings.end(),
861 std::ostream_iterator<string>(os, ","));
862 os << doc_encoding << "]{inputenc}\n";
864 } else if (inputenc != "default") {
865 os << "\\usepackage[" << inputenc
870 // At the very beginning the text parameters.
871 if (paperpackage != PACKAGE_NONE) {
872 switch (paperpackage) {
876 os << "\\usepackage{a4}\n";
880 os << "\\usepackage{a4wide}\n";
883 case PACKAGE_WIDEMARGINSA4:
884 os << "\\usepackage[widemargins]{a4}\n";
890 if (use_geometry || nonstandard_papersize) {
891 os << "\\usepackage{geometry}\n";
893 os << "\\geometry{verbose";
894 if (orientation == ORIENTATION_LANDSCAPE)
898 if (!paperwidth.empty())
901 if (!paperheight.empty())
902 os << ",paperheight="
906 os << ",letterpaper";
911 case PAPER_USEXECUTIVE:
912 os << ",executivepaper";
933 // default papersize ie PAPER_DEFAULT
934 switch (lyxrc.default_papersize) {
935 case PAPER_DEFAULT: // keep compiler happy
937 os << ",letterpaper";
942 case PAPER_USEXECUTIVE:
943 os << ",executivepaper";
963 if (!topmargin.empty())
964 os << ",tmargin=" << topmargin;
965 if (!bottommargin.empty())
966 os << ",bmargin=" << bottommargin;
967 if (!leftmargin.empty())
968 os << ",lmargin=" << leftmargin;
969 if (!rightmargin.empty())
970 os << ",rmargin=" << rightmargin;
971 if (!headheight.empty())
972 os << ",headheight=" << headheight;
973 if (!headsep.empty())
974 os << ",headsep=" << headsep;
975 if (!footskip.empty())
976 os << ",footskip=" << footskip;
981 if (tokenPos(tclass.opt_pagestyle(),
982 '|', pagestyle) >= 0) {
983 if (pagestyle == "fancy") {
984 os << "\\usepackage{fancyhdr}\n";
987 os << "\\pagestyle{" << pagestyle << "}\n";
991 if (secnumdepth != tclass.secnumdepth()) {
992 os << "\\setcounter{secnumdepth}{"
997 if (tocdepth != tclass.tocdepth()) {
998 os << "\\setcounter{tocdepth}{"
1004 if (paragraph_separation) {
1005 switch (getDefSkip().kind()) {
1006 case VSpace::SMALLSKIP:
1007 os << "\\setlength\\parskip{\\smallskipamount}\n";
1009 case VSpace::MEDSKIP:
1010 os << "\\setlength\\parskip{\\medskipamount}\n";
1012 case VSpace::BIGSKIP:
1013 os << "\\setlength\\parskip{\\bigskipamount}\n";
1015 case VSpace::LENGTH:
1016 os << "\\setlength\\parskip{"
1017 << getDefSkip().length().asLatexString()
1020 default: // should never happen // Then delete it.
1021 os << "\\setlength\\parskip{\\medskipamount}\n";
1026 os << "\\setlength\\parindent{0pt}\n";
1030 // If we use jurabib, we have to call babel here.
1031 if (use_babel && features.isRequired("jurabib")) {
1032 os << babelCall(language_options.str())
1034 << features.getBabelOptions();
1038 // Now insert the LyX specific LaTeX commands...
1040 // The optional packages;
1041 string lyxpreamble(features.getPackages());
1043 // this might be useful...
1044 lyxpreamble += "\n\\makeatletter\n";
1046 // Some macros LyX will need
1047 string tmppreamble(features.getMacros());
1049 if (!tmppreamble.empty()) {
1050 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1051 "LyX specific LaTeX commands.\n"
1052 + tmppreamble + '\n';
1055 // the text class specific preamble
1056 tmppreamble = features.getTClassPreamble();
1057 if (!tmppreamble.empty()) {
1058 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1059 "Textclass specific LaTeX commands.\n"
1060 + tmppreamble + '\n';
1063 /* the user-defined preamble */
1064 if (!preamble.empty()) {
1065 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1066 "User specified LaTeX commands.\n"
1070 // Itemize bullet settings need to be last in case the user
1071 // defines their own bullets that use a package included
1072 // in the user-defined preamble -- ARRae
1073 // Actually it has to be done much later than that
1074 // since some packages like frenchb make modifications
1075 // at \begin{document} time -- JMarc
1077 for (int i = 0; i < 4; ++i) {
1078 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1079 if (bullets_def.empty())
1080 bullets_def="\\AtBeginDocument{\n";
1081 bullets_def += " \\renewcommand{\\labelitemi";
1083 // `i' is one less than the item to modify
1090 bullets_def += "ii";
1096 bullets_def += "}{" +
1097 user_defined_bullet(i).getText()
1102 if (!bullets_def.empty())
1103 lyxpreamble += bullets_def + "}\n\n";
1105 // We try to load babel late, in case it interferes
1106 // with other packages.
1107 // Jurabib has to be called after babel, though.
1108 if (use_babel && !features.isRequired("jurabib")) {
1109 lyxpreamble += babelCall(language_options.str()) + '\n';
1110 lyxpreamble += features.getBabelOptions();
1113 lyxpreamble += "\\makeatother\n";
1115 // dvipost settings come after everything else
1116 if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
1119 "\\dvipost{osstart color push Red}\n"
1120 "\\dvipost{osend color pop}\n"
1121 "\\dvipost{cbstart color push Blue}\n"
1122 "\\dvipost{cbend color pop}\n";
1126 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1127 for (int j = 0; j != nlines; ++j) {
1136 void BufferParams::useClassDefaults()
1138 LyXTextClass const & tclass = textclasslist[textclass];
1140 sides = tclass.sides();
1141 columns = tclass.columns();
1142 pagestyle = tclass.pagestyle();
1143 options = tclass.options();
1144 secnumdepth = tclass.secnumdepth();
1145 tocdepth = tclass.tocdepth();
1149 bool BufferParams::hasClassDefaults() const
1151 LyXTextClass const & tclass = textclasslist[textclass];
1153 return (sides == tclass.sides()
1154 && columns == tclass.columns()
1155 && pagestyle == tclass.pagestyle()
1156 && options == tclass.options()
1157 && secnumdepth == tclass.secnumdepth()
1158 && tocdepth == tclass.tocdepth());
1162 LyXTextClass const & BufferParams::getLyXTextClass() const
1164 return textclasslist[textclass];
1168 void BufferParams::readPreamble(LyXLex & lex)
1170 if (lex.getString() != "\\begin_preamble")
1171 lyxerr << "Error (BufferParams::readPreamble):"
1172 "consistency check failed." << endl;
1174 preamble = lex.getLongString("\\end_preamble");
1178 void BufferParams::readLanguage(LyXLex & lex)
1180 if (!lex.next()) return;
1182 string const tmptok = lex.getString();
1184 // check if tmptok is part of tex_babel in tex-defs.h
1185 language = languages.getLanguage(tmptok);
1187 // Language tmptok was not found
1188 language = default_language;
1189 lyxerr << "Warning: Setting language `"
1190 << tmptok << "' to `" << language->lang()
1196 void BufferParams::readGraphicsDriver(LyXLex & lex)
1198 if (!lex.next()) return;
1200 string const tmptok = lex.getString();
1201 // check if tmptok is part of tex_graphics in tex_defs.h
1204 string const test = tex_graphics[n++];
1206 if (test == tmptok) {
1207 graphicsDriver = tmptok;
1209 } else if (test == "") {
1211 "Warning: graphics driver `$$Token' not recognized!\n"
1212 " Setting graphics driver to `default'.\n");
1213 graphicsDriver = "default";
1220 void BufferParams::readBullets(LyXLex & lex)
1222 if (!lex.next()) return;
1224 int const index = lex.getInteger();
1226 int temp_int = lex.getInteger();
1227 user_defined_bullet(index).setFont(temp_int);
1228 temp_bullet(index).setFont(temp_int);
1230 user_defined_bullet(index).setCharacter(temp_int);
1231 temp_bullet(index).setCharacter(temp_int);
1233 user_defined_bullet(index).setSize(temp_int);
1234 temp_bullet(index).setSize(temp_int);
1238 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1240 // The bullet class should be able to read this.
1241 if (!lex.next()) return;
1242 int const index = lex.getInteger();
1244 string const temp_str = lex.getString();
1246 user_defined_bullet(index).setText(temp_str);
1247 temp_bullet(index).setText(temp_str);
1251 string const BufferParams::paperSizeName() const
1253 char real_papersize = papersize;
1254 if (real_papersize == PAPER_DEFAULT)
1255 real_papersize = lyxrc.default_papersize;
1257 switch (real_papersize) {
1266 case PAPER_USEXECUTIVE:
1270 case PAPER_USLETTER:
1277 string const BufferParams::dvips_options() const
1282 && papersize == PAPER_CUSTOM
1283 && !lyxrc.print_paper_dimension_flag.empty()
1284 && !paperwidth.empty()
1285 && !paperheight.empty()) {
1286 // using a custom papersize
1287 result = lyxrc.print_paper_dimension_flag;
1288 result += ' ' + paperwidth;
1289 result += ',' + paperheight;
1291 string const paper_option = paperSizeName();
1292 if (paper_option != "letter" ||
1293 orientation != ORIENTATION_LANDSCAPE) {
1294 // dvips won't accept -t letter -t landscape.
1295 // In all other cases, include the paper size
1297 result = lyxrc.print_paper_flag;
1298 result += ' ' + paper_option;
1301 if (orientation == ORIENTATION_LANDSCAPE &&
1302 papersize != PAPER_CUSTOM)
1303 result += ' ' + lyxrc.print_landscape_flag;
1308 string const BufferParams::babelCall(string const & lang_opts) const
1310 string tmp = lyxrc.language_package;
1311 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1312 tmp = string("\\usepackage[") + lang_opts + "]{babel}";