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/tostr.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);
270 SpaceTranslator const & spacetranslator()
272 static SpaceTranslator translator = init_spacetranslator();
276 // ends annonym namespace
280 struct BufferParams::Impl
284 AuthorList authorlist;
285 BranchList branchlist;
286 boost::array<Bullet, 4> temp_bullets;
287 boost::array<Bullet, 4> user_defined_bullets;
289 /** This is the amount of space used for paragraph_separation "skip",
290 * and for detached paragraphs in "indented" documents.
296 BufferParams::Impl::Impl()
297 : defskip(VSpace::MEDSKIP)
299 // set initial author
300 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
305 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
309 return new BufferParams::Impl(*ptr);
313 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
319 BufferParams::BufferParams()
320 : // Initialize textclass to point to article. if `first' is
321 // true in the returned pair, then `second' is the textclass
322 // number; if it is false, second is 0. In both cases, second
324 textclass(textclasslist.NumberOfClass("article").second),
327 paragraph_separation = PARSEP_INDENT;
328 quotes_language = InsetQuotes::EnglishQ;
329 quotes_times = InsetQuotes::DoubleQ;
330 fontsize = "default";
333 papersize = PAPER_DEFAULT;
334 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
335 paperpackage = PACKAGE_NONE;
336 orientation = ORIENTATION_PORTRAIT;
337 use_geometry = false;
338 use_amsmath = AMS_AUTO;
339 cite_engine = biblio::ENGINE_BASIC;
340 use_bibtopic = false;
341 tracking_changes = false;
344 language = default_language;
347 graphicsDriver = "default";
348 sides = LyXTextClass::OneSide;
350 pagestyle = "default";
352 for (int iter = 0; iter < 4; ++iter) {
353 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
354 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
359 BufferParams::~BufferParams()
363 AuthorList & BufferParams::authors()
365 return pimpl_->authorlist;
369 AuthorList const & BufferParams::authors() const
371 return pimpl_->authorlist;
375 BranchList & BufferParams::branchlist()
377 return pimpl_->branchlist;
381 BranchList const & BufferParams::branchlist() const
383 return pimpl_->branchlist;
387 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
389 BOOST_ASSERT(index < 4);
390 return pimpl_->temp_bullets[index];
394 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
396 BOOST_ASSERT(index < 4);
397 return pimpl_->temp_bullets[index];
401 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
403 BOOST_ASSERT(index < 4);
404 return pimpl_->user_defined_bullets[index];
408 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
410 BOOST_ASSERT(index < 4);
411 return pimpl_->user_defined_bullets[index];
415 Spacing & BufferParams::spacing()
417 return pimpl_->spacing;
421 Spacing const & BufferParams::spacing() const
423 return pimpl_->spacing;
427 VSpace const & BufferParams::getDefSkip() const
429 return pimpl_->defskip;
433 void BufferParams::setDefSkip(VSpace const & vs)
435 pimpl_->defskip = vs;
439 string const BufferParams::readToken(LyXLex & lex, string const & token)
441 if (token == "\\textclass") {
443 string const classname = lex.getString();
444 pair<bool, lyx::textclass_type> pp =
445 textclasslist.NumberOfClass(classname);
447 textclass = pp.second;
452 if (!getLyXTextClass().isTeXClassAvailable()) {
454 bformat(_("The document uses a missing "
455 "TeX class \"%1$s\".\n"), classname);
456 Alert::warning(_("Document class not available"),
457 msg + _("LyX will not be able to produce output."));
459 } else if (token == "\\begin_preamble") {
461 } else if (token == "\\options") {
463 options = lex.getString();
464 } else if (token == "\\language") {
466 } else if (token == "\\inputencoding") {
468 } else if (token == "\\graphics") {
469 readGraphicsDriver(lex);
470 } else if (token == "\\fontscheme") {
472 } else if (token == "\\paragraph_separation") {
475 paragraph_separation = parseptranslator().find(parsep);
476 } else if (token == "\\defskip") {
478 pimpl_->defskip = VSpace(lex.getString());
479 } else if (token == "\\quotes_language") {
482 quotes_language = quoteslangtranslator().find(quotes_lang);
483 } else if (token == "\\quotes_times") {
486 quotes_times = quotestimestranslator().find(qtimes);
487 } else if (token == "\\papersize") {
490 papersize2 = papersizetranslator().find(ppsize);
491 } else if (token == "\\paperpackage") {
494 paperpackage = paperpackagestranslator().find(ppackage);
495 } else if (token == "\\use_geometry") {
497 } else if (token == "\\use_amsmath") {
500 use_amsmath = amstranslator().find(use_ams);
501 } else if (token == "\\cite_engine") {
504 cite_engine = citeenginetranslator().find(engine);
505 } else if (token == "\\use_bibtopic") {
507 } else if (token == "\\tracking_changes") {
508 lex >> tracking_changes;
509 } else if (token == "\\branch") {
511 string branch = lex.getString();
512 branchlist().add(branch);
515 string const tok = lex.getString();
516 if (tok == "\\end_branch")
518 Branch * branch_ptr = branchlist().find(branch);
519 if (tok == "\\selected") {
522 branch_ptr->setSelected(lex.getInteger());
524 // not yet operational
525 if (tok == "\\color") {
527 string color = lex.getString();
529 branch_ptr->setColor(color);
530 // Update also the LColor table:
532 color = lcolor.getX11Name(LColor::background);
533 lcolor.setColor(branch, color);
537 } else if (token == "\\author") {
539 istringstream ss(lex.getString());
542 author_map.push_back(pimpl_->authorlist.record(a));
543 } else if (token == "\\paperorientation") {
546 orientation = paperorientationtranslator().find(orient);
547 } else if (token == "\\paperwidth") {
549 } else if (token == "\\paperheight") {
551 } else if (token == "\\leftmargin") {
553 } else if (token == "\\topmargin") {
555 } else if (token == "\\rightmargin") {
557 } else if (token == "\\bottommargin") {
559 } else if (token == "\\headheight") {
561 } else if (token == "\\headsep") {
563 } else if (token == "\\footskip") {
565 } else if (token == "\\paperfontsize") {
567 } else if (token == "\\papercolumns") {
569 } else if (token == "\\papersides") {
572 sides = sidestranslator().find(psides);
573 } else if (token == "\\paperpagestyle") {
575 } else if (token == "\\bullet") {
577 } else if (token == "\\bulletLaTeX") {
578 readBulletsLaTeX(lex);
579 } else if (token == "\\secnumdepth") {
581 } else if (token == "\\tocdepth") {
583 } else if (token == "\\spacing") {
587 if (nspacing == "other") {
590 spacing().set(spacetranslator().find(nspacing), tmp_val);
591 } else if (token == "\\float_placement") {
592 lex >> float_placement;
601 void BufferParams::writeFile(ostream & os) const
603 // The top of the file is written by the buffer.
604 // Prints out the buffer info into the .lyx file given by file
607 os << "\\textclass " << textclasslist[textclass].name() << '\n';
609 // then the the preamble
610 if (!preamble.empty()) {
611 // remove '\n' from the end of preamble
612 string const tmppreamble = rtrim(preamble, "\n");
613 os << "\\begin_preamble\n"
615 << "\n\\end_preamble\n";
619 if (!options.empty()) {
620 os << "\\options " << options << '\n';
623 // then the text parameters
624 if (language != ignore_language)
625 os << "\\language " << language->lang() << '\n';
626 os << "\\inputencoding " << inputenc
627 << "\n\\fontscheme " << fonts
628 << "\n\\graphics " << graphicsDriver << '\n';
630 if (!float_placement.empty()) {
631 os << "\\float_placement " << float_placement << '\n';
633 os << "\\paperfontsize " << fontsize << '\n';
635 spacing().writeFile(os);
637 os << "\\papersize " << string_papersize[papersize2]
638 << "\n\\paperpackage " << string_paperpackages[paperpackage]
639 << "\n\\use_geometry " << tostr(use_geometry)
640 << "\n\\use_amsmath " << use_amsmath
641 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
642 << "\n\\use_bibtopic " << tostr(use_bibtopic)
643 << "\n\\paperorientation " << string_orientation[orientation]
646 std::list<Branch>::const_iterator it = branchlist().begin();
647 std::list<Branch>::const_iterator end = branchlist().end();
648 for (; it != end; ++it) {
649 os << "\\branch " << it->getBranch()
650 << "\n\\selected " << it->getSelected()
651 << "\n\\color " << it->getColor()
656 if (!paperwidth.empty())
657 os << "\\paperwidth "
658 << VSpace(paperwidth).asLyXCommand() << '\n';
659 if (!paperheight.empty())
660 os << "\\paperheight "
661 << VSpace(paperheight).asLyXCommand() << '\n';
662 if (!leftmargin.empty())
663 os << "\\leftmargin "
664 << VSpace(leftmargin).asLyXCommand() << '\n';
665 if (!topmargin.empty())
667 << VSpace(topmargin).asLyXCommand() << '\n';
668 if (!rightmargin.empty())
669 os << "\\rightmargin "
670 << VSpace(rightmargin).asLyXCommand() << '\n';
671 if (!bottommargin.empty())
672 os << "\\bottommargin "
673 << VSpace(bottommargin).asLyXCommand() << '\n';
674 if (!headheight.empty())
675 os << "\\headheight "
676 << VSpace(headheight).asLyXCommand() << '\n';
677 if (!headsep.empty())
679 << VSpace(headsep).asLyXCommand() << '\n';
680 if (!footskip.empty())
682 << VSpace(footskip).asLyXCommand() << '\n';
683 os << "\\secnumdepth " << secnumdepth
684 << "\n\\tocdepth " << tocdepth
685 << "\n\\paragraph_separation "
686 << string_paragraph_separation[paragraph_separation]
687 << "\n\\defskip " << getDefSkip().asLyXCommand()
688 << "\n\\quotes_language "
689 << string_quotes_language[quotes_language] << '\n'
691 << quotestimestranslator().find(quotes_times)
692 << "\n\\papercolumns " << columns
693 << "\n\\papersides " << sides
694 << "\n\\paperpagestyle " << pagestyle << '\n';
695 for (int i = 0; i < 4; ++i) {
696 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
697 if (user_defined_bullet(i).getFont() != -1) {
698 os << "\\bullet " << i << " "
699 << user_defined_bullet(i).getFont() << " "
700 << user_defined_bullet(i).getCharacter() << " "
701 << user_defined_bullet(i).getSize() << "\n";
704 os << "\\bulletLaTeX " << i << " \""
705 << user_defined_bullet(i).getText()
711 os << "\\tracking_changes " << tostr(tracking_changes) << "\n";
713 if (tracking_changes) {
714 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
715 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
716 for (; it != end; ++it) {
717 os << "\\author " << it->second << "\n";
723 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
724 TexRow & texrow) const
726 os << "\\documentclass";
728 LyXTextClass const & tclass = getLyXTextClass();
730 ostringstream clsoptions; // the document class options.
732 if (tokenPos(tclass.opt_fontsize(),
733 '|', fontsize) >= 0) {
734 // only write if existing in list (and not default)
735 clsoptions << fontsize << "pt,";
740 (paperpackage == PACKAGE_NONE)) {
743 clsoptions << "a3paper,";
746 clsoptions << "a4paper,";
749 clsoptions << "letterpaper,";
752 clsoptions << "a5paper,";
755 clsoptions << "b5paper,";
757 case PAPER_EXECUTIVEPAPER:
758 clsoptions << "executivepaper,";
760 case PAPER_LEGALPAPER:
761 clsoptions << "legalpaper,";
769 if (sides != tclass.sides()) {
771 case LyXTextClass::OneSide:
772 clsoptions << "oneside,";
774 case LyXTextClass::TwoSides:
775 clsoptions << "twoside,";
781 if (columns != tclass.columns()) {
783 clsoptions << "twocolumn,";
785 clsoptions << "onecolumn,";
789 && orientation == ORIENTATION_LANDSCAPE)
790 clsoptions << "landscape,";
792 // language should be a parameter to \documentclass
793 if (language->babel() == "hebrew"
794 && default_language->babel() != "hebrew")
795 // This seems necessary
796 features.useLanguage(default_language);
798 ostringstream language_options;
799 bool const use_babel = features.useBabel();
801 language_options << features.getLanguages();
802 language_options << language->babel();
803 if (lyxrc.language_global_options)
804 clsoptions << language_options.str() << ',';
807 // the user-defined options
808 if (!options.empty()) {
809 clsoptions << options << ',';
812 string strOptions(clsoptions.str());
813 if (!strOptions.empty()) {
814 strOptions = rtrim(strOptions, ",");
815 os << '[' << strOptions << ']';
818 os << '{' << tclass.latexname() << "}\n";
820 // end of \documentclass defs
822 // font selection must be done before loading fontenc.sty
823 // The ae package is not needed when using OT1 font encoding.
824 if (fonts != "default" &&
825 (fonts != "ae" || lyxrc.fontenc != "default")) {
826 os << "\\usepackage{" << fonts << "}\n";
829 os << "\\usepackage{aecompl}\n";
833 // this one is not per buffer
834 if (lyxrc.fontenc != "default") {
835 os << "\\usepackage[" << lyxrc.fontenc
840 if (inputenc == "auto") {
841 string const doc_encoding =
842 language->encoding()->LatexName();
844 // Create a list with all the input encodings used
846 std::set<string> encodings =
847 features.getEncodingSet(doc_encoding);
849 os << "\\usepackage[";
850 std::copy(encodings.begin(), encodings.end(),
851 std::ostream_iterator<string>(os, ","));
852 os << doc_encoding << "]{inputenc}\n";
854 } else if (inputenc != "default") {
855 os << "\\usepackage[" << inputenc
860 // At the very beginning the text parameters.
861 if (paperpackage != PACKAGE_NONE) {
862 switch (paperpackage) {
866 os << "\\usepackage{a4}\n";
870 os << "\\usepackage{a4wide}\n";
873 case PACKAGE_WIDEMARGINSA4:
874 os << "\\usepackage[widemargins]{a4}\n";
880 os << "\\usepackage{geometry}\n";
882 os << "\\geometry{verbose";
883 if (orientation == ORIENTATION_LANDSCAPE)
885 switch (papersize2) {
886 case VM_PAPER_CUSTOM:
887 if (!paperwidth.empty())
890 if (!paperheight.empty())
891 os << ",paperheight="
894 case VM_PAPER_USLETTER:
895 os << ",letterpaper";
897 case VM_PAPER_USLEGAL:
900 case VM_PAPER_USEXECUTIVE:
901 os << ",executivepaper";
922 // default papersize ie VM_PAPER_DEFAULT
923 switch (lyxrc.default_papersize) {
924 case PAPER_DEFAULT: // keep compiler happy
926 os << ",letterpaper";
928 case PAPER_LEGALPAPER:
931 case PAPER_EXECUTIVEPAPER:
932 os << ",executivepaper";
948 if (!topmargin.empty())
949 os << ",tmargin=" << topmargin;
950 if (!bottommargin.empty())
951 os << ",bmargin=" << bottommargin;
952 if (!leftmargin.empty())
953 os << ",lmargin=" << leftmargin;
954 if (!rightmargin.empty())
955 os << ",rmargin=" << rightmargin;
956 if (!headheight.empty())
957 os << ",headheight=" << headheight;
958 if (!headsep.empty())
959 os << ",headsep=" << headsep;
960 if (!footskip.empty())
961 os << ",footskip=" << footskip;
966 if (tokenPos(tclass.opt_pagestyle(),
967 '|', pagestyle) >= 0) {
968 if (pagestyle == "fancy") {
969 os << "\\usepackage{fancyhdr}\n";
972 os << "\\pagestyle{" << pagestyle << "}\n";
976 if (secnumdepth != tclass.secnumdepth()) {
977 os << "\\setcounter{secnumdepth}{"
982 if (tocdepth != tclass.tocdepth()) {
983 os << "\\setcounter{tocdepth}{"
989 if (paragraph_separation) {
990 switch (getDefSkip().kind()) {
991 case VSpace::SMALLSKIP:
992 os << "\\setlength\\parskip{\\smallskipamount}\n";
994 case VSpace::MEDSKIP:
995 os << "\\setlength\\parskip{\\medskipamount}\n";
997 case VSpace::BIGSKIP:
998 os << "\\setlength\\parskip{\\bigskipamount}\n";
1000 case VSpace::LENGTH:
1001 os << "\\setlength\\parskip{"
1002 << getDefSkip().length().asLatexString()
1005 default: // should never happen // Then delete it.
1006 os << "\\setlength\\parskip{\\medskipamount}\n";
1011 os << "\\setlength\\parindent{0pt}\n";
1015 // If we use jurabib, we have to call babel here.
1016 if (use_babel && features.isRequired("jurabib")) {
1017 os << babelCall(language_options.str())
1019 << features.getBabelOptions();
1023 // Now insert the LyX specific LaTeX commands...
1025 // The optional packages;
1026 string lyxpreamble(features.getPackages());
1028 // this might be useful...
1029 lyxpreamble += "\n\\makeatletter\n";
1031 // Some macros LyX will need
1032 string tmppreamble(features.getMacros());
1034 if (!tmppreamble.empty()) {
1035 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1036 "LyX specific LaTeX commands.\n"
1037 + tmppreamble + '\n';
1040 // the text class specific preamble
1041 tmppreamble = features.getTClassPreamble();
1042 if (!tmppreamble.empty()) {
1043 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1044 "Textclass specific LaTeX commands.\n"
1045 + tmppreamble + '\n';
1048 /* the user-defined preamble */
1049 if (!preamble.empty()) {
1050 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1051 "User specified LaTeX commands.\n"
1055 // Itemize bullet settings need to be last in case the user
1056 // defines their own bullets that use a package included
1057 // in the user-defined preamble -- ARRae
1058 // Actually it has to be done much later than that
1059 // since some packages like frenchb make modifications
1060 // at \begin{document} time -- JMarc
1062 for (int i = 0; i < 4; ++i) {
1063 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1064 if (bullets_def.empty())
1065 bullets_def="\\AtBeginDocument{\n";
1066 bullets_def += " \\renewcommand{\\labelitemi";
1068 // `i' is one less than the item to modify
1075 bullets_def += "ii";
1081 bullets_def += "}{" +
1082 user_defined_bullet(i).getText()
1087 if (!bullets_def.empty())
1088 lyxpreamble += bullets_def + "}\n\n";
1090 // We try to load babel late, in case it interferes
1091 // with other packages.
1092 // Jurabib has to be called after babel, though.
1093 if (use_babel && !features.isRequired("jurabib")) {
1094 lyxpreamble += babelCall(language_options.str()) + '\n';
1095 lyxpreamble += features.getBabelOptions();
1098 lyxpreamble += "\\makeatother\n";
1100 // dvipost settings come after everything else
1101 if (tracking_changes) {
1104 "\\dvipost{osstart color push Red}\n"
1105 "\\dvipost{osend color pop}\n"
1106 "\\dvipost{cbstart color push Blue}\n"
1107 "\\dvipost{cbend color pop}\n";
1111 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1112 for (int j = 0; j != nlines; ++j) {
1121 void BufferParams::setPaperStuff()
1123 papersize = PAPER_DEFAULT;
1124 char const c1 = paperpackage;
1125 if (c1 == PACKAGE_NONE) {
1126 char const c2 = papersize2;
1127 if (c2 == VM_PAPER_USLETTER)
1128 papersize = PAPER_USLETTER;
1129 else if (c2 == VM_PAPER_USLEGAL)
1130 papersize = PAPER_LEGALPAPER;
1131 else if (c2 == VM_PAPER_USEXECUTIVE)
1132 papersize = PAPER_EXECUTIVEPAPER;
1133 else if (c2 == VM_PAPER_A3)
1134 papersize = PAPER_A3PAPER;
1135 else if (c2 == VM_PAPER_A4)
1136 papersize = PAPER_A4PAPER;
1137 else if (c2 == VM_PAPER_A5)
1138 papersize = PAPER_A5PAPER;
1139 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1140 (c2 == VM_PAPER_B5))
1141 papersize = PAPER_B5PAPER;
1142 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1143 (c1 == PACKAGE_WIDEMARGINSA4))
1144 papersize = PAPER_A4PAPER;
1148 void BufferParams::useClassDefaults()
1150 LyXTextClass const & tclass = textclasslist[textclass];
1152 sides = tclass.sides();
1153 columns = tclass.columns();
1154 pagestyle = tclass.pagestyle();
1155 options = tclass.options();
1156 secnumdepth = tclass.secnumdepth();
1157 tocdepth = tclass.tocdepth();
1161 bool BufferParams::hasClassDefaults() const
1163 LyXTextClass const & tclass = textclasslist[textclass];
1165 return (sides == tclass.sides()
1166 && columns == tclass.columns()
1167 && pagestyle == tclass.pagestyle()
1168 && options == tclass.options()
1169 && secnumdepth == tclass.secnumdepth()
1170 && tocdepth == tclass.tocdepth());
1174 LyXTextClass const & BufferParams::getLyXTextClass() const
1176 return textclasslist[textclass];
1180 void BufferParams::readPreamble(LyXLex & lex)
1182 if (lex.getString() != "\\begin_preamble")
1183 lyxerr << "Error (BufferParams::readPreamble):"
1184 "consistency check failed." << endl;
1186 preamble = lex.getLongString("\\end_preamble");
1190 void BufferParams::readLanguage(LyXLex & lex)
1192 if (!lex.next()) return;
1194 string const tmptok = lex.getString();
1196 // check if tmptok is part of tex_babel in tex-defs.h
1197 language = languages.getLanguage(tmptok);
1199 // Language tmptok was not found
1200 language = default_language;
1201 lyxerr << "Warning: Setting language `"
1202 << tmptok << "' to `" << language->lang()
1208 void BufferParams::readGraphicsDriver(LyXLex & lex)
1210 if (!lex.next()) return;
1212 string const tmptok = lex.getString();
1213 // check if tmptok is part of tex_graphics in tex_defs.h
1216 string const test = tex_graphics[n++];
1218 if (test == tmptok) {
1219 graphicsDriver = tmptok;
1221 } else if (test == "last_item") {
1223 "Warning: graphics driver `$$Token' not recognized!\n"
1224 " Setting graphics driver to `default'.\n");
1225 graphicsDriver = "default";
1232 void BufferParams::readBullets(LyXLex & lex)
1234 if (!lex.next()) return;
1236 int const index = lex.getInteger();
1238 int temp_int = lex.getInteger();
1239 user_defined_bullet(index).setFont(temp_int);
1240 temp_bullet(index).setFont(temp_int);
1242 user_defined_bullet(index).setCharacter(temp_int);
1243 temp_bullet(index).setCharacter(temp_int);
1245 user_defined_bullet(index).setSize(temp_int);
1246 temp_bullet(index).setSize(temp_int);
1250 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1252 // The bullet class should be able to read this.
1253 if (!lex.next()) return;
1254 int const index = lex.getInteger();
1256 string const temp_str = lex.getString();
1258 user_defined_bullet(index).setText(temp_str);
1259 temp_bullet(index).setText(temp_str);
1263 string const BufferParams::paperSizeName() const
1265 char real_papersize = papersize;
1266 if (real_papersize == PAPER_DEFAULT)
1267 real_papersize = lyxrc.default_papersize;
1269 switch (real_papersize) {
1278 case PAPER_EXECUTIVEPAPER:
1280 case PAPER_LEGALPAPER:
1282 case PAPER_USLETTER:
1289 string const BufferParams::dvips_options() const
1294 && papersize2 == VM_PAPER_CUSTOM
1295 && !lyxrc.print_paper_dimension_flag.empty()
1296 && !paperwidth.empty()
1297 && !paperheight.empty()) {
1298 // using a custom papersize
1299 result = lyxrc.print_paper_dimension_flag;
1300 result += ' ' + paperwidth;
1301 result += ',' + paperheight;
1303 string const paper_option = paperSizeName();
1304 if (paper_option != "letter" ||
1305 orientation != ORIENTATION_LANDSCAPE) {
1306 // dvips won't accept -t letter -t landscape.
1307 // In all other cases, include the paper size
1309 result = lyxrc.print_paper_flag;
1310 result += ' ' + paper_option;
1313 if (orientation == ORIENTATION_LANDSCAPE &&
1314 papersize2 != VM_PAPER_CUSTOM)
1315 result += ' ' + lyxrc.print_landscape_flag;
1320 string const BufferParams::babelCall(string const & lang_opts) const
1322 string tmp = lyxrc.language_package;
1323 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1324 tmp = string("\\usepackage[") + lang_opts + "]{babel}";