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
42 #include <boost/array.hpp>
46 namespace support = lyx::support;
47 using lyx::support::bformat;
48 using lyx::support::rtrim;
49 using lyx::support::tokenPos;
53 using std::istringstream;
55 using std::ostringstream;
58 namespace biblio = lyx::biblio;
63 int findToken(char const * const str[], string const search_token)
67 if (search_token != "default") {
68 while (str[i][0] && str[i] != search_token) {
72 lyxerr << "Unknown argument: '"
73 << search_token << "'\n";
84 struct BufferParams::Impl
88 AuthorList authorlist;
89 BranchList branchlist;
90 boost::array<Bullet, 4> temp_bullets;
91 boost::array<Bullet, 4> user_defined_bullets;
93 /** This is the amount of space used for paragraph_separation "skip",
94 * and for detached paragraphs in "indented" documents.
100 BufferParams::Impl::Impl()
101 : defskip(VSpace::MEDSKIP)
103 // set initial author
104 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
109 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
111 return new BufferParams::Impl(*ptr);
115 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
121 BufferParams::BufferParams()
122 : // Initialize textclass to point to article. if `first' is
123 // true in the returned pair, then `second' is the textclass
124 // number; if it is false, second is 0. In both cases, second
126 textclass(textclasslist.NumberOfClass("article").second),
129 paragraph_separation = PARSEP_INDENT;
130 quotes_language = InsetQuotes::EnglishQ;
131 quotes_times = InsetQuotes::DoubleQ;
132 fontsize = "default";
135 papersize = PAPER_DEFAULT;
136 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
137 paperpackage = PACKAGE_NONE;
138 orientation = ORIENTATION_PORTRAIT;
139 use_geometry = false;
140 use_amsmath = AMS_AUTO;
141 cite_engine = biblio::ENGINE_BASIC;
142 use_bibtopic = false;
143 tracking_changes = false;
146 language = default_language;
149 graphicsDriver = "default";
150 sides = LyXTextClass::OneSide;
152 pagestyle = "default";
154 for (int iter = 0; iter < 4; ++iter) {
155 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
156 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
161 BufferParams::~BufferParams()
165 AuthorList & BufferParams::authors()
167 return pimpl_->authorlist;
171 AuthorList const & BufferParams::authors() const
173 return pimpl_->authorlist;
177 BranchList & BufferParams::branchlist()
179 return pimpl_->branchlist;
183 BranchList const & BufferParams::branchlist() const
185 return pimpl_->branchlist;
189 Bullet & BufferParams::temp_bullet(lyx::size_type index)
191 BOOST_ASSERT(index < 4);
192 return pimpl_->temp_bullets[index];
196 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
198 BOOST_ASSERT(index < 4);
199 return pimpl_->temp_bullets[index];
203 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
205 BOOST_ASSERT(index < 4);
206 return pimpl_->user_defined_bullets[index];
210 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
212 BOOST_ASSERT(index < 4);
213 return pimpl_->user_defined_bullets[index];
217 Spacing & BufferParams::spacing()
219 return pimpl_->spacing;
223 Spacing const & BufferParams::spacing() const
225 return pimpl_->spacing;
229 VSpace const & BufferParams::getDefSkip() const
231 return pimpl_->defskip;
235 void BufferParams::setDefSkip(VSpace const & vs)
237 pimpl_->defskip = vs;
241 string const BufferParams::readToken(LyXLex & lex, string const & token)
243 if (token == "\\textclass") {
245 string const classname = lex.getString();
246 pair<bool, lyx::textclass_type> pp =
247 textclasslist.NumberOfClass(classname);
249 textclass = pp.second;
254 if (!getLyXTextClass().isTeXClassAvailable()) {
255 string msg = bformat(_("The document uses a missing "
256 "TeX class \"%1$s\".\n"), classname);
257 Alert::warning(_("Document class not available"),
258 msg + _("LyX will not be able to produce output."));
260 } else if (token == "\\begin_preamble") {
262 } else if (token == "\\options") {
264 options = lex.getString();
265 } else if (token == "\\language") {
267 } else if (token == "\\inputencoding") {
269 inputenc = lex.getString();
270 } else if (token == "\\graphics") {
271 readGraphicsDriver(lex);
272 } else if (token == "\\fontscheme") {
274 fonts = lex.getString();
275 } else if (token == "\\paragraph_separation") {
277 int tmpret = findToken(string_paragraph_separation, lex.getString());
280 paragraph_separation =
281 static_cast<PARSEP>(tmpret);
282 } else if (token == "\\defskip") {
284 pimpl_->defskip = VSpace(lex.getString());
285 } else if (token == "\\quotes_language") {
286 // FIXME: should be params.readQuotes()
288 int tmpret = findToken(string_quotes_language, lex.getString());
291 InsetQuotes::quote_language tmpl =
292 InsetQuotes::EnglishQ;
295 tmpl = InsetQuotes::EnglishQ;
298 tmpl = InsetQuotes::SwedishQ;
301 tmpl = InsetQuotes::GermanQ;
304 tmpl = InsetQuotes::PolishQ;
307 tmpl = InsetQuotes::FrenchQ;
310 tmpl = InsetQuotes::DanishQ;
313 quotes_language = tmpl;
314 } else if (token == "\\quotes_times") {
315 // FIXME: should be params.readQuotes()
317 switch (lex.getInteger()) {
319 quotes_times = InsetQuotes::SingleQ;
322 quotes_times = InsetQuotes::DoubleQ;
325 } else if (token == "\\papersize") {
327 int tmpret = findToken(string_papersize, lex.getString());
331 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
332 } else if (token == "\\paperpackage") {
334 int tmpret = findToken(string_paperpackages, lex.getString());
337 paperpackage = PACKAGE_NONE;
339 paperpackage = PAPER_PACKAGES(tmpret);
340 } else if (token == "\\use_geometry") {
342 use_geometry = lex.getInteger();
343 } else if (token == "\\use_amsmath") {
345 use_amsmath = static_cast<AMS>(
347 } else if (token == "\\cite_engine") {
349 string const engine = lex.getString();
351 cite_engine = biblio::ENGINE_BASIC;
352 if (engine == "natbib_numerical")
353 cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
354 else if (engine == "natbib_authoryear")
355 cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
356 else if (engine == "jurabib")
357 cite_engine = biblio::ENGINE_JURABIB;
359 } else if (token == "\\use_bibtopic") {
361 use_bibtopic = lex.getInteger();
362 } else if (token == "\\tracking_changes") {
364 tracking_changes = lex.getInteger();
365 } else if (token == "\\branch") {
367 string branch = lex.getString();
368 branchlist().add(branch);
371 string const tok = lex.getString();
372 if (tok == "\\end_branch")
374 Branch * branch_ptr = branchlist().find(branch);
375 if (tok == "\\selected") {
378 branch_ptr->setSelected(lex.getInteger());
380 // not yet operational
381 if (tok == "\\color") {
383 string color = lex.getString();
385 branch_ptr->setColor(color);
386 // Update also the LColor table:
388 color = lcolor.getX11Name(LColor::background);
389 lcolor.setColor(branch, color);
393 } else if (token == "\\author") {
395 istringstream ss(lex.getString());
398 author_map.push_back(pimpl_->authorlist.record(a));
399 } else if (token == "\\paperorientation") {
401 int tmpret = findToken(string_orientation, lex.getString());
405 static_cast<PAPER_ORIENTATION>(tmpret);
406 } else if (token == "\\paperwidth") {
408 paperwidth = lex.getString();
409 } else if (token == "\\paperheight") {
411 paperheight = lex.getString();
412 } else if (token == "\\leftmargin") {
414 leftmargin = lex.getString();
415 } else if (token == "\\topmargin") {
417 topmargin = lex.getString();
418 } else if (token == "\\rightmargin") {
420 rightmargin = lex.getString();
421 } else if (token == "\\bottommargin") {
423 bottommargin = lex.getString();
424 } else if (token == "\\headheight") {
426 headheight = lex.getString();
427 } else if (token == "\\headsep") {
429 headsep = lex.getString();
430 } else if (token == "\\footskip") {
432 footskip = lex.getString();
433 } else if (token == "\\paperfontsize") {
435 fontsize = lex.getString();
436 } else if (token == "\\papercolumns") {
438 columns = lex.getInteger();
439 } else if (token == "\\papersides") {
441 switch (lex.getInteger()) {
443 case 1: sides = LyXTextClass::OneSide; break;
444 case 2: sides = LyXTextClass::TwoSides; break;
446 } else if (token == "\\paperpagestyle") {
448 pagestyle = lex.getString();
449 } else if (token == "\\bullet") {
450 // FIXME: should be params.readBullets()
452 int const index = lex.getInteger();
454 int temp_int = lex.getInteger();
455 user_defined_bullet(index).setFont(temp_int);
456 temp_bullet(index).setFont(temp_int);
458 temp_int = lex.getInteger();
459 user_defined_bullet(index).setCharacter(temp_int);
460 temp_bullet(index).setCharacter(temp_int);
462 temp_int = lex.getInteger();
463 user_defined_bullet(index).setSize(temp_int);
464 temp_bullet(index).setSize(temp_int);
465 } else if (token == "\\bulletLaTeX") {
466 // The bullet class should be able to read this.
468 int const index = lex.getInteger();
470 string temp_str = lex.getString();
472 user_defined_bullet(index).setText(temp_str);
473 temp_bullet(index).setText(temp_str);
474 } else if (token == "\\secnumdepth") {
476 secnumdepth = lex.getInteger();
477 } else if (token == "\\tocdepth") {
479 tocdepth = lex.getInteger();
480 } else if (token == "\\spacing") {
482 string const tmp = lex.getString();
483 Spacing::Space tmp_space = Spacing::Default;
485 if (tmp == "single") {
486 tmp_space = Spacing::Single;
487 } else if (tmp == "onehalf") {
488 tmp_space = Spacing::Onehalf;
489 } else if (tmp == "double") {
490 tmp_space = Spacing::Double;
491 } else if (tmp == "other") {
493 tmp_space = Spacing::Other;
494 tmp_val = lex.getFloat();
496 lex.printError("Unknown spacing token: '$$Token'");
498 spacing().set(tmp_space, tmp_val);
499 } else if (token == "\\float_placement") {
501 float_placement = lex.getString();
510 void BufferParams::writeFile(ostream & os) const
512 // The top of the file is written by the buffer.
513 // Prints out the buffer info into the .lyx file given by file
516 os << "\\textclass " << textclasslist[textclass].name() << '\n';
518 // then the the preamble
519 if (!preamble.empty()) {
520 // remove '\n' from the end of preamble
521 string const tmppreamble = rtrim(preamble, "\n");
522 os << "\\begin_preamble\n"
524 << "\n\\end_preamble\n";
528 if (!options.empty()) {
529 os << "\\options " << options << '\n';
532 /* then the text parameters */
533 if (language != ignore_language)
534 os << "\\language " << language->lang() << '\n';
535 os << "\\inputencoding " << inputenc
536 << "\n\\fontscheme " << fonts
537 << "\n\\graphics " << graphicsDriver << '\n';
539 if (!float_placement.empty()) {
540 os << "\\float_placement " << float_placement << '\n';
542 os << "\\paperfontsize " << fontsize << '\n';
544 spacing().writeFile(os);
546 string cite_engine_str = "basic";
547 switch (cite_engine) {
548 case biblio::ENGINE_BASIC:
550 case biblio::ENGINE_NATBIB_NUMERICAL:
551 cite_engine_str = "natbib_numerical";
553 case biblio::ENGINE_NATBIB_AUTHORYEAR:
554 cite_engine_str = "natbib_authoryear";
556 case biblio::ENGINE_JURABIB:
557 cite_engine_str = "jurabib";
561 os << "\\papersize " << string_papersize[papersize2]
562 << "\n\\paperpackage " << string_paperpackages[paperpackage]
563 << "\n\\use_geometry " << use_geometry
564 << "\n\\use_amsmath " << use_amsmath
565 << "\n\\cite_engine " << cite_engine_str
566 << "\n\\use_bibtopic " << use_bibtopic
567 << "\n\\paperorientation " << string_orientation[orientation]
570 std::list<Branch>::const_iterator it = branchlist().begin();
571 std::list<Branch>::const_iterator end = branchlist().end();
572 for (; it != end; ++it) {
573 os << "\\branch " << it->getBranch()
574 << "\n\\selected " << it->getSelected()
575 << "\n\\color " << it->getColor()
580 if (!paperwidth.empty())
581 os << "\\paperwidth "
582 << VSpace(paperwidth).asLyXCommand() << '\n';
583 if (!paperheight.empty())
584 os << "\\paperheight "
585 << VSpace(paperheight).asLyXCommand() << '\n';
586 if (!leftmargin.empty())
587 os << "\\leftmargin "
588 << VSpace(leftmargin).asLyXCommand() << '\n';
589 if (!topmargin.empty())
591 << VSpace(topmargin).asLyXCommand() << '\n';
592 if (!rightmargin.empty())
593 os << "\\rightmargin "
594 << VSpace(rightmargin).asLyXCommand() << '\n';
595 if (!bottommargin.empty())
596 os << "\\bottommargin "
597 << VSpace(bottommargin).asLyXCommand() << '\n';
598 if (!headheight.empty())
599 os << "\\headheight "
600 << VSpace(headheight).asLyXCommand() << '\n';
601 if (!headsep.empty())
603 << VSpace(headsep).asLyXCommand() << '\n';
604 if (!footskip.empty())
606 << VSpace(footskip).asLyXCommand() << '\n';
607 os << "\\secnumdepth " << secnumdepth
608 << "\n\\tocdepth " << tocdepth
609 << "\n\\paragraph_separation "
610 << string_paragraph_separation[paragraph_separation]
611 << "\n\\defskip " << getDefSkip().asLyXCommand()
612 << "\n\\quotes_language "
613 << string_quotes_language[quotes_language] << '\n';
614 switch (quotes_times) {
615 // An output operator for insetquotes would be nice
616 case InsetQuotes::SingleQ:
617 os << "\\quotes_times 1\n"; break;
618 case InsetQuotes::DoubleQ:
619 os << "\\quotes_times 2\n"; break;
621 os << "\\papercolumns " << columns
622 << "\n\\papersides " << sides
623 << "\n\\paperpagestyle " << pagestyle << '\n';
624 for (int i = 0; i < 4; ++i) {
625 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
626 if (user_defined_bullet(i).getFont() != -1) {
627 os << "\\bullet " << i << " "
628 << user_defined_bullet(i).getFont() << " "
629 << user_defined_bullet(i).getCharacter() << " "
630 << user_defined_bullet(i).getSize() << "\n";
633 os << "\\bulletLaTeX " << i << " \""
634 << user_defined_bullet(i).getText()
640 os << "\\tracking_changes " << tracking_changes << "\n";
642 if (tracking_changes) {
643 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
644 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
645 for (; it != end; ++it) {
646 os << "\\author " << it->second << "\n";
652 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
653 TexRow & texrow) const
655 os << "\\documentclass";
657 LyXTextClass const & tclass = getLyXTextClass();
659 ostringstream clsoptions; // the document class options.
661 if (tokenPos(tclass.opt_fontsize(),
662 '|', fontsize) >= 0) {
663 // only write if existing in list (and not default)
664 clsoptions << fontsize << "pt,";
669 (paperpackage == PACKAGE_NONE)) {
672 clsoptions << "a3paper,";
675 clsoptions << "a4paper,";
678 clsoptions << "letterpaper,";
681 clsoptions << "a5paper,";
684 clsoptions << "b5paper,";
686 case PAPER_EXECUTIVEPAPER:
687 clsoptions << "executivepaper,";
689 case PAPER_LEGALPAPER:
690 clsoptions << "legalpaper,";
698 if (sides != tclass.sides()) {
700 case LyXTextClass::OneSide:
701 clsoptions << "oneside,";
703 case LyXTextClass::TwoSides:
704 clsoptions << "twoside,";
710 if (columns != tclass.columns()) {
712 clsoptions << "twocolumn,";
714 clsoptions << "onecolumn,";
718 && orientation == ORIENTATION_LANDSCAPE)
719 clsoptions << "landscape,";
721 // language should be a parameter to \documentclass
722 if (language->babel() == "hebrew"
723 && default_language->babel() != "hebrew")
724 // This seems necessary
725 features.useLanguage(default_language);
727 ostringstream language_options;
728 bool const use_babel = features.useBabel();
730 language_options << features.getLanguages();
731 language_options << language->babel();
732 if (lyxrc.language_global_options)
733 clsoptions << language_options.str() << ',';
736 // the user-defined options
737 if (!options.empty()) {
738 clsoptions << options << ',';
741 string strOptions(clsoptions.str());
742 if (!strOptions.empty()) {
743 strOptions = rtrim(strOptions, ",");
744 os << '[' << strOptions << ']';
747 os << '{' << tclass.latexname() << "}\n";
749 // end of \documentclass defs
751 // font selection must be done before loading fontenc.sty
752 // The ae package is not needed when using OT1 font encoding.
753 if (fonts != "default" &&
754 (fonts != "ae" || lyxrc.fontenc != "default")) {
755 os << "\\usepackage{" << fonts << "}\n";
758 os << "\\usepackage{aecompl}\n";
762 // this one is not per buffer
763 if (lyxrc.fontenc != "default") {
764 os << "\\usepackage[" << lyxrc.fontenc
769 if (inputenc == "auto") {
770 string const doc_encoding =
771 language->encoding()->LatexName();
773 // Create a list with all the input encodings used
775 std::set<string> encodings =
776 features.getEncodingSet(doc_encoding);
778 os << "\\usepackage[";
779 std::copy(encodings.begin(), encodings.end(),
780 std::ostream_iterator<string>(os, ","));
781 os << doc_encoding << "]{inputenc}\n";
783 } else if (inputenc != "default") {
784 os << "\\usepackage[" << inputenc
789 // At the very beginning the text parameters.
790 if (paperpackage != PACKAGE_NONE) {
791 switch (paperpackage) {
795 os << "\\usepackage{a4}\n";
799 os << "\\usepackage{a4wide}\n";
802 case PACKAGE_WIDEMARGINSA4:
803 os << "\\usepackage[widemargins]{a4}\n";
809 os << "\\usepackage{geometry}\n";
811 os << "\\geometry{verbose";
812 if (orientation == ORIENTATION_LANDSCAPE)
814 switch (papersize2) {
815 case VM_PAPER_CUSTOM:
816 if (!paperwidth.empty())
819 if (!paperheight.empty())
820 os << ",paperheight="
823 case VM_PAPER_USLETTER:
824 os << ",letterpaper";
826 case VM_PAPER_USLEGAL:
829 case VM_PAPER_USEXECUTIVE:
830 os << ",executivepaper";
851 // default papersize ie VM_PAPER_DEFAULT
852 switch (lyxrc.default_papersize) {
853 case PAPER_DEFAULT: // keep compiler happy
855 os << ",letterpaper";
857 case PAPER_LEGALPAPER:
860 case PAPER_EXECUTIVEPAPER:
861 os << ",executivepaper";
877 if (!topmargin.empty())
878 os << ",tmargin=" << topmargin;
879 if (!bottommargin.empty())
880 os << ",bmargin=" << bottommargin;
881 if (!leftmargin.empty())
882 os << ",lmargin=" << leftmargin;
883 if (!rightmargin.empty())
884 os << ",rmargin=" << rightmargin;
885 if (!headheight.empty())
886 os << ",headheight=" << headheight;
887 if (!headsep.empty())
888 os << ",headsep=" << headsep;
889 if (!footskip.empty())
890 os << ",footskip=" << footskip;
895 if (tokenPos(tclass.opt_pagestyle(),
896 '|', pagestyle) >= 0) {
897 if (pagestyle == "fancy") {
898 os << "\\usepackage{fancyhdr}\n";
901 os << "\\pagestyle{" << pagestyle << "}\n";
905 if (secnumdepth != tclass.secnumdepth()) {
906 os << "\\setcounter{secnumdepth}{"
911 if (tocdepth != tclass.tocdepth()) {
912 os << "\\setcounter{tocdepth}{"
918 if (paragraph_separation) {
919 switch (getDefSkip().kind()) {
920 case VSpace::SMALLSKIP:
921 os << "\\setlength\\parskip{\\smallskipamount}\n";
923 case VSpace::MEDSKIP:
924 os << "\\setlength\\parskip{\\medskipamount}\n";
926 case VSpace::BIGSKIP:
927 os << "\\setlength\\parskip{\\bigskipamount}\n";
930 os << "\\setlength\\parskip{"
931 << getDefSkip().length().asLatexString()
934 default: // should never happen // Then delete it.
935 os << "\\setlength\\parskip{\\medskipamount}\n";
940 os << "\\setlength\\parindent{0pt}\n";
944 // If we use jurabib, we have to call babel here.
945 if (use_babel && features.isRequired("jurabib")) {
946 os << babelCall(language_options.str())
948 << features.getBabelOptions();
952 // Now insert the LyX specific LaTeX commands...
954 // The optional packages;
955 string lyxpreamble(features.getPackages());
957 // this might be useful...
958 lyxpreamble += "\n\\makeatletter\n";
960 // Some macros LyX will need
961 string tmppreamble(features.getMacros());
963 if (!tmppreamble.empty()) {
964 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
965 "LyX specific LaTeX commands.\n"
966 + tmppreamble + '\n';
969 // the text class specific preamble
970 tmppreamble = features.getTClassPreamble();
971 if (!tmppreamble.empty()) {
972 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
973 "Textclass specific LaTeX commands.\n"
974 + tmppreamble + '\n';
977 /* the user-defined preamble */
978 if (!preamble.empty()) {
979 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
980 "User specified LaTeX commands.\n"
984 // Itemize bullet settings need to be last in case the user
985 // defines their own bullets that use a package included
986 // in the user-defined preamble -- ARRae
987 // Actually it has to be done much later than that
988 // since some packages like frenchb make modifications
989 // at \begin{document} time -- JMarc
991 for (int i = 0; i < 4; ++i) {
992 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
993 if (bullets_def.empty())
994 bullets_def="\\AtBeginDocument{\n";
995 bullets_def += " \\renewcommand{\\labelitemi";
997 // `i' is one less than the item to modify
1004 bullets_def += "ii";
1010 bullets_def += "}{" +
1011 user_defined_bullet(i).getText()
1016 if (!bullets_def.empty())
1017 lyxpreamble += bullets_def + "}\n\n";
1019 // We try to load babel late, in case it interferes
1020 // with other packages.
1021 // Jurabib has to be called after babel, though.
1022 if (use_babel && !features.isRequired("jurabib")) {
1023 lyxpreamble += babelCall(language_options.str()) + '\n';
1024 lyxpreamble += features.getBabelOptions();
1027 lyxpreamble += "\\makeatother\n";
1029 // dvipost settings come after everything else
1030 if (tracking_changes) {
1033 "\\dvipost{osstart color push Red}\n"
1034 "\\dvipost{osend color pop}\n"
1035 "\\dvipost{cbstart color push Blue}\n"
1036 "\\dvipost{cbend color pop}\n";
1040 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1041 for (int j = 0; j != nlines; ++j) {
1049 void BufferParams::setPaperStuff()
1051 papersize = PAPER_DEFAULT;
1052 char const c1 = paperpackage;
1053 if (c1 == PACKAGE_NONE) {
1054 char const c2 = papersize2;
1055 if (c2 == VM_PAPER_USLETTER)
1056 papersize = PAPER_USLETTER;
1057 else if (c2 == VM_PAPER_USLEGAL)
1058 papersize = PAPER_LEGALPAPER;
1059 else if (c2 == VM_PAPER_USEXECUTIVE)
1060 papersize = PAPER_EXECUTIVEPAPER;
1061 else if (c2 == VM_PAPER_A3)
1062 papersize = PAPER_A3PAPER;
1063 else if (c2 == VM_PAPER_A4)
1064 papersize = PAPER_A4PAPER;
1065 else if (c2 == VM_PAPER_A5)
1066 papersize = PAPER_A5PAPER;
1067 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1068 (c2 == VM_PAPER_B5))
1069 papersize = PAPER_B5PAPER;
1070 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1071 (c1 == PACKAGE_WIDEMARGINSA4))
1072 papersize = PAPER_A4PAPER;
1076 void BufferParams::useClassDefaults()
1078 LyXTextClass const & tclass = textclasslist[textclass];
1080 sides = tclass.sides();
1081 columns = tclass.columns();
1082 pagestyle = tclass.pagestyle();
1083 options = tclass.options();
1084 secnumdepth = tclass.secnumdepth();
1085 tocdepth = tclass.tocdepth();
1089 bool BufferParams::hasClassDefaults() const
1091 LyXTextClass const & tclass = textclasslist[textclass];
1093 return (sides == tclass.sides()
1094 && columns == tclass.columns()
1095 && pagestyle == tclass.pagestyle()
1096 && options == tclass.options()
1097 && secnumdepth == tclass.secnumdepth()
1098 && tocdepth == tclass.tocdepth());
1102 LyXTextClass const & BufferParams::getLyXTextClass() const
1104 return textclasslist[textclass];
1108 void BufferParams::readPreamble(LyXLex & lex)
1110 if (lex.getString() != "\\begin_preamble")
1111 lyxerr << "Error (BufferParams::readPreamble):"
1112 "consistency check failed." << endl;
1114 preamble = lex.getLongString("\\end_preamble");
1118 void BufferParams::readLanguage(LyXLex & lex)
1120 if (!lex.next()) return;
1122 string const tmptok = lex.getString();
1124 // check if tmptok is part of tex_babel in tex-defs.h
1125 language = languages.getLanguage(tmptok);
1127 // Language tmptok was not found
1128 language = default_language;
1129 lyxerr << "Warning: Setting language `"
1130 << tmptok << "' to `" << language->lang()
1136 void BufferParams::readGraphicsDriver(LyXLex & lex)
1138 if (!lex.next()) return;
1140 string const tmptok = lex.getString();
1141 // check if tmptok is part of tex_graphics in tex_defs.h
1144 string const test = tex_graphics[n++];
1146 if (test == tmptok) {
1147 graphicsDriver = tmptok;
1149 } else if (test == "last_item") {
1151 "Warning: graphics driver `$$Token' not recognized!\n"
1152 " Setting graphics driver to `default'.\n");
1153 graphicsDriver = "default";
1160 string const BufferParams::paperSizeName() const
1162 char real_papersize = papersize;
1163 if (real_papersize == PAPER_DEFAULT)
1164 real_papersize = lyxrc.default_papersize;
1166 switch (real_papersize) {
1175 case PAPER_EXECUTIVEPAPER:
1177 case PAPER_LEGALPAPER:
1179 case PAPER_USLETTER:
1186 string const BufferParams::dvips_options() const
1191 && papersize2 == VM_PAPER_CUSTOM
1192 && !lyxrc.print_paper_dimension_flag.empty()
1193 && !paperwidth.empty()
1194 && !paperheight.empty()) {
1195 // using a custom papersize
1196 result = lyxrc.print_paper_dimension_flag;
1197 result += ' ' + paperwidth;
1198 result += ',' + paperheight;
1200 string const paper_option = paperSizeName();
1201 if (paper_option != "letter" ||
1202 orientation != ORIENTATION_LANDSCAPE) {
1203 // dvips won't accept -t letter -t landscape.
1204 // In all other cases, include the paper size
1206 result = lyxrc.print_paper_flag;
1207 result += ' ' + paper_option;
1210 if (orientation == ORIENTATION_LANDSCAPE &&
1211 papersize2 != VM_PAPER_CUSTOM)
1212 result += ' ' + lyxrc.print_landscape_flag;
1217 string const BufferParams::babelCall(string const & lang_opts) const
1219 string tmp = lyxrc.language_package;
1220 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1221 tmp = string("\\usepackage[") + lang_opts + "]{babel}";