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, VMARGIN_PAPER_TYPE> PaperSizeTranslator;
131 PaperSizeTranslator const init_papersizetranslator()
133 PaperSizeTranslator translator(string_papersize[0], VM_PAPER_DEFAULT);
134 translator.addPair(string_papersize[1], VM_PAPER_CUSTOM);
135 translator.addPair(string_papersize[2], VM_PAPER_USLETTER);
136 translator.addPair(string_papersize[3], VM_PAPER_USLEGAL);
137 translator.addPair(string_papersize[4], VM_PAPER_USEXECUTIVE);
138 translator.addPair(string_papersize[5], VM_PAPER_A3);
139 translator.addPair(string_papersize[6], VM_PAPER_A4);
140 translator.addPair(string_papersize[7], VM_PAPER_A5);
141 translator.addPair(string_papersize[8], VM_PAPER_B3);
142 translator.addPair(string_papersize[9], VM_PAPER_B4);
143 translator.addPair(string_papersize[10], VM_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 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
337 paperpackage = PACKAGE_NONE;
338 orientation = ORIENTATION_PORTRAIT;
339 use_geometry = false;
340 use_amsmath = AMS_AUTO;
341 cite_engine = biblio::ENGINE_BASIC;
342 use_bibtopic = false;
343 tracking_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 papersize2 = 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 == "\\branch") {
513 string branch = lex.getString();
514 branchlist().add(branch);
517 string const tok = lex.getString();
518 if (tok == "\\end_branch")
520 Branch * branch_ptr = branchlist().find(branch);
521 if (tok == "\\selected") {
524 branch_ptr->setSelected(lex.getInteger());
526 // not yet operational
527 if (tok == "\\color") {
529 string color = lex.getString();
531 branch_ptr->setColor(color);
532 // Update also the LColor table:
534 color = lcolor.getX11Name(LColor::background);
535 lcolor.setColor(branch, color);
539 } else if (token == "\\author") {
541 istringstream ss(lex.getString());
544 author_map.push_back(pimpl_->authorlist.record(a));
545 } else if (token == "\\paperorientation") {
548 orientation = paperorientationtranslator().find(orient);
549 } else if (token == "\\paperwidth") {
551 } else if (token == "\\paperheight") {
553 } else if (token == "\\leftmargin") {
555 } else if (token == "\\topmargin") {
557 } else if (token == "\\rightmargin") {
559 } else if (token == "\\bottommargin") {
561 } else if (token == "\\headheight") {
563 } else if (token == "\\headsep") {
565 } else if (token == "\\footskip") {
567 } else if (token == "\\paperfontsize") {
569 } else if (token == "\\papercolumns") {
571 } else if (token == "\\papersides") {
574 sides = sidestranslator().find(psides);
575 } else if (token == "\\paperpagestyle") {
577 } else if (token == "\\bullet") {
579 } else if (token == "\\bulletLaTeX") {
580 readBulletsLaTeX(lex);
581 } else if (token == "\\secnumdepth") {
583 } else if (token == "\\tocdepth") {
585 } else if (token == "\\spacing") {
589 if (nspacing == "other") {
592 spacing().set(spacetranslator().find(nspacing), tmp_val);
593 } else if (token == "\\float_placement") {
594 lex >> float_placement;
603 void BufferParams::writeFile(ostream & os) const
605 // The top of the file is written by the buffer.
606 // Prints out the buffer info into the .lyx file given by file
609 os << "\\textclass " << textclasslist[textclass].name() << '\n';
611 // then the the preamble
612 if (!preamble.empty()) {
613 // remove '\n' from the end of preamble
614 string const tmppreamble = rtrim(preamble, "\n");
615 os << "\\begin_preamble\n"
617 << "\n\\end_preamble\n";
621 if (!options.empty()) {
622 os << "\\options " << options << '\n';
625 // then the text parameters
626 if (language != ignore_language)
627 os << "\\language " << language->lang() << '\n';
628 os << "\\inputencoding " << inputenc
629 << "\n\\fontscheme " << fonts
630 << "\n\\graphics " << graphicsDriver << '\n';
632 if (!float_placement.empty()) {
633 os << "\\float_placement " << float_placement << '\n';
635 os << "\\paperfontsize " << fontsize << '\n';
637 spacing().writeFile(os);
639 os << "\\papersize " << string_papersize[papersize2]
640 << "\n\\paperpackage " << string_paperpackages[paperpackage]
641 << "\n\\use_geometry " << convert<string>(use_geometry)
642 << "\n\\use_amsmath " << use_amsmath
643 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
644 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
645 << "\n\\paperorientation " << string_orientation[orientation]
648 std::list<Branch>::const_iterator it = branchlist().begin();
649 std::list<Branch>::const_iterator end = branchlist().end();
650 for (; it != end; ++it) {
651 os << "\\branch " << it->getBranch()
652 << "\n\\selected " << it->getSelected()
653 << "\n\\color " << it->getColor()
658 if (!paperwidth.empty())
659 os << "\\paperwidth "
660 << VSpace(paperwidth).asLyXCommand() << '\n';
661 if (!paperheight.empty())
662 os << "\\paperheight "
663 << VSpace(paperheight).asLyXCommand() << '\n';
664 if (!leftmargin.empty())
665 os << "\\leftmargin "
666 << VSpace(leftmargin).asLyXCommand() << '\n';
667 if (!topmargin.empty())
669 << VSpace(topmargin).asLyXCommand() << '\n';
670 if (!rightmargin.empty())
671 os << "\\rightmargin "
672 << VSpace(rightmargin).asLyXCommand() << '\n';
673 if (!bottommargin.empty())
674 os << "\\bottommargin "
675 << VSpace(bottommargin).asLyXCommand() << '\n';
676 if (!headheight.empty())
677 os << "\\headheight "
678 << VSpace(headheight).asLyXCommand() << '\n';
679 if (!headsep.empty())
681 << VSpace(headsep).asLyXCommand() << '\n';
682 if (!footskip.empty())
684 << VSpace(footskip).asLyXCommand() << '\n';
685 os << "\\secnumdepth " << secnumdepth
686 << "\n\\tocdepth " << tocdepth
687 << "\n\\paragraph_separation "
688 << string_paragraph_separation[paragraph_separation]
689 << "\n\\defskip " << getDefSkip().asLyXCommand()
690 << "\n\\quotes_language "
691 << string_quotes_language[quotes_language] << '\n'
693 << quotestimestranslator().find(quotes_times)
694 << "\n\\papercolumns " << columns
695 << "\n\\papersides " << sides
696 << "\n\\paperpagestyle " << pagestyle << '\n';
697 for (int i = 0; i < 4; ++i) {
698 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
699 if (user_defined_bullet(i).getFont() != -1) {
700 os << "\\bullet " << i << " "
701 << user_defined_bullet(i).getFont() << " "
702 << user_defined_bullet(i).getCharacter() << " "
703 << user_defined_bullet(i).getSize() << "\n";
706 os << "\\bulletLaTeX " << i << " \""
707 << user_defined_bullet(i).getText()
713 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
715 if (tracking_changes) {
716 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
717 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
718 for (; it != end; ++it) {
719 os << "\\author " << it->second << "\n";
725 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
726 TexRow & texrow) const
728 os << "\\documentclass";
730 LyXTextClass const & tclass = getLyXTextClass();
732 ostringstream clsoptions; // the document class options.
734 if (tokenPos(tclass.opt_fontsize(),
735 '|', fontsize) >= 0) {
736 // only write if existing in list (and not default)
737 clsoptions << fontsize << "pt,";
742 (paperpackage == PACKAGE_NONE)) {
745 clsoptions << "a3paper,";
748 clsoptions << "a4paper,";
751 clsoptions << "letterpaper,";
754 clsoptions << "a5paper,";
757 clsoptions << "b5paper,";
759 case PAPER_EXECUTIVEPAPER:
760 clsoptions << "executivepaper,";
762 case PAPER_LEGALPAPER:
763 clsoptions << "legalpaper,";
771 if (sides != tclass.sides()) {
773 case LyXTextClass::OneSide:
774 clsoptions << "oneside,";
776 case LyXTextClass::TwoSides:
777 clsoptions << "twoside,";
783 if (columns != tclass.columns()) {
785 clsoptions << "twocolumn,";
787 clsoptions << "onecolumn,";
791 && orientation == ORIENTATION_LANDSCAPE)
792 clsoptions << "landscape,";
794 // language should be a parameter to \documentclass
795 if (language->babel() == "hebrew"
796 && default_language->babel() != "hebrew")
797 // This seems necessary
798 features.useLanguage(default_language);
800 ostringstream language_options;
801 bool const use_babel = features.useBabel();
803 language_options << features.getLanguages();
804 language_options << language->babel();
805 if (lyxrc.language_global_options)
806 clsoptions << language_options.str() << ',';
809 // the user-defined options
810 if (!options.empty()) {
811 clsoptions << options << ',';
814 string strOptions(clsoptions.str());
815 if (!strOptions.empty()) {
816 strOptions = rtrim(strOptions, ",");
817 os << '[' << strOptions << ']';
820 os << '{' << tclass.latexname() << "}\n";
822 // end of \documentclass defs
824 // font selection must be done before loading fontenc.sty
825 // The ae package is not needed when using OT1 font encoding.
826 if (fonts != "default" &&
827 (fonts != "ae" || lyxrc.fontenc != "default")) {
828 os << "\\usepackage{" << fonts << "}\n";
831 os << "\\usepackage{aecompl}\n";
835 // this one is not per buffer
836 if (lyxrc.fontenc != "default") {
837 os << "\\usepackage[" << lyxrc.fontenc
842 if (inputenc == "auto") {
843 string const doc_encoding =
844 language->encoding()->LatexName();
846 // Create a list with all the input encodings used
848 std::set<string> encodings =
849 features.getEncodingSet(doc_encoding);
851 os << "\\usepackage[";
852 std::copy(encodings.begin(), encodings.end(),
853 std::ostream_iterator<string>(os, ","));
854 os << doc_encoding << "]{inputenc}\n";
856 } else if (inputenc != "default") {
857 os << "\\usepackage[" << inputenc
862 // At the very beginning the text parameters.
863 if (paperpackage != PACKAGE_NONE) {
864 switch (paperpackage) {
868 os << "\\usepackage{a4}\n";
872 os << "\\usepackage{a4wide}\n";
875 case PACKAGE_WIDEMARGINSA4:
876 os << "\\usepackage[widemargins]{a4}\n";
882 os << "\\usepackage{geometry}\n";
884 os << "\\geometry{verbose";
885 if (orientation == ORIENTATION_LANDSCAPE)
887 switch (papersize2) {
888 case VM_PAPER_CUSTOM:
889 if (!paperwidth.empty())
892 if (!paperheight.empty())
893 os << ",paperheight="
896 case VM_PAPER_USLETTER:
897 os << ",letterpaper";
899 case VM_PAPER_USLEGAL:
902 case VM_PAPER_USEXECUTIVE:
903 os << ",executivepaper";
924 // default papersize ie VM_PAPER_DEFAULT
925 switch (lyxrc.default_papersize) {
926 case PAPER_DEFAULT: // keep compiler happy
928 os << ",letterpaper";
930 case PAPER_LEGALPAPER:
933 case PAPER_EXECUTIVEPAPER:
934 os << ",executivepaper";
950 if (!topmargin.empty())
951 os << ",tmargin=" << topmargin;
952 if (!bottommargin.empty())
953 os << ",bmargin=" << bottommargin;
954 if (!leftmargin.empty())
955 os << ",lmargin=" << leftmargin;
956 if (!rightmargin.empty())
957 os << ",rmargin=" << rightmargin;
958 if (!headheight.empty())
959 os << ",headheight=" << headheight;
960 if (!headsep.empty())
961 os << ",headsep=" << headsep;
962 if (!footskip.empty())
963 os << ",footskip=" << footskip;
968 if (tokenPos(tclass.opt_pagestyle(),
969 '|', pagestyle) >= 0) {
970 if (pagestyle == "fancy") {
971 os << "\\usepackage{fancyhdr}\n";
974 os << "\\pagestyle{" << pagestyle << "}\n";
978 if (secnumdepth != tclass.secnumdepth()) {
979 os << "\\setcounter{secnumdepth}{"
984 if (tocdepth != tclass.tocdepth()) {
985 os << "\\setcounter{tocdepth}{"
991 if (paragraph_separation) {
992 switch (getDefSkip().kind()) {
993 case VSpace::SMALLSKIP:
994 os << "\\setlength\\parskip{\\smallskipamount}\n";
996 case VSpace::MEDSKIP:
997 os << "\\setlength\\parskip{\\medskipamount}\n";
999 case VSpace::BIGSKIP:
1000 os << "\\setlength\\parskip{\\bigskipamount}\n";
1002 case VSpace::LENGTH:
1003 os << "\\setlength\\parskip{"
1004 << getDefSkip().length().asLatexString()
1007 default: // should never happen // Then delete it.
1008 os << "\\setlength\\parskip{\\medskipamount}\n";
1013 os << "\\setlength\\parindent{0pt}\n";
1017 // If we use jurabib, we have to call babel here.
1018 if (use_babel && features.isRequired("jurabib")) {
1019 os << babelCall(language_options.str())
1021 << features.getBabelOptions();
1025 // Now insert the LyX specific LaTeX commands...
1027 // The optional packages;
1028 string lyxpreamble(features.getPackages());
1030 // this might be useful...
1031 lyxpreamble += "\n\\makeatletter\n";
1033 // Some macros LyX will need
1034 string tmppreamble(features.getMacros());
1036 if (!tmppreamble.empty()) {
1037 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1038 "LyX specific LaTeX commands.\n"
1039 + tmppreamble + '\n';
1042 // the text class specific preamble
1043 tmppreamble = features.getTClassPreamble();
1044 if (!tmppreamble.empty()) {
1045 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1046 "Textclass specific LaTeX commands.\n"
1047 + tmppreamble + '\n';
1050 /* the user-defined preamble */
1051 if (!preamble.empty()) {
1052 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1053 "User specified LaTeX commands.\n"
1057 // Itemize bullet settings need to be last in case the user
1058 // defines their own bullets that use a package included
1059 // in the user-defined preamble -- ARRae
1060 // Actually it has to be done much later than that
1061 // since some packages like frenchb make modifications
1062 // at \begin{document} time -- JMarc
1064 for (int i = 0; i < 4; ++i) {
1065 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1066 if (bullets_def.empty())
1067 bullets_def="\\AtBeginDocument{\n";
1068 bullets_def += " \\renewcommand{\\labelitemi";
1070 // `i' is one less than the item to modify
1077 bullets_def += "ii";
1083 bullets_def += "}{" +
1084 user_defined_bullet(i).getText()
1089 if (!bullets_def.empty())
1090 lyxpreamble += bullets_def + "}\n\n";
1092 // We try to load babel late, in case it interferes
1093 // with other packages.
1094 // Jurabib has to be called after babel, though.
1095 if (use_babel && !features.isRequired("jurabib")) {
1096 lyxpreamble += babelCall(language_options.str()) + '\n';
1097 lyxpreamble += features.getBabelOptions();
1100 lyxpreamble += "\\makeatother\n";
1102 // dvipost settings come after everything else
1103 if (tracking_changes) {
1106 "\\dvipost{osstart color push Red}\n"
1107 "\\dvipost{osend color pop}\n"
1108 "\\dvipost{cbstart color push Blue}\n"
1109 "\\dvipost{cbend color pop}\n";
1113 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1114 for (int j = 0; j != nlines; ++j) {
1123 void BufferParams::setPaperStuff()
1125 papersize = PAPER_DEFAULT;
1126 char const c1 = paperpackage;
1127 if (c1 == PACKAGE_NONE) {
1128 char const c2 = papersize2;
1129 if (c2 == VM_PAPER_USLETTER)
1130 papersize = PAPER_USLETTER;
1131 else if (c2 == VM_PAPER_USLEGAL)
1132 papersize = PAPER_LEGALPAPER;
1133 else if (c2 == VM_PAPER_USEXECUTIVE)
1134 papersize = PAPER_EXECUTIVEPAPER;
1135 else if (c2 == VM_PAPER_A3)
1136 papersize = PAPER_A3PAPER;
1137 else if (c2 == VM_PAPER_A4)
1138 papersize = PAPER_A4PAPER;
1139 else if (c2 == VM_PAPER_A5)
1140 papersize = PAPER_A5PAPER;
1141 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1142 (c2 == VM_PAPER_B5))
1143 papersize = PAPER_B5PAPER;
1144 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1145 (c1 == PACKAGE_WIDEMARGINSA4))
1146 papersize = PAPER_A4PAPER;
1150 void BufferParams::useClassDefaults()
1152 LyXTextClass const & tclass = textclasslist[textclass];
1154 sides = tclass.sides();
1155 columns = tclass.columns();
1156 pagestyle = tclass.pagestyle();
1157 options = tclass.options();
1158 secnumdepth = tclass.secnumdepth();
1159 tocdepth = tclass.tocdepth();
1163 bool BufferParams::hasClassDefaults() const
1165 LyXTextClass const & tclass = textclasslist[textclass];
1167 return (sides == tclass.sides()
1168 && columns == tclass.columns()
1169 && pagestyle == tclass.pagestyle()
1170 && options == tclass.options()
1171 && secnumdepth == tclass.secnumdepth()
1172 && tocdepth == tclass.tocdepth());
1176 LyXTextClass const & BufferParams::getLyXTextClass() const
1178 return textclasslist[textclass];
1182 void BufferParams::readPreamble(LyXLex & lex)
1184 if (lex.getString() != "\\begin_preamble")
1185 lyxerr << "Error (BufferParams::readPreamble):"
1186 "consistency check failed." << endl;
1188 preamble = lex.getLongString("\\end_preamble");
1192 void BufferParams::readLanguage(LyXLex & lex)
1194 if (!lex.next()) return;
1196 string const tmptok = lex.getString();
1198 // check if tmptok is part of tex_babel in tex-defs.h
1199 language = languages.getLanguage(tmptok);
1201 // Language tmptok was not found
1202 language = default_language;
1203 lyxerr << "Warning: Setting language `"
1204 << tmptok << "' to `" << language->lang()
1210 void BufferParams::readGraphicsDriver(LyXLex & lex)
1212 if (!lex.next()) return;
1214 string const tmptok = lex.getString();
1215 // check if tmptok is part of tex_graphics in tex_defs.h
1218 string const test = tex_graphics[n++];
1220 if (test == tmptok) {
1221 graphicsDriver = tmptok;
1223 } else if (test == "last_item") {
1225 "Warning: graphics driver `$$Token' not recognized!\n"
1226 " Setting graphics driver to `default'.\n");
1227 graphicsDriver = "default";
1234 void BufferParams::readBullets(LyXLex & lex)
1236 if (!lex.next()) return;
1238 int const index = lex.getInteger();
1240 int temp_int = lex.getInteger();
1241 user_defined_bullet(index).setFont(temp_int);
1242 temp_bullet(index).setFont(temp_int);
1244 user_defined_bullet(index).setCharacter(temp_int);
1245 temp_bullet(index).setCharacter(temp_int);
1247 user_defined_bullet(index).setSize(temp_int);
1248 temp_bullet(index).setSize(temp_int);
1252 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1254 // The bullet class should be able to read this.
1255 if (!lex.next()) return;
1256 int const index = lex.getInteger();
1258 string const temp_str = lex.getString();
1260 user_defined_bullet(index).setText(temp_str);
1261 temp_bullet(index).setText(temp_str);
1265 string const BufferParams::paperSizeName() const
1267 char real_papersize = papersize;
1268 if (real_papersize == PAPER_DEFAULT)
1269 real_papersize = lyxrc.default_papersize;
1271 switch (real_papersize) {
1280 case PAPER_EXECUTIVEPAPER:
1282 case PAPER_LEGALPAPER:
1284 case PAPER_USLETTER:
1291 string const BufferParams::dvips_options() const
1296 && papersize2 == VM_PAPER_CUSTOM
1297 && !lyxrc.print_paper_dimension_flag.empty()
1298 && !paperwidth.empty()
1299 && !paperheight.empty()) {
1300 // using a custom papersize
1301 result = lyxrc.print_paper_dimension_flag;
1302 result += ' ' + paperwidth;
1303 result += ',' + paperheight;
1305 string const paper_option = paperSizeName();
1306 if (paper_option != "letter" ||
1307 orientation != ORIENTATION_LANDSCAPE) {
1308 // dvips won't accept -t letter -t landscape.
1309 // In all other cases, include the paper size
1311 result = lyxrc.print_paper_flag;
1312 result += ' ' + paper_option;
1315 if (orientation == ORIENTATION_LANDSCAPE &&
1316 papersize2 != VM_PAPER_CUSTOM)
1317 result += ' ' + lyxrc.print_landscape_flag;
1322 string const BufferParams::babelCall(string const & lang_opts) const
1324 string tmp = lyxrc.language_package;
1325 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1326 tmp = string("\\usepackage[") + lang_opts + "]{babel}";