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 struct BufferParams::Impl
285 AuthorList authorlist;
286 BranchList branchlist;
287 boost::array<Bullet, 4> temp_bullets;
288 boost::array<Bullet, 4> user_defined_bullets;
290 /** This is the amount of space used for paragraph_separation "skip",
291 * and for detached paragraphs in "indented" documents.
297 BufferParams::Impl::Impl()
298 : defskip(VSpace::MEDSKIP)
300 // set initial author
301 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
306 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
310 return new BufferParams::Impl(*ptr);
314 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
320 BufferParams::BufferParams()
321 : // Initialize textclass to point to article. if `first' is
322 // true in the returned pair, then `second' is the textclass
323 // number; if it is false, second is 0. In both cases, second
325 textclass(textclasslist.NumberOfClass("article").second),
328 paragraph_separation = PARSEP_INDENT;
329 quotes_language = InsetQuotes::EnglishQ;
330 quotes_times = InsetQuotes::DoubleQ;
331 fontsize = "default";
334 papersize = PAPER_DEFAULT;
335 papersize2 = VM_PAPER_DEFAULT; /* 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;
345 language = default_language;
348 graphicsDriver = "default";
349 sides = LyXTextClass::OneSide;
351 pagestyle = "default";
353 for (int iter = 0; iter < 4; ++iter) {
354 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
355 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
360 BufferParams::~BufferParams()
364 AuthorList & BufferParams::authors()
366 return pimpl_->authorlist;
370 AuthorList const & BufferParams::authors() const
372 return pimpl_->authorlist;
376 BranchList & BufferParams::branchlist()
378 return pimpl_->branchlist;
382 BranchList const & BufferParams::branchlist() const
384 return pimpl_->branchlist;
388 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
390 BOOST_ASSERT(index < 4);
391 return pimpl_->temp_bullets[index];
395 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
397 BOOST_ASSERT(index < 4);
398 return pimpl_->temp_bullets[index];
402 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
404 BOOST_ASSERT(index < 4);
405 return pimpl_->user_defined_bullets[index];
409 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
411 BOOST_ASSERT(index < 4);
412 return pimpl_->user_defined_bullets[index];
416 Spacing & BufferParams::spacing()
418 return pimpl_->spacing;
422 Spacing const & BufferParams::spacing() const
424 return pimpl_->spacing;
428 VSpace const & BufferParams::getDefSkip() const
430 return pimpl_->defskip;
434 void BufferParams::setDefSkip(VSpace const & vs)
436 pimpl_->defskip = vs;
440 string const BufferParams::readToken(LyXLex & lex, string const & token)
442 if (token == "\\textclass") {
444 string const classname = lex.getString();
445 pair<bool, lyx::textclass_type> pp =
446 textclasslist.NumberOfClass(classname);
448 textclass = pp.second;
453 if (!getLyXTextClass().isTeXClassAvailable()) {
455 bformat(_("The document uses a missing "
456 "TeX class \"%1$s\".\n"), classname);
457 Alert::warning(_("Document class not available"),
458 msg + _("LyX will not be able to produce output."));
460 } else if (token == "\\begin_preamble") {
462 } else if (token == "\\options") {
464 options = lex.getString();
465 } else if (token == "\\language") {
467 } else if (token == "\\inputencoding") {
469 } else if (token == "\\graphics") {
470 readGraphicsDriver(lex);
471 } else if (token == "\\fontscheme") {
473 } else if (token == "\\paragraph_separation") {
476 paragraph_separation = parseptranslator().find(parsep);
477 } else if (token == "\\defskip") {
479 pimpl_->defskip = VSpace(lex.getString());
480 } else if (token == "\\quotes_language") {
483 quotes_language = quoteslangtranslator().find(quotes_lang);
484 } else if (token == "\\quotes_times") {
487 quotes_times = quotestimestranslator().find(qtimes);
488 } else if (token == "\\papersize") {
491 papersize2 = papersizetranslator().find(ppsize);
492 } else if (token == "\\paperpackage") {
495 paperpackage = paperpackagestranslator().find(ppackage);
496 } else if (token == "\\use_geometry") {
498 } else if (token == "\\use_amsmath") {
501 use_amsmath = amstranslator().find(use_ams);
502 } else if (token == "\\cite_engine") {
505 cite_engine = citeenginetranslator().find(engine);
506 } else if (token == "\\use_bibtopic") {
508 } else if (token == "\\tracking_changes") {
509 lex >> tracking_changes;
510 } else if (token == "\\branch") {
512 string branch = lex.getString();
513 branchlist().add(branch);
516 string const tok = lex.getString();
517 if (tok == "\\end_branch")
519 Branch * branch_ptr = branchlist().find(branch);
520 if (tok == "\\selected") {
523 branch_ptr->setSelected(lex.getInteger());
525 // not yet operational
526 if (tok == "\\color") {
528 string color = lex.getString();
530 branch_ptr->setColor(color);
531 // Update also the LColor table:
533 color = lcolor.getX11Name(LColor::background);
534 lcolor.setColor(branch, color);
538 } else if (token == "\\author") {
540 istringstream ss(lex.getString());
543 author_map.push_back(pimpl_->authorlist.record(a));
544 } else if (token == "\\paperorientation") {
547 orientation = paperorientationtranslator().find(orient);
548 } else if (token == "\\paperwidth") {
550 } else if (token == "\\paperheight") {
552 } else if (token == "\\leftmargin") {
554 } else if (token == "\\topmargin") {
556 } else if (token == "\\rightmargin") {
558 } else if (token == "\\bottommargin") {
560 } else if (token == "\\headheight") {
562 } else if (token == "\\headsep") {
564 } else if (token == "\\footskip") {
566 } else if (token == "\\paperfontsize") {
568 } else if (token == "\\papercolumns") {
570 } else if (token == "\\papersides") {
573 sides = sidestranslator().find(psides);
574 } else if (token == "\\paperpagestyle") {
576 } else if (token == "\\bullet") {
578 } else if (token == "\\bulletLaTeX") {
579 readBulletsLaTeX(lex);
580 } else if (token == "\\secnumdepth") {
582 } else if (token == "\\tocdepth") {
584 } else if (token == "\\spacing") {
588 if (nspacing == "other") {
591 spacing().set(spacetranslator().find(nspacing), tmp_val);
592 } else if (token == "\\float_placement") {
593 lex >> float_placement;
602 void BufferParams::writeFile(ostream & os) const
604 // The top of the file is written by the buffer.
605 // Prints out the buffer info into the .lyx file given by file
608 os << "\\textclass " << textclasslist[textclass].name() << '\n';
610 // then the the preamble
611 if (!preamble.empty()) {
612 // remove '\n' from the end of preamble
613 string const tmppreamble = rtrim(preamble, "\n");
614 os << "\\begin_preamble\n"
616 << "\n\\end_preamble\n";
620 if (!options.empty()) {
621 os << "\\options " << options << '\n';
624 // then the text parameters
625 if (language != ignore_language)
626 os << "\\language " << language->lang() << '\n';
627 os << "\\inputencoding " << inputenc
628 << "\n\\fontscheme " << fonts
629 << "\n\\graphics " << graphicsDriver << '\n';
631 if (!float_placement.empty()) {
632 os << "\\float_placement " << float_placement << '\n';
634 os << "\\paperfontsize " << fontsize << '\n';
636 spacing().writeFile(os);
638 os << "\\papersize " << string_papersize[papersize2]
639 << "\n\\paperpackage " << string_paperpackages[paperpackage]
640 << "\n\\use_geometry " << convert<string>(use_geometry)
641 << "\n\\use_amsmath " << use_amsmath
642 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
643 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
644 << "\n\\paperorientation " << string_orientation[orientation]
647 std::list<Branch>::const_iterator it = branchlist().begin();
648 std::list<Branch>::const_iterator end = branchlist().end();
649 for (; it != end; ++it) {
650 os << "\\branch " << it->getBranch()
651 << "\n\\selected " << it->getSelected()
652 << "\n\\color " << it->getColor()
657 if (!paperwidth.empty())
658 os << "\\paperwidth "
659 << VSpace(paperwidth).asLyXCommand() << '\n';
660 if (!paperheight.empty())
661 os << "\\paperheight "
662 << VSpace(paperheight).asLyXCommand() << '\n';
663 if (!leftmargin.empty())
664 os << "\\leftmargin "
665 << VSpace(leftmargin).asLyXCommand() << '\n';
666 if (!topmargin.empty())
668 << VSpace(topmargin).asLyXCommand() << '\n';
669 if (!rightmargin.empty())
670 os << "\\rightmargin "
671 << VSpace(rightmargin).asLyXCommand() << '\n';
672 if (!bottommargin.empty())
673 os << "\\bottommargin "
674 << VSpace(bottommargin).asLyXCommand() << '\n';
675 if (!headheight.empty())
676 os << "\\headheight "
677 << VSpace(headheight).asLyXCommand() << '\n';
678 if (!headsep.empty())
680 << VSpace(headsep).asLyXCommand() << '\n';
681 if (!footskip.empty())
683 << VSpace(footskip).asLyXCommand() << '\n';
684 os << "\\secnumdepth " << secnumdepth
685 << "\n\\tocdepth " << tocdepth
686 << "\n\\paragraph_separation "
687 << string_paragraph_separation[paragraph_separation]
688 << "\n\\defskip " << getDefSkip().asLyXCommand()
689 << "\n\\quotes_language "
690 << string_quotes_language[quotes_language] << '\n'
692 << quotestimestranslator().find(quotes_times)
693 << "\n\\papercolumns " << columns
694 << "\n\\papersides " << sides
695 << "\n\\paperpagestyle " << pagestyle << '\n';
696 for (int i = 0; i < 4; ++i) {
697 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
698 if (user_defined_bullet(i).getFont() != -1) {
699 os << "\\bullet " << i << " "
700 << user_defined_bullet(i).getFont() << " "
701 << user_defined_bullet(i).getCharacter() << " "
702 << user_defined_bullet(i).getSize() << "\n";
705 os << "\\bulletLaTeX " << i << " \""
706 << user_defined_bullet(i).getText()
712 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
714 if (tracking_changes) {
715 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
716 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
717 for (; it != end; ++it) {
718 os << "\\author " << it->second << "\n";
724 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
725 TexRow & texrow) const
727 os << "\\documentclass";
729 LyXTextClass const & tclass = getLyXTextClass();
731 ostringstream clsoptions; // the document class options.
733 if (tokenPos(tclass.opt_fontsize(),
734 '|', fontsize) >= 0) {
735 // only write if existing in list (and not default)
736 clsoptions << fontsize << "pt,";
741 (paperpackage == PACKAGE_NONE)) {
744 clsoptions << "a3paper,";
747 clsoptions << "a4paper,";
750 clsoptions << "letterpaper,";
753 clsoptions << "a5paper,";
756 clsoptions << "b5paper,";
758 case PAPER_EXECUTIVEPAPER:
759 clsoptions << "executivepaper,";
761 case PAPER_LEGALPAPER:
762 clsoptions << "legalpaper,";
770 if (sides != tclass.sides()) {
772 case LyXTextClass::OneSide:
773 clsoptions << "oneside,";
775 case LyXTextClass::TwoSides:
776 clsoptions << "twoside,";
782 if (columns != tclass.columns()) {
784 clsoptions << "twocolumn,";
786 clsoptions << "onecolumn,";
790 && orientation == ORIENTATION_LANDSCAPE)
791 clsoptions << "landscape,";
793 // language should be a parameter to \documentclass
794 if (language->babel() == "hebrew"
795 && default_language->babel() != "hebrew")
796 // This seems necessary
797 features.useLanguage(default_language);
799 ostringstream language_options;
800 bool const use_babel = features.useBabel();
802 language_options << features.getLanguages();
803 language_options << language->babel();
804 if (lyxrc.language_global_options)
805 clsoptions << language_options.str() << ',';
808 // the user-defined options
809 if (!options.empty()) {
810 clsoptions << options << ',';
813 string strOptions(clsoptions.str());
814 if (!strOptions.empty()) {
815 strOptions = rtrim(strOptions, ",");
816 os << '[' << strOptions << ']';
819 os << '{' << tclass.latexname() << "}\n";
821 // end of \documentclass defs
823 // font selection must be done before loading fontenc.sty
824 // The ae package is not needed when using OT1 font encoding.
825 if (fonts != "default" &&
826 (fonts != "ae" || lyxrc.fontenc != "default")) {
827 os << "\\usepackage{" << fonts << "}\n";
830 os << "\\usepackage{aecompl}\n";
834 // this one is not per buffer
835 if (lyxrc.fontenc != "default") {
836 os << "\\usepackage[" << lyxrc.fontenc
841 if (inputenc == "auto") {
842 string const doc_encoding =
843 language->encoding()->LatexName();
845 // Create a list with all the input encodings used
847 std::set<string> encodings =
848 features.getEncodingSet(doc_encoding);
850 os << "\\usepackage[";
851 std::copy(encodings.begin(), encodings.end(),
852 std::ostream_iterator<string>(os, ","));
853 os << doc_encoding << "]{inputenc}\n";
855 } else if (inputenc != "default") {
856 os << "\\usepackage[" << inputenc
861 // At the very beginning the text parameters.
862 if (paperpackage != PACKAGE_NONE) {
863 switch (paperpackage) {
867 os << "\\usepackage{a4}\n";
871 os << "\\usepackage{a4wide}\n";
874 case PACKAGE_WIDEMARGINSA4:
875 os << "\\usepackage[widemargins]{a4}\n";
881 os << "\\usepackage{geometry}\n";
883 os << "\\geometry{verbose";
884 if (orientation == ORIENTATION_LANDSCAPE)
886 switch (papersize2) {
887 case VM_PAPER_CUSTOM:
888 if (!paperwidth.empty())
891 if (!paperheight.empty())
892 os << ",paperheight="
895 case VM_PAPER_USLETTER:
896 os << ",letterpaper";
898 case VM_PAPER_USLEGAL:
901 case VM_PAPER_USEXECUTIVE:
902 os << ",executivepaper";
923 // default papersize ie VM_PAPER_DEFAULT
924 switch (lyxrc.default_papersize) {
925 case PAPER_DEFAULT: // keep compiler happy
927 os << ",letterpaper";
929 case PAPER_LEGALPAPER:
932 case PAPER_EXECUTIVEPAPER:
933 os << ",executivepaper";
949 if (!topmargin.empty())
950 os << ",tmargin=" << topmargin;
951 if (!bottommargin.empty())
952 os << ",bmargin=" << bottommargin;
953 if (!leftmargin.empty())
954 os << ",lmargin=" << leftmargin;
955 if (!rightmargin.empty())
956 os << ",rmargin=" << rightmargin;
957 if (!headheight.empty())
958 os << ",headheight=" << headheight;
959 if (!headsep.empty())
960 os << ",headsep=" << headsep;
961 if (!footskip.empty())
962 os << ",footskip=" << footskip;
967 if (tokenPos(tclass.opt_pagestyle(),
968 '|', pagestyle) >= 0) {
969 if (pagestyle == "fancy") {
970 os << "\\usepackage{fancyhdr}\n";
973 os << "\\pagestyle{" << pagestyle << "}\n";
977 if (secnumdepth != tclass.secnumdepth()) {
978 os << "\\setcounter{secnumdepth}{"
983 if (tocdepth != tclass.tocdepth()) {
984 os << "\\setcounter{tocdepth}{"
990 if (paragraph_separation) {
991 switch (getDefSkip().kind()) {
992 case VSpace::SMALLSKIP:
993 os << "\\setlength\\parskip{\\smallskipamount}\n";
995 case VSpace::MEDSKIP:
996 os << "\\setlength\\parskip{\\medskipamount}\n";
998 case VSpace::BIGSKIP:
999 os << "\\setlength\\parskip{\\bigskipamount}\n";
1001 case VSpace::LENGTH:
1002 os << "\\setlength\\parskip{"
1003 << getDefSkip().length().asLatexString()
1006 default: // should never happen // Then delete it.
1007 os << "\\setlength\\parskip{\\medskipamount}\n";
1012 os << "\\setlength\\parindent{0pt}\n";
1016 // If we use jurabib, we have to call babel here.
1017 if (use_babel && features.isRequired("jurabib")) {
1018 os << babelCall(language_options.str())
1020 << features.getBabelOptions();
1024 // Now insert the LyX specific LaTeX commands...
1026 // The optional packages;
1027 string lyxpreamble(features.getPackages());
1029 // this might be useful...
1030 lyxpreamble += "\n\\makeatletter\n";
1032 // Some macros LyX will need
1033 string tmppreamble(features.getMacros());
1035 if (!tmppreamble.empty()) {
1036 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1037 "LyX specific LaTeX commands.\n"
1038 + tmppreamble + '\n';
1041 // the text class specific preamble
1042 tmppreamble = features.getTClassPreamble();
1043 if (!tmppreamble.empty()) {
1044 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1045 "Textclass specific LaTeX commands.\n"
1046 + tmppreamble + '\n';
1049 /* the user-defined preamble */
1050 if (!preamble.empty()) {
1051 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1052 "User specified LaTeX commands.\n"
1056 // Itemize bullet settings need to be last in case the user
1057 // defines their own bullets that use a package included
1058 // in the user-defined preamble -- ARRae
1059 // Actually it has to be done much later than that
1060 // since some packages like frenchb make modifications
1061 // at \begin{document} time -- JMarc
1063 for (int i = 0; i < 4; ++i) {
1064 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1065 if (bullets_def.empty())
1066 bullets_def="\\AtBeginDocument{\n";
1067 bullets_def += " \\renewcommand{\\labelitemi";
1069 // `i' is one less than the item to modify
1076 bullets_def += "ii";
1082 bullets_def += "}{" +
1083 user_defined_bullet(i).getText()
1088 if (!bullets_def.empty())
1089 lyxpreamble += bullets_def + "}\n\n";
1091 // We try to load babel late, in case it interferes
1092 // with other packages.
1093 // Jurabib has to be called after babel, though.
1094 if (use_babel && !features.isRequired("jurabib")) {
1095 lyxpreamble += babelCall(language_options.str()) + '\n';
1096 lyxpreamble += features.getBabelOptions();
1099 lyxpreamble += "\\makeatother\n";
1101 // dvipost settings come after everything else
1102 if (tracking_changes) {
1105 "\\dvipost{osstart color push Red}\n"
1106 "\\dvipost{osend color pop}\n"
1107 "\\dvipost{cbstart color push Blue}\n"
1108 "\\dvipost{cbend color pop}\n";
1112 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1113 for (int j = 0; j != nlines; ++j) {
1122 void BufferParams::setPaperStuff()
1124 papersize = PAPER_DEFAULT;
1125 char const c1 = paperpackage;
1126 if (c1 == PACKAGE_NONE) {
1127 char const c2 = papersize2;
1128 if (c2 == VM_PAPER_USLETTER)
1129 papersize = PAPER_USLETTER;
1130 else if (c2 == VM_PAPER_USLEGAL)
1131 papersize = PAPER_LEGALPAPER;
1132 else if (c2 == VM_PAPER_USEXECUTIVE)
1133 papersize = PAPER_EXECUTIVEPAPER;
1134 else if (c2 == VM_PAPER_A3)
1135 papersize = PAPER_A3PAPER;
1136 else if (c2 == VM_PAPER_A4)
1137 papersize = PAPER_A4PAPER;
1138 else if (c2 == VM_PAPER_A5)
1139 papersize = PAPER_A5PAPER;
1140 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1141 (c2 == VM_PAPER_B5))
1142 papersize = PAPER_B5PAPER;
1143 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1144 (c1 == PACKAGE_WIDEMARGINSA4))
1145 papersize = PAPER_A4PAPER;
1149 void BufferParams::useClassDefaults()
1151 LyXTextClass const & tclass = textclasslist[textclass];
1153 sides = tclass.sides();
1154 columns = tclass.columns();
1155 pagestyle = tclass.pagestyle();
1156 options = tclass.options();
1157 secnumdepth = tclass.secnumdepth();
1158 tocdepth = tclass.tocdepth();
1162 bool BufferParams::hasClassDefaults() const
1164 LyXTextClass const & tclass = textclasslist[textclass];
1166 return (sides == tclass.sides()
1167 && columns == tclass.columns()
1168 && pagestyle == tclass.pagestyle()
1169 && options == tclass.options()
1170 && secnumdepth == tclass.secnumdepth()
1171 && tocdepth == tclass.tocdepth());
1175 LyXTextClass const & BufferParams::getLyXTextClass() const
1177 return textclasslist[textclass];
1181 void BufferParams::readPreamble(LyXLex & lex)
1183 if (lex.getString() != "\\begin_preamble")
1184 lyxerr << "Error (BufferParams::readPreamble):"
1185 "consistency check failed." << endl;
1187 preamble = lex.getLongString("\\end_preamble");
1191 void BufferParams::readLanguage(LyXLex & lex)
1193 if (!lex.next()) return;
1195 string const tmptok = lex.getString();
1197 // check if tmptok is part of tex_babel in tex-defs.h
1198 language = languages.getLanguage(tmptok);
1200 // Language tmptok was not found
1201 language = default_language;
1202 lyxerr << "Warning: Setting language `"
1203 << tmptok << "' to `" << language->lang()
1209 void BufferParams::readGraphicsDriver(LyXLex & lex)
1211 if (!lex.next()) return;
1213 string const tmptok = lex.getString();
1214 // check if tmptok is part of tex_graphics in tex_defs.h
1217 string const test = tex_graphics[n++];
1219 if (test == tmptok) {
1220 graphicsDriver = tmptok;
1222 } else if (test == "last_item") {
1224 "Warning: graphics driver `$$Token' not recognized!\n"
1225 " Setting graphics driver to `default'.\n");
1226 graphicsDriver = "default";
1233 void BufferParams::readBullets(LyXLex & lex)
1235 if (!lex.next()) return;
1237 int const index = lex.getInteger();
1239 int temp_int = lex.getInteger();
1240 user_defined_bullet(index).setFont(temp_int);
1241 temp_bullet(index).setFont(temp_int);
1243 user_defined_bullet(index).setCharacter(temp_int);
1244 temp_bullet(index).setCharacter(temp_int);
1246 user_defined_bullet(index).setSize(temp_int);
1247 temp_bullet(index).setSize(temp_int);
1251 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1253 // The bullet class should be able to read this.
1254 if (!lex.next()) return;
1255 int const index = lex.getInteger();
1257 string const temp_str = lex.getString();
1259 user_defined_bullet(index).setText(temp_str);
1260 temp_bullet(index).setText(temp_str);
1264 string const BufferParams::paperSizeName() const
1266 char real_papersize = papersize;
1267 if (real_papersize == PAPER_DEFAULT)
1268 real_papersize = lyxrc.default_papersize;
1270 switch (real_papersize) {
1279 case PAPER_EXECUTIVEPAPER:
1281 case PAPER_LEGALPAPER:
1283 case PAPER_USLETTER:
1290 string const BufferParams::dvips_options() const
1295 && papersize2 == VM_PAPER_CUSTOM
1296 && !lyxrc.print_paper_dimension_flag.empty()
1297 && !paperwidth.empty()
1298 && !paperheight.empty()) {
1299 // using a custom papersize
1300 result = lyxrc.print_paper_dimension_flag;
1301 result += ' ' + paperwidth;
1302 result += ',' + paperheight;
1304 string const paper_option = paperSizeName();
1305 if (paper_option != "letter" ||
1306 orientation != ORIENTATION_LANDSCAPE) {
1307 // dvips won't accept -t letter -t landscape.
1308 // In all other cases, include the paper size
1310 result = lyxrc.print_paper_flag;
1311 result += ' ' + paper_option;
1314 if (orientation == ORIENTATION_LANDSCAPE &&
1315 papersize2 != VM_PAPER_CUSTOM)
1316 result += ' ' + lyxrc.print_landscape_flag;
1321 string const BufferParams::babelCall(string const & lang_opts) const
1323 string tmp = lyxrc.language_package;
1324 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1325 tmp = string("\\usepackage[") + lang_opts + "]{babel}";