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/translator.h"
43 #include <boost/array.hpp>
47 namespace support = lyx::support;
48 using lyx::support::bformat;
49 using lyx::support::rtrim;
50 using lyx::support::tokenPos;
54 using std::istringstream;
56 using std::ostringstream;
59 namespace biblio = lyx::biblio;
65 // Paragraph separation
66 typedef Translator<std::string, BufferParams::PARSEP> ParSepTranslator;
69 ParSepTranslator const init_parseptranslator() {
70 ParSepTranslator translator(string_paragraph_separation[0], BufferParams::PARSEP_INDENT);
71 translator.addPair(string_paragraph_separation[1], BufferParams::PARSEP_SKIP);
76 ParSepTranslator const & parseptranslator() {
77 static ParSepTranslator translator = init_parseptranslator();
82 typedef Translator<std::string, InsetQuotes::quote_language> QuotesLangTranslator;
85 QuotesLangTranslator const init_quoteslangtranslator() {
86 QuotesLangTranslator translator(string_quotes_language[0], InsetQuotes::EnglishQ);
87 translator.addPair(string_quotes_language[1], InsetQuotes::SwedishQ);
88 translator.addPair(string_quotes_language[2], InsetQuotes::GermanQ);
89 translator.addPair(string_quotes_language[3], InsetQuotes::PolishQ);
90 translator.addPair(string_quotes_language[4], InsetQuotes::FrenchQ);
91 translator.addPair(string_quotes_language[5], InsetQuotes::DanishQ);
96 QuotesLangTranslator const & quoteslangtranslator() {
97 static QuotesLangTranslator translator = init_quoteslangtranslator();
102 typedef Translator<int, InsetQuotes::quote_times> QuotesTimesTranslator;
105 QuotesTimesTranslator const init_quotestimestranslator() {
106 QuotesTimesTranslator translator(1, InsetQuotes::SingleQ);
107 translator.addPair(2, InsetQuotes::DoubleQ);
112 QuotesTimesTranslator const & quotestimestranslator() {
113 static QuotesTimesTranslator translator = init_quotestimestranslator();
118 typedef Translator<std::string, VMARGIN_PAPER_TYPE> PaperSizeTranslator;
121 PaperSizeTranslator const init_papersizetranslator() {
122 PaperSizeTranslator translator(string_papersize[0], VM_PAPER_DEFAULT);
123 translator.addPair(string_papersize[1], VM_PAPER_CUSTOM);
124 translator.addPair(string_papersize[2], VM_PAPER_USLETTER);
125 translator.addPair(string_papersize[3], VM_PAPER_USLEGAL);
126 translator.addPair(string_papersize[4], VM_PAPER_USEXECUTIVE);
127 translator.addPair(string_papersize[5], VM_PAPER_A3);
128 translator.addPair(string_papersize[6], VM_PAPER_A4);
129 translator.addPair(string_papersize[7], VM_PAPER_A5);
130 translator.addPair(string_papersize[8], VM_PAPER_B3);
131 translator.addPair(string_papersize[9], VM_PAPER_B4);
132 translator.addPair(string_papersize[10], VM_PAPER_B5);
137 PaperSizeTranslator const & papersizetranslator() {
138 static PaperSizeTranslator translator = init_papersizetranslator();
143 typedef Translator<std::string, PAPER_PACKAGES> PaperPackagesTranslator;
146 PaperPackagesTranslator const init_paperpackagestranslator() {
147 PaperPackagesTranslator translator(string_paperpackages[0], PACKAGE_NONE);
148 translator.addPair(string_paperpackages[1], PACKAGE_A4);
149 translator.addPair(string_paperpackages[2], PACKAGE_A4WIDE);
150 translator.addPair(string_paperpackages[3], PACKAGE_WIDEMARGINSA4);
155 PaperPackagesTranslator const & paperpackagestranslator() {
156 static PaperPackagesTranslator translator = init_paperpackagestranslator();
162 typedef Translator<std::string, PAPER_ORIENTATION> PaperOrientationTranslator;
165 PaperOrientationTranslator const init_paperorientationtranslator() {
166 PaperOrientationTranslator translator(string_orientation[0], ORIENTATION_PORTRAIT);
167 translator.addPair(string_orientation[1], ORIENTATION_LANDSCAPE);
172 PaperOrientationTranslator const & paperorientationtranslator() {
173 static PaperOrientationTranslator translator = init_paperorientationtranslator();
179 typedef Translator<int, LyXTextClass::PageSides> SidesTranslator;
182 SidesTranslator const init_sidestranslator() {
183 SidesTranslator translator(1, LyXTextClass::OneSide);
184 translator.addPair(2, LyXTextClass::TwoSides);
189 SidesTranslator const & sidestranslator() {
190 static SidesTranslator translator = init_sidestranslator();
197 typedef Translator<int, BufferParams::AMS> AMSTranslator;
200 AMSTranslator const init_amstranslator() {
201 AMSTranslator translator(0, BufferParams::AMS_OFF);
202 translator.addPair(1, BufferParams::AMS_AUTO);
203 translator.addPair(2, BufferParams::AMS_ON);
208 AMSTranslator const & amstranslator() {
209 static AMSTranslator translator = init_amstranslator();
216 typedef Translator<string, biblio::CiteEngine> CiteEngineTranslator;
219 CiteEngineTranslator const init_citeenginetranslator() {
220 CiteEngineTranslator translator("basic", biblio::ENGINE_BASIC);
221 translator.addPair("natbib_numerical", biblio::ENGINE_NATBIB_NUMERICAL);
222 translator.addPair("natbib_authoryear", biblio::ENGINE_NATBIB_AUTHORYEAR);
223 translator.addPair("jurabib", biblio::ENGINE_JURABIB);
228 CiteEngineTranslator const & citeenginetranslator() {
229 static CiteEngineTranslator translator = init_citeenginetranslator();
235 typedef Translator<string, Spacing::Space> SpaceTranslator;
238 SpaceTranslator const init_spacetranslator() {
239 SpaceTranslator translator("default", Spacing::Default);
240 translator.addPair("single", Spacing::Single);
241 translator.addPair("onehalf", Spacing::Onehalf);
242 translator.addPair("double", Spacing::Double);
247 SpaceTranslator const & spacetranslator() {
248 static SpaceTranslator translator = init_spacetranslator();
252 // ends annonym namespace
256 struct BufferParams::Impl
260 AuthorList authorlist;
261 BranchList branchlist;
262 boost::array<Bullet, 4> temp_bullets;
263 boost::array<Bullet, 4> user_defined_bullets;
265 /** This is the amount of space used for paragraph_separation "skip",
266 * and for detached paragraphs in "indented" documents.
272 BufferParams::Impl::Impl()
273 : defskip(VSpace::MEDSKIP)
275 // set initial author
276 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
281 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
283 return new BufferParams::Impl(*ptr);
287 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
293 BufferParams::BufferParams()
294 : // Initialize textclass to point to article. if `first' is
295 // true in the returned pair, then `second' is the textclass
296 // number; if it is false, second is 0. In both cases, second
298 textclass(textclasslist.NumberOfClass("article").second),
301 paragraph_separation = PARSEP_INDENT;
302 quotes_language = InsetQuotes::EnglishQ;
303 quotes_times = InsetQuotes::DoubleQ;
304 fontsize = "default";
307 papersize = PAPER_DEFAULT;
308 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
309 paperpackage = PACKAGE_NONE;
310 orientation = ORIENTATION_PORTRAIT;
311 use_geometry = false;
312 use_amsmath = AMS_AUTO;
313 cite_engine = biblio::ENGINE_BASIC;
314 use_bibtopic = false;
315 tracking_changes = false;
318 language = default_language;
321 graphicsDriver = "default";
322 sides = LyXTextClass::OneSide;
324 pagestyle = "default";
326 for (int iter = 0; iter < 4; ++iter) {
327 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
328 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
333 BufferParams::~BufferParams()
337 AuthorList & BufferParams::authors()
339 return pimpl_->authorlist;
343 AuthorList const & BufferParams::authors() const
345 return pimpl_->authorlist;
349 BranchList & BufferParams::branchlist()
351 return pimpl_->branchlist;
355 BranchList const & BufferParams::branchlist() const
357 return pimpl_->branchlist;
361 Bullet & BufferParams::temp_bullet(lyx::size_type index)
363 BOOST_ASSERT(index < 4);
364 return pimpl_->temp_bullets[index];
368 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
370 BOOST_ASSERT(index < 4);
371 return pimpl_->temp_bullets[index];
375 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
377 BOOST_ASSERT(index < 4);
378 return pimpl_->user_defined_bullets[index];
382 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
384 BOOST_ASSERT(index < 4);
385 return pimpl_->user_defined_bullets[index];
389 Spacing & BufferParams::spacing()
391 return pimpl_->spacing;
395 Spacing const & BufferParams::spacing() const
397 return pimpl_->spacing;
401 VSpace const & BufferParams::getDefSkip() const
403 return pimpl_->defskip;
407 void BufferParams::setDefSkip(VSpace const & vs)
409 pimpl_->defskip = vs;
413 string const BufferParams::readToken(LyXLex & lex, string const & token)
415 if (token == "\\textclass") {
417 string const classname = lex.getString();
418 pair<bool, lyx::textclass_type> pp =
419 textclasslist.NumberOfClass(classname);
421 textclass = pp.second;
426 if (!getLyXTextClass().isTeXClassAvailable()) {
427 string msg = bformat(_("The document uses a missing "
428 "TeX class \"%1$s\".\n"), classname);
429 Alert::warning(_("Document class not available"),
430 msg + _("LyX will not be able to produce output."));
432 } else if (token == "\\begin_preamble") {
434 } else if (token == "\\options") {
436 options = lex.getString();
437 } else if (token == "\\language") {
439 } else if (token == "\\inputencoding") {
441 } else if (token == "\\graphics") {
442 readGraphicsDriver(lex);
443 } else if (token == "\\fontscheme") {
445 } else if (token == "\\paragraph_separation") {
448 paragraph_separation = parseptranslator().find(parsep);
449 } else if (token == "\\defskip") {
451 pimpl_->defskip = VSpace(lex.getString());
452 } else if (token == "\\quotes_language") {
455 quotes_language = quoteslangtranslator().find(quotes_lang);
456 } else if (token == "\\quotes_times") {
459 quotes_times = quotestimestranslator().find(qtimes);
460 } else if (token == "\\papersize") {
463 papersize2 = papersizetranslator().find(ppsize);
464 } else if (token == "\\paperpackage") {
467 paperpackage = paperpackagestranslator().find(ppackage);
468 } else if (token == "\\use_geometry") {
470 } else if (token == "\\use_amsmath") {
473 use_amsmath = amstranslator().find(use_ams);
474 } else if (token == "\\cite_engine") {
477 cite_engine = citeenginetranslator().find(engine);
478 } else if (token == "\\use_bibtopic") {
480 } else if (token == "\\tracking_changes") {
481 lex >> tracking_changes;
482 } else if (token == "\\branch") {
484 string branch = lex.getString();
485 branchlist().add(branch);
488 string const tok = lex.getString();
489 if (tok == "\\end_branch")
491 Branch * branch_ptr = branchlist().find(branch);
492 if (tok == "\\selected") {
495 branch_ptr->setSelected(lex.getInteger());
497 // not yet operational
498 if (tok == "\\color") {
500 string color = lex.getString();
502 branch_ptr->setColor(color);
503 // Update also the LColor table:
505 color = lcolor.getX11Name(LColor::background);
506 lcolor.setColor(branch, color);
510 } else if (token == "\\author") {
512 istringstream ss(lex.getString());
515 author_map.push_back(pimpl_->authorlist.record(a));
516 } else if (token == "\\paperorientation") {
519 orientation = paperorientationtranslator().find(orient);
520 } else if (token == "\\paperwidth") {
522 } else if (token == "\\paperheight") {
524 } else if (token == "\\leftmargin") {
526 } else if (token == "\\topmargin") {
528 } else if (token == "\\rightmargin") {
530 } else if (token == "\\bottommargin") {
532 } else if (token == "\\headheight") {
534 } else if (token == "\\headsep") {
536 } else if (token == "\\footskip") {
538 } else if (token == "\\paperfontsize") {
540 } else if (token == "\\papercolumns") {
542 } else if (token == "\\papersides") {
545 sides = sidestranslator().find(psides);
546 } else if (token == "\\paperpagestyle") {
548 } else if (token == "\\bullet") {
550 } else if (token == "\\bulletLaTeX") {
551 readBulletsLaTeX(lex);
552 } else if (token == "\\secnumdepth") {
554 } else if (token == "\\tocdepth") {
556 } else if (token == "\\spacing") {
560 if (nspacing == "other") {
563 spacing().set(spacetranslator().find(nspacing), tmp_val);
564 } else if (token == "\\float_placement") {
565 lex >> float_placement;
574 void BufferParams::writeFile(ostream & os) const
576 // The top of the file is written by the buffer.
577 // Prints out the buffer info into the .lyx file given by file
580 os << "\\textclass " << textclasslist[textclass].name() << '\n';
582 // then the the preamble
583 if (!preamble.empty()) {
584 // remove '\n' from the end of preamble
585 string const tmppreamble = rtrim(preamble, "\n");
586 os << "\\begin_preamble\n"
588 << "\n\\end_preamble\n";
592 if (!options.empty()) {
593 os << "\\options " << options << '\n';
596 /* then the text parameters */
597 if (language != ignore_language)
598 os << "\\language " << language->lang() << '\n';
599 os << "\\inputencoding " << inputenc
600 << "\n\\fontscheme " << fonts
601 << "\n\\graphics " << graphicsDriver << '\n';
603 if (!float_placement.empty()) {
604 os << "\\float_placement " << float_placement << '\n';
606 os << "\\paperfontsize " << fontsize << '\n';
608 spacing().writeFile(os);
610 os << "\\papersize " << string_papersize[papersize2]
611 << "\n\\paperpackage " << string_paperpackages[paperpackage]
612 << "\n\\use_geometry " << use_geometry
613 << "\n\\use_amsmath " << use_amsmath
614 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
615 << "\n\\use_bibtopic " << use_bibtopic
616 << "\n\\paperorientation " << string_orientation[orientation]
619 std::list<Branch>::const_iterator it = branchlist().begin();
620 std::list<Branch>::const_iterator end = branchlist().end();
621 for (; it != end; ++it) {
622 os << "\\branch " << it->getBranch()
623 << "\n\\selected " << it->getSelected()
624 << "\n\\color " << it->getColor()
629 if (!paperwidth.empty())
630 os << "\\paperwidth "
631 << VSpace(paperwidth).asLyXCommand() << '\n';
632 if (!paperheight.empty())
633 os << "\\paperheight "
634 << VSpace(paperheight).asLyXCommand() << '\n';
635 if (!leftmargin.empty())
636 os << "\\leftmargin "
637 << VSpace(leftmargin).asLyXCommand() << '\n';
638 if (!topmargin.empty())
640 << VSpace(topmargin).asLyXCommand() << '\n';
641 if (!rightmargin.empty())
642 os << "\\rightmargin "
643 << VSpace(rightmargin).asLyXCommand() << '\n';
644 if (!bottommargin.empty())
645 os << "\\bottommargin "
646 << VSpace(bottommargin).asLyXCommand() << '\n';
647 if (!headheight.empty())
648 os << "\\headheight "
649 << VSpace(headheight).asLyXCommand() << '\n';
650 if (!headsep.empty())
652 << VSpace(headsep).asLyXCommand() << '\n';
653 if (!footskip.empty())
655 << VSpace(footskip).asLyXCommand() << '\n';
656 os << "\\secnumdepth " << secnumdepth
657 << "\n\\tocdepth " << tocdepth
658 << "\n\\paragraph_separation "
659 << string_paragraph_separation[paragraph_separation]
660 << "\n\\defskip " << getDefSkip().asLyXCommand()
661 << "\n\\quotes_language "
662 << string_quotes_language[quotes_language] << '\n'
664 << quotestimestranslator().find(quotes_times)
665 << "\n\\papercolumns " << columns
666 << "\n\\papersides " << sides
667 << "\n\\paperpagestyle " << pagestyle << '\n';
668 for (int i = 0; i < 4; ++i) {
669 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
670 if (user_defined_bullet(i).getFont() != -1) {
671 os << "\\bullet " << i << " "
672 << user_defined_bullet(i).getFont() << " "
673 << user_defined_bullet(i).getCharacter() << " "
674 << user_defined_bullet(i).getSize() << "\n";
677 os << "\\bulletLaTeX " << i << " \""
678 << user_defined_bullet(i).getText()
684 os << "\\tracking_changes " << tracking_changes << "\n";
686 if (tracking_changes) {
687 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
688 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
689 for (; it != end; ++it) {
690 os << "\\author " << it->second << "\n";
696 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
697 TexRow & texrow) const
699 os << "\\documentclass";
701 LyXTextClass const & tclass = getLyXTextClass();
703 ostringstream clsoptions; // the document class options.
705 if (tokenPos(tclass.opt_fontsize(),
706 '|', fontsize) >= 0) {
707 // only write if existing in list (and not default)
708 clsoptions << fontsize << "pt,";
713 (paperpackage == PACKAGE_NONE)) {
716 clsoptions << "a3paper,";
719 clsoptions << "a4paper,";
722 clsoptions << "letterpaper,";
725 clsoptions << "a5paper,";
728 clsoptions << "b5paper,";
730 case PAPER_EXECUTIVEPAPER:
731 clsoptions << "executivepaper,";
733 case PAPER_LEGALPAPER:
734 clsoptions << "legalpaper,";
742 if (sides != tclass.sides()) {
744 case LyXTextClass::OneSide:
745 clsoptions << "oneside,";
747 case LyXTextClass::TwoSides:
748 clsoptions << "twoside,";
754 if (columns != tclass.columns()) {
756 clsoptions << "twocolumn,";
758 clsoptions << "onecolumn,";
762 && orientation == ORIENTATION_LANDSCAPE)
763 clsoptions << "landscape,";
765 // language should be a parameter to \documentclass
766 if (language->babel() == "hebrew"
767 && default_language->babel() != "hebrew")
768 // This seems necessary
769 features.useLanguage(default_language);
771 ostringstream language_options;
772 bool const use_babel = features.useBabel();
774 language_options << features.getLanguages();
775 language_options << language->babel();
776 if (lyxrc.language_global_options)
777 clsoptions << language_options.str() << ',';
780 // the user-defined options
781 if (!options.empty()) {
782 clsoptions << options << ',';
785 string strOptions(clsoptions.str());
786 if (!strOptions.empty()) {
787 strOptions = rtrim(strOptions, ",");
788 os << '[' << strOptions << ']';
791 os << '{' << tclass.latexname() << "}\n";
793 // end of \documentclass defs
795 // font selection must be done before loading fontenc.sty
796 // The ae package is not needed when using OT1 font encoding.
797 if (fonts != "default" &&
798 (fonts != "ae" || lyxrc.fontenc != "default")) {
799 os << "\\usepackage{" << fonts << "}\n";
802 os << "\\usepackage{aecompl}\n";
806 // this one is not per buffer
807 if (lyxrc.fontenc != "default") {
808 os << "\\usepackage[" << lyxrc.fontenc
813 if (inputenc == "auto") {
814 string const doc_encoding =
815 language->encoding()->LatexName();
817 // Create a list with all the input encodings used
819 std::set<string> encodings =
820 features.getEncodingSet(doc_encoding);
822 os << "\\usepackage[";
823 std::copy(encodings.begin(), encodings.end(),
824 std::ostream_iterator<string>(os, ","));
825 os << doc_encoding << "]{inputenc}\n";
827 } else if (inputenc != "default") {
828 os << "\\usepackage[" << inputenc
833 // At the very beginning the text parameters.
834 if (paperpackage != PACKAGE_NONE) {
835 switch (paperpackage) {
839 os << "\\usepackage{a4}\n";
843 os << "\\usepackage{a4wide}\n";
846 case PACKAGE_WIDEMARGINSA4:
847 os << "\\usepackage[widemargins]{a4}\n";
853 os << "\\usepackage{geometry}\n";
855 os << "\\geometry{verbose";
856 if (orientation == ORIENTATION_LANDSCAPE)
858 switch (papersize2) {
859 case VM_PAPER_CUSTOM:
860 if (!paperwidth.empty())
863 if (!paperheight.empty())
864 os << ",paperheight="
867 case VM_PAPER_USLETTER:
868 os << ",letterpaper";
870 case VM_PAPER_USLEGAL:
873 case VM_PAPER_USEXECUTIVE:
874 os << ",executivepaper";
895 // default papersize ie VM_PAPER_DEFAULT
896 switch (lyxrc.default_papersize) {
897 case PAPER_DEFAULT: // keep compiler happy
899 os << ",letterpaper";
901 case PAPER_LEGALPAPER:
904 case PAPER_EXECUTIVEPAPER:
905 os << ",executivepaper";
921 if (!topmargin.empty())
922 os << ",tmargin=" << topmargin;
923 if (!bottommargin.empty())
924 os << ",bmargin=" << bottommargin;
925 if (!leftmargin.empty())
926 os << ",lmargin=" << leftmargin;
927 if (!rightmargin.empty())
928 os << ",rmargin=" << rightmargin;
929 if (!headheight.empty())
930 os << ",headheight=" << headheight;
931 if (!headsep.empty())
932 os << ",headsep=" << headsep;
933 if (!footskip.empty())
934 os << ",footskip=" << footskip;
939 if (tokenPos(tclass.opt_pagestyle(),
940 '|', pagestyle) >= 0) {
941 if (pagestyle == "fancy") {
942 os << "\\usepackage{fancyhdr}\n";
945 os << "\\pagestyle{" << pagestyle << "}\n";
949 if (secnumdepth != tclass.secnumdepth()) {
950 os << "\\setcounter{secnumdepth}{"
955 if (tocdepth != tclass.tocdepth()) {
956 os << "\\setcounter{tocdepth}{"
962 if (paragraph_separation) {
963 switch (getDefSkip().kind()) {
964 case VSpace::SMALLSKIP:
965 os << "\\setlength\\parskip{\\smallskipamount}\n";
967 case VSpace::MEDSKIP:
968 os << "\\setlength\\parskip{\\medskipamount}\n";
970 case VSpace::BIGSKIP:
971 os << "\\setlength\\parskip{\\bigskipamount}\n";
974 os << "\\setlength\\parskip{"
975 << getDefSkip().length().asLatexString()
978 default: // should never happen // Then delete it.
979 os << "\\setlength\\parskip{\\medskipamount}\n";
984 os << "\\setlength\\parindent{0pt}\n";
988 // If we use jurabib, we have to call babel here.
989 if (use_babel && features.isRequired("jurabib")) {
990 os << babelCall(language_options.str())
992 << features.getBabelOptions();
996 // Now insert the LyX specific LaTeX commands...
998 // The optional packages;
999 string lyxpreamble(features.getPackages());
1001 // this might be useful...
1002 lyxpreamble += "\n\\makeatletter\n";
1004 // Some macros LyX will need
1005 string tmppreamble(features.getMacros());
1007 if (!tmppreamble.empty()) {
1008 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1009 "LyX specific LaTeX commands.\n"
1010 + tmppreamble + '\n';
1013 // the text class specific preamble
1014 tmppreamble = features.getTClassPreamble();
1015 if (!tmppreamble.empty()) {
1016 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1017 "Textclass specific LaTeX commands.\n"
1018 + tmppreamble + '\n';
1021 /* the user-defined preamble */
1022 if (!preamble.empty()) {
1023 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1024 "User specified LaTeX commands.\n"
1028 // Itemize bullet settings need to be last in case the user
1029 // defines their own bullets that use a package included
1030 // in the user-defined preamble -- ARRae
1031 // Actually it has to be done much later than that
1032 // since some packages like frenchb make modifications
1033 // at \begin{document} time -- JMarc
1035 for (int i = 0; i < 4; ++i) {
1036 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1037 if (bullets_def.empty())
1038 bullets_def="\\AtBeginDocument{\n";
1039 bullets_def += " \\renewcommand{\\labelitemi";
1041 // `i' is one less than the item to modify
1048 bullets_def += "ii";
1054 bullets_def += "}{" +
1055 user_defined_bullet(i).getText()
1060 if (!bullets_def.empty())
1061 lyxpreamble += bullets_def + "}\n\n";
1063 // We try to load babel late, in case it interferes
1064 // with other packages.
1065 // Jurabib has to be called after babel, though.
1066 if (use_babel && !features.isRequired("jurabib")) {
1067 lyxpreamble += babelCall(language_options.str()) + '\n';
1068 lyxpreamble += features.getBabelOptions();
1071 lyxpreamble += "\\makeatother\n";
1073 // dvipost settings come after everything else
1074 if (tracking_changes) {
1077 "\\dvipost{osstart color push Red}\n"
1078 "\\dvipost{osend color pop}\n"
1079 "\\dvipost{cbstart color push Blue}\n"
1080 "\\dvipost{cbend color pop}\n";
1084 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1085 for (int j = 0; j != nlines; ++j) {
1093 void BufferParams::setPaperStuff()
1095 papersize = PAPER_DEFAULT;
1096 char const c1 = paperpackage;
1097 if (c1 == PACKAGE_NONE) {
1098 char const c2 = papersize2;
1099 if (c2 == VM_PAPER_USLETTER)
1100 papersize = PAPER_USLETTER;
1101 else if (c2 == VM_PAPER_USLEGAL)
1102 papersize = PAPER_LEGALPAPER;
1103 else if (c2 == VM_PAPER_USEXECUTIVE)
1104 papersize = PAPER_EXECUTIVEPAPER;
1105 else if (c2 == VM_PAPER_A3)
1106 papersize = PAPER_A3PAPER;
1107 else if (c2 == VM_PAPER_A4)
1108 papersize = PAPER_A4PAPER;
1109 else if (c2 == VM_PAPER_A5)
1110 papersize = PAPER_A5PAPER;
1111 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1112 (c2 == VM_PAPER_B5))
1113 papersize = PAPER_B5PAPER;
1114 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1115 (c1 == PACKAGE_WIDEMARGINSA4))
1116 papersize = PAPER_A4PAPER;
1120 void BufferParams::useClassDefaults()
1122 LyXTextClass const & tclass = textclasslist[textclass];
1124 sides = tclass.sides();
1125 columns = tclass.columns();
1126 pagestyle = tclass.pagestyle();
1127 options = tclass.options();
1128 secnumdepth = tclass.secnumdepth();
1129 tocdepth = tclass.tocdepth();
1133 bool BufferParams::hasClassDefaults() const
1135 LyXTextClass const & tclass = textclasslist[textclass];
1137 return (sides == tclass.sides()
1138 && columns == tclass.columns()
1139 && pagestyle == tclass.pagestyle()
1140 && options == tclass.options()
1141 && secnumdepth == tclass.secnumdepth()
1142 && tocdepth == tclass.tocdepth());
1146 LyXTextClass const & BufferParams::getLyXTextClass() const
1148 return textclasslist[textclass];
1152 void BufferParams::readPreamble(LyXLex & lex)
1154 if (lex.getString() != "\\begin_preamble")
1155 lyxerr << "Error (BufferParams::readPreamble):"
1156 "consistency check failed." << endl;
1158 preamble = lex.getLongString("\\end_preamble");
1162 void BufferParams::readLanguage(LyXLex & lex)
1164 if (!lex.next()) return;
1166 string const tmptok = lex.getString();
1168 // check if tmptok is part of tex_babel in tex-defs.h
1169 language = languages.getLanguage(tmptok);
1171 // Language tmptok was not found
1172 language = default_language;
1173 lyxerr << "Warning: Setting language `"
1174 << tmptok << "' to `" << language->lang()
1180 void BufferParams::readGraphicsDriver(LyXLex & lex)
1182 if (!lex.next()) return;
1184 string const tmptok = lex.getString();
1185 // check if tmptok is part of tex_graphics in tex_defs.h
1188 string const test = tex_graphics[n++];
1190 if (test == tmptok) {
1191 graphicsDriver = tmptok;
1193 } else if (test == "last_item") {
1195 "Warning: graphics driver `$$Token' not recognized!\n"
1196 " Setting graphics driver to `default'.\n");
1197 graphicsDriver = "default";
1204 void BufferParams::readBullets(LyXLex & lex)
1206 if (!lex.next()) return;
1208 int const index = lex.getInteger();
1210 int temp_int = lex.getInteger();
1211 user_defined_bullet(index).setFont(temp_int);
1212 temp_bullet(index).setFont(temp_int);
1214 user_defined_bullet(index).setCharacter(temp_int);
1215 temp_bullet(index).setCharacter(temp_int);
1217 user_defined_bullet(index).setSize(temp_int);
1218 temp_bullet(index).setSize(temp_int);
1222 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1224 // The bullet class should be able to read this.
1225 if (!lex.next()) return;
1226 int const index = lex.getInteger();
1228 string temp_str = lex.getString();
1230 user_defined_bullet(index).setText(temp_str);
1231 temp_bullet(index).setText(temp_str);
1235 string const BufferParams::paperSizeName() const
1237 char real_papersize = papersize;
1238 if (real_papersize == PAPER_DEFAULT)
1239 real_papersize = lyxrc.default_papersize;
1241 switch (real_papersize) {
1250 case PAPER_EXECUTIVEPAPER:
1252 case PAPER_LEGALPAPER:
1254 case PAPER_USLETTER:
1261 string const BufferParams::dvips_options() const
1266 && papersize2 == VM_PAPER_CUSTOM
1267 && !lyxrc.print_paper_dimension_flag.empty()
1268 && !paperwidth.empty()
1269 && !paperheight.empty()) {
1270 // using a custom papersize
1271 result = lyxrc.print_paper_dimension_flag;
1272 result += ' ' + paperwidth;
1273 result += ',' + paperheight;
1275 string const paper_option = paperSizeName();
1276 if (paper_option != "letter" ||
1277 orientation != ORIENTATION_LANDSCAPE) {
1278 // dvips won't accept -t letter -t landscape.
1279 // In all other cases, include the paper size
1281 result = lyxrc.print_paper_flag;
1282 result += ' ' + paper_option;
1285 if (orientation == ORIENTATION_LANDSCAPE &&
1286 papersize2 != VM_PAPER_CUSTOM)
1287 result += ' ' + lyxrc.print_landscape_flag;
1292 string const BufferParams::babelCall(string const & lang_opts) const
1294 string tmp = lyxrc.language_package;
1295 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1296 tmp = string("\\usepackage[") + lang_opts + "]{babel}";