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;
344 output_changes = false;
347 language = default_language;
350 graphicsDriver = "default";
351 sides = LyXTextClass::OneSide;
353 pagestyle = "default";
355 for (int iter = 0; iter < 4; ++iter) {
356 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
357 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
362 BufferParams::~BufferParams()
366 AuthorList & BufferParams::authors()
368 return pimpl_->authorlist;
372 AuthorList const & BufferParams::authors() const
374 return pimpl_->authorlist;
378 BranchList & BufferParams::branchlist()
380 return pimpl_->branchlist;
384 BranchList const & BufferParams::branchlist() const
386 return pimpl_->branchlist;
390 Bullet & BufferParams::temp_bullet(lyx::size_type const index)
392 BOOST_ASSERT(index < 4);
393 return pimpl_->temp_bullets[index];
397 Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const
399 BOOST_ASSERT(index < 4);
400 return pimpl_->temp_bullets[index];
404 Bullet & BufferParams::user_defined_bullet(lyx::size_type const index)
406 BOOST_ASSERT(index < 4);
407 return pimpl_->user_defined_bullets[index];
411 Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const
413 BOOST_ASSERT(index < 4);
414 return pimpl_->user_defined_bullets[index];
418 Spacing & BufferParams::spacing()
420 return pimpl_->spacing;
424 Spacing const & BufferParams::spacing() const
426 return pimpl_->spacing;
430 VSpace const & BufferParams::getDefSkip() const
432 return pimpl_->defskip;
436 void BufferParams::setDefSkip(VSpace const & vs)
438 pimpl_->defskip = vs;
442 string const BufferParams::readToken(LyXLex & lex, string const & token)
444 if (token == "\\textclass") {
446 string const classname = lex.getString();
447 pair<bool, lyx::textclass_type> pp =
448 textclasslist.NumberOfClass(classname);
450 textclass = pp.second;
455 if (!getLyXTextClass().isTeXClassAvailable()) {
457 bformat(_("The document uses a missing "
458 "TeX class \"%1$s\".\n"), classname);
459 Alert::warning(_("Document class not available"),
460 msg + _("LyX will not be able to produce output."));
462 } else if (token == "\\begin_preamble") {
464 } else if (token == "\\options") {
466 options = lex.getString();
467 } else if (token == "\\language") {
469 } else if (token == "\\inputencoding") {
471 } else if (token == "\\graphics") {
472 readGraphicsDriver(lex);
473 } else if (token == "\\fontscheme") {
475 } else if (token == "\\paragraph_separation") {
478 paragraph_separation = parseptranslator().find(parsep);
479 } else if (token == "\\defskip") {
481 pimpl_->defskip = VSpace(lex.getString());
482 } else if (token == "\\quotes_language") {
485 quotes_language = quoteslangtranslator().find(quotes_lang);
486 } else if (token == "\\quotes_times") {
489 quotes_times = quotestimestranslator().find(qtimes);
490 } else if (token == "\\papersize") {
493 papersize2 = papersizetranslator().find(ppsize);
494 } else if (token == "\\paperpackage") {
497 paperpackage = paperpackagestranslator().find(ppackage);
498 } else if (token == "\\use_geometry") {
500 } else if (token == "\\use_amsmath") {
503 use_amsmath = amstranslator().find(use_ams);
504 } else if (token == "\\cite_engine") {
507 cite_engine = citeenginetranslator().find(engine);
508 } else if (token == "\\use_bibtopic") {
510 } else if (token == "\\tracking_changes") {
511 lex >> tracking_changes;
512 } else if (token == "\\output_changes") {
513 lex >> output_changes;
514 } else if (token == "\\branch") {
516 string branch = lex.getString();
517 branchlist().add(branch);
520 string const tok = lex.getString();
521 if (tok == "\\end_branch")
523 Branch * branch_ptr = branchlist().find(branch);
524 if (tok == "\\selected") {
527 branch_ptr->setSelected(lex.getInteger());
529 // not yet operational
530 if (tok == "\\color") {
532 string color = lex.getString();
534 branch_ptr->setColor(color);
535 // Update also the LColor table:
537 color = lcolor.getX11Name(LColor::background);
538 lcolor.setColor(branch, color);
542 } else if (token == "\\author") {
544 istringstream ss(lex.getString());
547 author_map.push_back(pimpl_->authorlist.record(a));
548 } else if (token == "\\paperorientation") {
551 orientation = paperorientationtranslator().find(orient);
552 } else if (token == "\\paperwidth") {
554 } else if (token == "\\paperheight") {
556 } else if (token == "\\leftmargin") {
558 } else if (token == "\\topmargin") {
560 } else if (token == "\\rightmargin") {
562 } else if (token == "\\bottommargin") {
564 } else if (token == "\\headheight") {
566 } else if (token == "\\headsep") {
568 } else if (token == "\\footskip") {
570 } else if (token == "\\paperfontsize") {
572 } else if (token == "\\papercolumns") {
574 } else if (token == "\\papersides") {
577 sides = sidestranslator().find(psides);
578 } else if (token == "\\paperpagestyle") {
580 } else if (token == "\\bullet") {
582 } else if (token == "\\bulletLaTeX") {
583 readBulletsLaTeX(lex);
584 } else if (token == "\\secnumdepth") {
586 } else if (token == "\\tocdepth") {
588 } else if (token == "\\spacing") {
592 if (nspacing == "other") {
595 spacing().set(spacetranslator().find(nspacing), tmp_val);
596 } else if (token == "\\float_placement") {
597 lex >> float_placement;
606 void BufferParams::writeFile(ostream & os) const
608 // The top of the file is written by the buffer.
609 // Prints out the buffer info into the .lyx file given by file
612 os << "\\textclass " << textclasslist[textclass].name() << '\n';
614 // then the the preamble
615 if (!preamble.empty()) {
616 // remove '\n' from the end of preamble
617 string const tmppreamble = rtrim(preamble, "\n");
618 os << "\\begin_preamble\n"
620 << "\n\\end_preamble\n";
624 if (!options.empty()) {
625 os << "\\options " << options << '\n';
628 // then the text parameters
629 if (language != ignore_language)
630 os << "\\language " << language->lang() << '\n';
631 os << "\\inputencoding " << inputenc
632 << "\n\\fontscheme " << fonts
633 << "\n\\graphics " << graphicsDriver << '\n';
635 if (!float_placement.empty()) {
636 os << "\\float_placement " << float_placement << '\n';
638 os << "\\paperfontsize " << fontsize << '\n';
640 spacing().writeFile(os);
642 os << "\\papersize " << string_papersize[papersize2]
643 << "\n\\paperpackage " << string_paperpackages[paperpackage]
644 << "\n\\use_geometry " << convert<string>(use_geometry)
645 << "\n\\use_amsmath " << use_amsmath
646 << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
647 << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
648 << "\n\\paperorientation " << string_orientation[orientation]
651 std::list<Branch>::const_iterator it = branchlist().begin();
652 std::list<Branch>::const_iterator end = branchlist().end();
653 for (; it != end; ++it) {
654 os << "\\branch " << it->getBranch()
655 << "\n\\selected " << it->getSelected()
656 << "\n\\color " << it->getColor()
661 if (!paperwidth.empty())
662 os << "\\paperwidth "
663 << VSpace(paperwidth).asLyXCommand() << '\n';
664 if (!paperheight.empty())
665 os << "\\paperheight "
666 << VSpace(paperheight).asLyXCommand() << '\n';
667 if (!leftmargin.empty())
668 os << "\\leftmargin "
669 << VSpace(leftmargin).asLyXCommand() << '\n';
670 if (!topmargin.empty())
672 << VSpace(topmargin).asLyXCommand() << '\n';
673 if (!rightmargin.empty())
674 os << "\\rightmargin "
675 << VSpace(rightmargin).asLyXCommand() << '\n';
676 if (!bottommargin.empty())
677 os << "\\bottommargin "
678 << VSpace(bottommargin).asLyXCommand() << '\n';
679 if (!headheight.empty())
680 os << "\\headheight "
681 << VSpace(headheight).asLyXCommand() << '\n';
682 if (!headsep.empty())
684 << VSpace(headsep).asLyXCommand() << '\n';
685 if (!footskip.empty())
687 << VSpace(footskip).asLyXCommand() << '\n';
688 os << "\\secnumdepth " << secnumdepth
689 << "\n\\tocdepth " << tocdepth
690 << "\n\\paragraph_separation "
691 << string_paragraph_separation[paragraph_separation]
692 << "\n\\defskip " << getDefSkip().asLyXCommand()
693 << "\n\\quotes_language "
694 << string_quotes_language[quotes_language] << '\n'
696 << quotestimestranslator().find(quotes_times)
697 << "\n\\papercolumns " << columns
698 << "\n\\papersides " << sides
699 << "\n\\paperpagestyle " << pagestyle << '\n';
700 for (int i = 0; i < 4; ++i) {
701 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
702 if (user_defined_bullet(i).getFont() != -1) {
703 os << "\\bullet " << i << " "
704 << user_defined_bullet(i).getFont() << " "
705 << user_defined_bullet(i).getCharacter() << " "
706 << user_defined_bullet(i).getSize() << "\n";
709 os << "\\bulletLaTeX " << i << " \""
710 << user_defined_bullet(i).getText()
716 os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
717 os << "\\output_changes " << convert<string>(output_changes) << "\n";
719 if (tracking_changes) {
720 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
721 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
722 for (; it != end; ++it) {
723 os << "\\author " << it->second << "\n";
729 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
730 TexRow & texrow) const
732 os << "\\documentclass";
734 LyXTextClass const & tclass = getLyXTextClass();
736 ostringstream clsoptions; // the document class options.
738 if (tokenPos(tclass.opt_fontsize(),
739 '|', fontsize) >= 0) {
740 // only write if existing in list (and not default)
741 clsoptions << fontsize << "pt,";
746 (paperpackage == PACKAGE_NONE)) {
749 clsoptions << "a3paper,";
752 clsoptions << "a4paper,";
755 clsoptions << "letterpaper,";
758 clsoptions << "a5paper,";
761 clsoptions << "b5paper,";
763 case PAPER_EXECUTIVEPAPER:
764 clsoptions << "executivepaper,";
766 case PAPER_LEGALPAPER:
767 clsoptions << "legalpaper,";
775 if (sides != tclass.sides()) {
777 case LyXTextClass::OneSide:
778 clsoptions << "oneside,";
780 case LyXTextClass::TwoSides:
781 clsoptions << "twoside,";
787 if (columns != tclass.columns()) {
789 clsoptions << "twocolumn,";
791 clsoptions << "onecolumn,";
795 && orientation == ORIENTATION_LANDSCAPE)
796 clsoptions << "landscape,";
798 // language should be a parameter to \documentclass
799 if (language->babel() == "hebrew"
800 && default_language->babel() != "hebrew")
801 // This seems necessary
802 features.useLanguage(default_language);
804 ostringstream language_options;
805 bool const use_babel = features.useBabel();
807 language_options << features.getLanguages();
808 language_options << language->babel();
809 if (lyxrc.language_global_options)
810 clsoptions << language_options.str() << ',';
813 // the user-defined options
814 if (!options.empty()) {
815 clsoptions << options << ',';
818 string strOptions(clsoptions.str());
819 if (!strOptions.empty()) {
820 strOptions = rtrim(strOptions, ",");
821 os << '[' << strOptions << ']';
824 os << '{' << tclass.latexname() << "}\n";
826 // end of \documentclass defs
828 // font selection must be done before loading fontenc.sty
829 // The ae package is not needed when using OT1 font encoding.
830 if (fonts != "default" &&
831 (fonts != "ae" || lyxrc.fontenc != "default")) {
832 os << "\\usepackage{" << fonts << "}\n";
835 os << "\\usepackage{aecompl}\n";
839 // this one is not per buffer
840 if (lyxrc.fontenc != "default") {
841 os << "\\usepackage[" << lyxrc.fontenc
846 if (inputenc == "auto") {
847 string const doc_encoding =
848 language->encoding()->LatexName();
850 // Create a list with all the input encodings used
852 std::set<string> encodings =
853 features.getEncodingSet(doc_encoding);
855 os << "\\usepackage[";
856 std::copy(encodings.begin(), encodings.end(),
857 std::ostream_iterator<string>(os, ","));
858 os << doc_encoding << "]{inputenc}\n";
860 } else if (inputenc != "default") {
861 os << "\\usepackage[" << inputenc
866 // At the very beginning the text parameters.
867 if (paperpackage != PACKAGE_NONE) {
868 switch (paperpackage) {
872 os << "\\usepackage{a4}\n";
876 os << "\\usepackage{a4wide}\n";
879 case PACKAGE_WIDEMARGINSA4:
880 os << "\\usepackage[widemargins]{a4}\n";
886 os << "\\usepackage{geometry}\n";
888 os << "\\geometry{verbose";
889 if (orientation == ORIENTATION_LANDSCAPE)
891 switch (papersize2) {
892 case VM_PAPER_CUSTOM:
893 if (!paperwidth.empty())
896 if (!paperheight.empty())
897 os << ",paperheight="
900 case VM_PAPER_USLETTER:
901 os << ",letterpaper";
903 case VM_PAPER_USLEGAL:
906 case VM_PAPER_USEXECUTIVE:
907 os << ",executivepaper";
928 // default papersize ie VM_PAPER_DEFAULT
929 switch (lyxrc.default_papersize) {
930 case PAPER_DEFAULT: // keep compiler happy
932 os << ",letterpaper";
934 case PAPER_LEGALPAPER:
937 case PAPER_EXECUTIVEPAPER:
938 os << ",executivepaper";
954 if (!topmargin.empty())
955 os << ",tmargin=" << topmargin;
956 if (!bottommargin.empty())
957 os << ",bmargin=" << bottommargin;
958 if (!leftmargin.empty())
959 os << ",lmargin=" << leftmargin;
960 if (!rightmargin.empty())
961 os << ",rmargin=" << rightmargin;
962 if (!headheight.empty())
963 os << ",headheight=" << headheight;
964 if (!headsep.empty())
965 os << ",headsep=" << headsep;
966 if (!footskip.empty())
967 os << ",footskip=" << footskip;
972 if (tokenPos(tclass.opt_pagestyle(),
973 '|', pagestyle) >= 0) {
974 if (pagestyle == "fancy") {
975 os << "\\usepackage{fancyhdr}\n";
978 os << "\\pagestyle{" << pagestyle << "}\n";
982 if (secnumdepth != tclass.secnumdepth()) {
983 os << "\\setcounter{secnumdepth}{"
988 if (tocdepth != tclass.tocdepth()) {
989 os << "\\setcounter{tocdepth}{"
995 if (paragraph_separation) {
996 switch (getDefSkip().kind()) {
997 case VSpace::SMALLSKIP:
998 os << "\\setlength\\parskip{\\smallskipamount}\n";
1000 case VSpace::MEDSKIP:
1001 os << "\\setlength\\parskip{\\medskipamount}\n";
1003 case VSpace::BIGSKIP:
1004 os << "\\setlength\\parskip{\\bigskipamount}\n";
1006 case VSpace::LENGTH:
1007 os << "\\setlength\\parskip{"
1008 << getDefSkip().length().asLatexString()
1011 default: // should never happen // Then delete it.
1012 os << "\\setlength\\parskip{\\medskipamount}\n";
1017 os << "\\setlength\\parindent{0pt}\n";
1021 // If we use jurabib, we have to call babel here.
1022 if (use_babel && features.isRequired("jurabib")) {
1023 os << babelCall(language_options.str())
1025 << features.getBabelOptions();
1029 // Now insert the LyX specific LaTeX commands...
1031 // The optional packages;
1032 string lyxpreamble(features.getPackages());
1034 // this might be useful...
1035 lyxpreamble += "\n\\makeatletter\n";
1037 // Some macros LyX will need
1038 string tmppreamble(features.getMacros());
1040 if (!tmppreamble.empty()) {
1041 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1042 "LyX specific LaTeX commands.\n"
1043 + tmppreamble + '\n';
1046 // the text class specific preamble
1047 tmppreamble = features.getTClassPreamble();
1048 if (!tmppreamble.empty()) {
1049 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1050 "Textclass specific LaTeX commands.\n"
1051 + tmppreamble + '\n';
1054 /* the user-defined preamble */
1055 if (!preamble.empty()) {
1056 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
1057 "User specified LaTeX commands.\n"
1061 // Itemize bullet settings need to be last in case the user
1062 // defines their own bullets that use a package included
1063 // in the user-defined preamble -- ARRae
1064 // Actually it has to be done much later than that
1065 // since some packages like frenchb make modifications
1066 // at \begin{document} time -- JMarc
1068 for (int i = 0; i < 4; ++i) {
1069 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1070 if (bullets_def.empty())
1071 bullets_def="\\AtBeginDocument{\n";
1072 bullets_def += " \\renewcommand{\\labelitemi";
1074 // `i' is one less than the item to modify
1081 bullets_def += "ii";
1087 bullets_def += "}{" +
1088 user_defined_bullet(i).getText()
1093 if (!bullets_def.empty())
1094 lyxpreamble += bullets_def + "}\n\n";
1096 // We try to load babel late, in case it interferes
1097 // with other packages.
1098 // Jurabib has to be called after babel, though.
1099 if (use_babel && !features.isRequired("jurabib")) {
1100 lyxpreamble += babelCall(language_options.str()) + '\n';
1101 lyxpreamble += features.getBabelOptions();
1104 lyxpreamble += "\\makeatother\n";
1106 // dvipost settings come after everything else
1107 if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
1110 "\\dvipost{osstart color push Red}\n"
1111 "\\dvipost{osend color pop}\n"
1112 "\\dvipost{cbstart color push Blue}\n"
1113 "\\dvipost{cbend color pop}\n";
1117 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1118 for (int j = 0; j != nlines; ++j) {
1127 void BufferParams::setPaperStuff()
1129 papersize = PAPER_DEFAULT;
1130 char const c1 = paperpackage;
1131 if (c1 == PACKAGE_NONE) {
1132 char const c2 = papersize2;
1133 if (c2 == VM_PAPER_USLETTER)
1134 papersize = PAPER_USLETTER;
1135 else if (c2 == VM_PAPER_USLEGAL)
1136 papersize = PAPER_LEGALPAPER;
1137 else if (c2 == VM_PAPER_USEXECUTIVE)
1138 papersize = PAPER_EXECUTIVEPAPER;
1139 else if (c2 == VM_PAPER_A3)
1140 papersize = PAPER_A3PAPER;
1141 else if (c2 == VM_PAPER_A4)
1142 papersize = PAPER_A4PAPER;
1143 else if (c2 == VM_PAPER_A5)
1144 papersize = PAPER_A5PAPER;
1145 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1146 (c2 == VM_PAPER_B5))
1147 papersize = PAPER_B5PAPER;
1148 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1149 (c1 == PACKAGE_WIDEMARGINSA4))
1150 papersize = PAPER_A4PAPER;
1154 void BufferParams::useClassDefaults()
1156 LyXTextClass const & tclass = textclasslist[textclass];
1158 sides = tclass.sides();
1159 columns = tclass.columns();
1160 pagestyle = tclass.pagestyle();
1161 options = tclass.options();
1162 secnumdepth = tclass.secnumdepth();
1163 tocdepth = tclass.tocdepth();
1167 bool BufferParams::hasClassDefaults() const
1169 LyXTextClass const & tclass = textclasslist[textclass];
1171 return (sides == tclass.sides()
1172 && columns == tclass.columns()
1173 && pagestyle == tclass.pagestyle()
1174 && options == tclass.options()
1175 && secnumdepth == tclass.secnumdepth()
1176 && tocdepth == tclass.tocdepth());
1180 LyXTextClass const & BufferParams::getLyXTextClass() const
1182 return textclasslist[textclass];
1186 void BufferParams::readPreamble(LyXLex & lex)
1188 if (lex.getString() != "\\begin_preamble")
1189 lyxerr << "Error (BufferParams::readPreamble):"
1190 "consistency check failed." << endl;
1192 preamble = lex.getLongString("\\end_preamble");
1196 void BufferParams::readLanguage(LyXLex & lex)
1198 if (!lex.next()) return;
1200 string const tmptok = lex.getString();
1202 // check if tmptok is part of tex_babel in tex-defs.h
1203 language = languages.getLanguage(tmptok);
1205 // Language tmptok was not found
1206 language = default_language;
1207 lyxerr << "Warning: Setting language `"
1208 << tmptok << "' to `" << language->lang()
1214 void BufferParams::readGraphicsDriver(LyXLex & lex)
1216 if (!lex.next()) return;
1218 string const tmptok = lex.getString();
1219 // check if tmptok is part of tex_graphics in tex_defs.h
1222 string const test = tex_graphics[n++];
1224 if (test == tmptok) {
1225 graphicsDriver = tmptok;
1227 } else if (test == "last_item") {
1229 "Warning: graphics driver `$$Token' not recognized!\n"
1230 " Setting graphics driver to `default'.\n");
1231 graphicsDriver = "default";
1238 void BufferParams::readBullets(LyXLex & lex)
1240 if (!lex.next()) return;
1242 int const index = lex.getInteger();
1244 int temp_int = lex.getInteger();
1245 user_defined_bullet(index).setFont(temp_int);
1246 temp_bullet(index).setFont(temp_int);
1248 user_defined_bullet(index).setCharacter(temp_int);
1249 temp_bullet(index).setCharacter(temp_int);
1251 user_defined_bullet(index).setSize(temp_int);
1252 temp_bullet(index).setSize(temp_int);
1256 void BufferParams::readBulletsLaTeX(LyXLex & lex)
1258 // The bullet class should be able to read this.
1259 if (!lex.next()) return;
1260 int const index = lex.getInteger();
1262 string const temp_str = lex.getString();
1264 user_defined_bullet(index).setText(temp_str);
1265 temp_bullet(index).setText(temp_str);
1269 string const BufferParams::paperSizeName() const
1271 char real_papersize = papersize;
1272 if (real_papersize == PAPER_DEFAULT)
1273 real_papersize = lyxrc.default_papersize;
1275 switch (real_papersize) {
1284 case PAPER_EXECUTIVEPAPER:
1286 case PAPER_LEGALPAPER:
1288 case PAPER_USLETTER:
1295 string const BufferParams::dvips_options() const
1300 && papersize2 == VM_PAPER_CUSTOM
1301 && !lyxrc.print_paper_dimension_flag.empty()
1302 && !paperwidth.empty()
1303 && !paperheight.empty()) {
1304 // using a custom papersize
1305 result = lyxrc.print_paper_dimension_flag;
1306 result += ' ' + paperwidth;
1307 result += ',' + paperheight;
1309 string const paper_option = paperSizeName();
1310 if (paper_option != "letter" ||
1311 orientation != ORIENTATION_LANDSCAPE) {
1312 // dvips won't accept -t letter -t landscape.
1313 // In all other cases, include the paper size
1315 result = lyxrc.print_paper_flag;
1316 result += ' ' + paper_option;
1319 if (orientation == ORIENTATION_LANDSCAPE &&
1320 papersize2 != VM_PAPER_CUSTOM)
1321 result += ' ' + lyxrc.print_landscape_flag;
1326 string const BufferParams::babelCall(string const & lang_opts) const
1328 string tmp = lyxrc.language_package;
1329 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1330 tmp = string("\\usepackage[") + lang_opts + "]{babel}";