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>
44 #include "support/std_sstream.h"
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;
59 struct BufferParams::Impl
63 AuthorList authorlist;
64 BranchList branchlist;
65 boost::array<Bullet, 4> temp_bullets;
66 boost::array<Bullet, 4> user_defined_bullets;
68 /** This is the amount of space used for paragraph_separation "skip",
69 * and for detached paragraphs in "indented" documents.
75 BufferParams::Impl::Impl()
76 : defskip(VSpace::MEDSKIP)
79 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
84 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
86 return new BufferParams::Impl(*ptr);
90 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
96 BufferParams::BufferParams()
97 : // Initialize textclass to point to article. if `first' is
98 // true in the returned pair, then `second' is the textclass
99 // number; if it is false, second is 0. In both cases, second
101 textclass(textclasslist.NumberOfClass("article").second),
104 paragraph_separation = PARSEP_INDENT;
105 quotes_language = InsetQuotes::EnglishQ;
106 quotes_times = InsetQuotes::DoubleQ;
107 fontsize = "default";
110 papersize = PAPER_DEFAULT;
111 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
112 paperpackage = PACKAGE_NONE;
113 orientation = ORIENTATION_PORTRAIT;
114 use_geometry = false;
115 use_amsmath = AMS_AUTO;
117 use_numerical_citations = false;
119 use_bibtopic = false;
120 tracking_changes = false;
123 language = default_language;
126 graphicsDriver = "default";
127 sides = LyXTextClass::OneSide;
129 pagestyle = "default";
131 for (int iter = 0; iter < 4; ++iter) {
132 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
133 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
138 BufferParams::~BufferParams()
142 AuthorList & BufferParams::authors()
144 return pimpl_->authorlist;
148 AuthorList const & BufferParams::authors() const
150 return pimpl_->authorlist;
154 BranchList & BufferParams::branchlist()
156 return pimpl_->branchlist;
160 BranchList const & BufferParams::branchlist() const
162 return pimpl_->branchlist;
166 Bullet & BufferParams::temp_bullet(lyx::size_type index)
168 BOOST_ASSERT(index < 4);
169 return pimpl_->temp_bullets[index];
173 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
175 BOOST_ASSERT(index < 4);
176 return pimpl_->temp_bullets[index];
180 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
182 BOOST_ASSERT(index < 4);
183 return pimpl_->user_defined_bullets[index];
187 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
189 BOOST_ASSERT(index < 4);
190 return pimpl_->user_defined_bullets[index];
194 Spacing & BufferParams::spacing()
196 return pimpl_->spacing;
200 Spacing const & BufferParams::spacing() const
202 return pimpl_->spacing;
206 VSpace const & BufferParams::getDefSkip() const
208 return pimpl_->defskip;
212 void BufferParams::setDefSkip(VSpace const & vs)
214 pimpl_->defskip = vs;
218 string const BufferParams::readToken(LyXLex & lex, string const & token)
220 if (token == "\\textclass") {
222 string const classname = lex.getString();
223 pair<bool, lyx::textclass_type> pp =
224 textclasslist.NumberOfClass(classname);
226 textclass = pp.second;
231 if (!getLyXTextClass().isTeXClassAvailable()) {
232 string msg = bformat(_("The document uses a missing "
233 "TeX class \"%1$s\".\n"), classname);
234 Alert::warning(_("Document class not available"),
235 msg + _("LyX will not be able to produce output."));
237 } else if (token == "\\begin_preamble") {
239 } else if (token == "\\options") {
241 options = lex.getString();
242 } else if (token == "\\language") {
244 } else if (token == "\\inputencoding") {
246 inputenc = lex.getString();
247 } else if (token == "\\graphics") {
248 readGraphicsDriver(lex);
249 } else if (token == "\\fontscheme") {
251 fonts = lex.getString();
252 } else if (token == "\\paragraph_separation") {
253 int tmpret = lex.findToken(string_paragraph_separation);
256 paragraph_separation =
257 static_cast<PARSEP>(tmpret);
258 } else if (token == "\\defskip") {
260 pimpl_->defskip = VSpace(lex.getString());
261 } else if (token == "\\quotes_language") {
262 // FIXME: should be params.readQuotes()
263 int tmpret = lex.findToken(string_quotes_language);
266 InsetQuotes::quote_language tmpl =
267 InsetQuotes::EnglishQ;
270 tmpl = InsetQuotes::EnglishQ;
273 tmpl = InsetQuotes::SwedishQ;
276 tmpl = InsetQuotes::GermanQ;
279 tmpl = InsetQuotes::PolishQ;
282 tmpl = InsetQuotes::FrenchQ;
285 tmpl = InsetQuotes::DanishQ;
288 quotes_language = tmpl;
289 } else if (token == "\\quotes_times") {
290 // FIXME: should be params.readQuotes()
292 switch (lex.getInteger()) {
294 quotes_times = InsetQuotes::SingleQ;
297 quotes_times = InsetQuotes::DoubleQ;
300 } else if (token == "\\papersize") {
301 int tmpret = lex.findToken(string_papersize);
305 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
306 } else if (token == "\\paperpackage") {
307 int tmpret = lex.findToken(string_paperpackages);
310 paperpackage = PACKAGE_NONE;
312 paperpackage = PAPER_PACKAGES(tmpret);
313 } else if (token == "\\use_geometry") {
315 use_geometry = lex.getInteger();
316 } else if (token == "\\use_amsmath") {
318 use_amsmath = static_cast<AMS>(
320 } else if (token == "\\use_natbib") {
322 use_natbib = lex.getInteger();
323 } else if (token == "\\use_numerical_citations") {
325 use_numerical_citations = lex.getInteger();
326 } else if (token == "\\use_jurabib") {
328 use_jurabib = lex.getInteger();
329 } else if (token == "\\use_bibtopic") {
331 use_bibtopic = lex.getInteger();
332 } else if (token == "\\tracking_changes") {
334 tracking_changes = lex.getInteger();
335 } else if (token == "\\branch") {
337 string branch = lex.getString();
338 branchlist().add(branch);
341 string const tok = lex.getString();
342 if (tok == "\\end_branch")
344 Branch * branch_ptr = branchlist().find(branch);
345 if (tok == "\\selected") {
348 branch_ptr->setSelected(lex.getInteger());
350 // not yet operational
351 if (tok == "\\color") {
353 string color = lex.getString();
355 branch_ptr->setColor(color);
356 // Update also the LColor table:
358 color = lcolor.getX11Name(LColor::background);
359 lcolor.setColor(branch, color);
363 } else if (token == "\\author") {
365 istringstream ss(lex.getString());
368 author_map.push_back(pimpl_->authorlist.record(a));
369 } else if (token == "\\paperorientation") {
370 int tmpret = lex.findToken(string_orientation);
374 static_cast<PAPER_ORIENTATION>(tmpret);
375 } else if (token == "\\paperwidth") {
377 paperwidth = lex.getString();
378 } else if (token == "\\paperheight") {
380 paperheight = lex.getString();
381 } else if (token == "\\leftmargin") {
383 leftmargin = lex.getString();
384 } else if (token == "\\topmargin") {
386 topmargin = lex.getString();
387 } else if (token == "\\rightmargin") {
389 rightmargin = lex.getString();
390 } else if (token == "\\bottommargin") {
392 bottommargin = lex.getString();
393 } else if (token == "\\headheight") {
395 headheight = lex.getString();
396 } else if (token == "\\headsep") {
398 headsep = lex.getString();
399 } else if (token == "\\footskip") {
401 footskip = lex.getString();
402 } else if (token == "\\paperfontsize") {
404 fontsize = rtrim(lex.getString());
405 } else if (token == "\\papercolumns") {
407 columns = lex.getInteger();
408 } else if (token == "\\papersides") {
410 switch (lex.getInteger()) {
412 case 1: sides = LyXTextClass::OneSide; break;
413 case 2: sides = LyXTextClass::TwoSides; break;
415 } else if (token == "\\paperpagestyle") {
417 pagestyle = rtrim(lex.getString());
418 } else if (token == "\\bullet") {
419 // FIXME: should be params.readBullets()
421 int const index = lex.getInteger();
423 int temp_int = lex.getInteger();
424 user_defined_bullet(index).setFont(temp_int);
425 temp_bullet(index).setFont(temp_int);
427 temp_int = lex.getInteger();
428 user_defined_bullet(index).setCharacter(temp_int);
429 temp_bullet(index).setCharacter(temp_int);
431 temp_int = lex.getInteger();
432 user_defined_bullet(index).setSize(temp_int);
433 temp_bullet(index).setSize(temp_int);
435 string const temp_str = lex.getString();
436 if (temp_str != "\\end_bullet") {
437 // this element isn't really necessary for
438 // parsing but is easier for humans
439 // to understand bullets. Put it back and
440 // set a debug message?
441 lex.printError("\\end_bullet expected, got" + temp_str);
442 //how can I put it back?
444 } else if (token == "\\bulletLaTeX") {
445 // The bullet class should be able to read this.
447 int const index = lex.getInteger();
449 string temp_str = lex.getString();
451 while (temp_str != "\\end_bullet") {
452 // this loop structure is needed when user
453 // enters an empty string since the first
454 // thing returned will be the \\end_bullet
456 // if the LaTeX entry has spaces. Each element
457 // therefore needs to be read in turn
460 temp_str = lex.getString();
463 user_defined_bullet(index).setText(sum_str);
464 temp_bullet(index).setText(sum_str);
465 } else if (token == "\\secnumdepth") {
467 secnumdepth = lex.getInteger();
468 } else if (token == "\\tocdepth") {
470 tocdepth = lex.getInteger();
471 } else if (token == "\\spacing") {
473 string const tmp = rtrim(lex.getString());
474 Spacing::Space tmp_space = Spacing::Default;
476 if (tmp == "single") {
477 tmp_space = Spacing::Single;
478 } else if (tmp == "onehalf") {
479 tmp_space = Spacing::Onehalf;
480 } else if (tmp == "double") {
481 tmp_space = Spacing::Double;
482 } else if (tmp == "other") {
484 tmp_space = Spacing::Other;
485 tmp_val = lex.getFloat();
487 lex.printError("Unknown spacing token: '$$Token'");
489 #if 0 // FIXME: Handled in lyx2lyx ?
490 // Small hack so that files written with klyx will be
493 par->params().spacing(Spacing(tmp_space, tmp_val));
495 spacing().set(tmp_space, tmp_val);
496 } else if (token == "\\float_placement") {
498 float_placement = lex.getString();
507 void BufferParams::writeFile(ostream & os) const
509 // The top of the file is written by the buffer.
510 // Prints out the buffer info into the .lyx file given by file
513 os << "\\textclass " << textclasslist[textclass].name() << '\n';
515 // then the the preamble
516 if (!preamble.empty()) {
517 // remove '\n' from the end of preamble
518 string const tmppreamble = rtrim(preamble, "\n");
519 os << "\\begin_preamble\n"
521 << "\n\\end_preamble\n";
525 if (!options.empty()) {
526 os << "\\options " << options << '\n';
529 /* then the text parameters */
530 if (language != ignore_language)
531 os << "\\language " << language->lang() << '\n';
532 os << "\\inputencoding " << inputenc
533 << "\n\\fontscheme " << fonts
534 << "\n\\graphics " << graphicsDriver << '\n';
536 if (!float_placement.empty()) {
537 os << "\\float_placement " << float_placement << '\n';
539 os << "\\paperfontsize " << fontsize << '\n';
541 spacing().writeFile(os);
543 os << "\\papersize " << string_papersize[papersize2]
544 << "\n\\paperpackage " << string_paperpackages[paperpackage]
545 << "\n\\use_geometry " << use_geometry
546 << "\n\\use_amsmath " << use_amsmath
547 << "\n\\use_natbib " << use_natbib
548 << "\n\\use_numerical_citations " << use_numerical_citations
549 << "\n\\use_jurabib " << use_jurabib
550 << "\n\\use_bibtopic " << use_bibtopic
551 << "\n\\paperorientation " << string_orientation[orientation]
554 std::list<Branch>::const_iterator it = branchlist().begin();
555 std::list<Branch>::const_iterator end = branchlist().end();
556 for (; it != end; ++it) {
557 os << "\\branch " << it->getBranch()
558 << "\n\\selected " << it->getSelected()
559 << "\n\\color " << it->getColor()
564 if (!paperwidth.empty())
565 os << "\\paperwidth "
566 << VSpace(paperwidth).asLyXCommand() << '\n';
567 if (!paperheight.empty())
568 os << "\\paperheight "
569 << VSpace(paperheight).asLyXCommand() << '\n';
570 if (!leftmargin.empty())
571 os << "\\leftmargin "
572 << VSpace(leftmargin).asLyXCommand() << '\n';
573 if (!topmargin.empty())
575 << VSpace(topmargin).asLyXCommand() << '\n';
576 if (!rightmargin.empty())
577 os << "\\rightmargin "
578 << VSpace(rightmargin).asLyXCommand() << '\n';
579 if (!bottommargin.empty())
580 os << "\\bottommargin "
581 << VSpace(bottommargin).asLyXCommand() << '\n';
582 if (!headheight.empty())
583 os << "\\headheight "
584 << VSpace(headheight).asLyXCommand() << '\n';
585 if (!headsep.empty())
587 << VSpace(headsep).asLyXCommand() << '\n';
588 if (!footskip.empty())
590 << VSpace(footskip).asLyXCommand() << '\n';
591 os << "\\secnumdepth " << secnumdepth
592 << "\n\\tocdepth " << tocdepth
593 << "\n\\paragraph_separation "
594 << string_paragraph_separation[paragraph_separation]
595 << "\n\\defskip " << getDefSkip().asLyXCommand()
596 << "\n\\quotes_language "
597 << string_quotes_language[quotes_language] << '\n';
598 switch (quotes_times) {
599 // An output operator for insetquotes would be nice
600 case InsetQuotes::SingleQ:
601 os << "\\quotes_times 1\n"; break;
602 case InsetQuotes::DoubleQ:
603 os << "\\quotes_times 2\n"; break;
605 os << "\\papercolumns " << columns
606 << "\n\\papersides " << sides
607 << "\n\\paperpagestyle " << pagestyle << '\n';
608 for (int i = 0; i < 4; ++i) {
609 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
610 if (user_defined_bullet(i).getFont() != -1) {
611 os << "\\bullet " << i
613 << user_defined_bullet(i).getFont()
615 << user_defined_bullet(i).getCharacter()
617 << user_defined_bullet(i).getSize()
618 << "\n\\end_bullet\n";
621 os << "\\bulletLaTeX " << i
623 << user_defined_bullet(i).getText()
624 << "\"\n\\end_bullet\n";
629 os << "\\tracking_changes " << tracking_changes << "\n";
631 if (tracking_changes) {
632 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
633 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
634 for (; it != end; ++it) {
635 os << "\\author " << it->second << "\n";
641 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
642 TexRow & texrow) const
644 os << "\\documentclass";
646 LyXTextClass const & tclass = getLyXTextClass();
648 ostringstream clsoptions; // the document class options.
650 if (tokenPos(tclass.opt_fontsize(),
651 '|', fontsize) >= 0) {
652 // only write if existing in list (and not default)
653 clsoptions << fontsize << "pt,";
658 (paperpackage == PACKAGE_NONE)) {
661 clsoptions << "a3paper,";
664 clsoptions << "a4paper,";
667 clsoptions << "letterpaper,";
670 clsoptions << "a5paper,";
673 clsoptions << "b5paper,";
675 case PAPER_EXECUTIVEPAPER:
676 clsoptions << "executivepaper,";
678 case PAPER_LEGALPAPER:
679 clsoptions << "legalpaper,";
687 if (sides != tclass.sides()) {
689 case LyXTextClass::OneSide:
690 clsoptions << "oneside,";
692 case LyXTextClass::TwoSides:
693 clsoptions << "twoside,";
699 if (columns != tclass.columns()) {
701 clsoptions << "twocolumn,";
703 clsoptions << "onecolumn,";
707 && orientation == ORIENTATION_LANDSCAPE)
708 clsoptions << "landscape,";
710 // language should be a parameter to \documentclass
711 if (language->babel() == "hebrew"
712 && default_language->babel() != "hebrew")
713 // This seems necessary
714 features.useLanguage(default_language);
716 ostringstream language_options;
717 bool const use_babel = features.useBabel();
719 language_options << features.getLanguages();
720 language_options << language->babel();
721 if (lyxrc.language_global_options)
722 clsoptions << language_options.str() << ',';
725 // the user-defined options
726 if (!options.empty()) {
727 clsoptions << options << ',';
730 string strOptions(clsoptions.str());
731 if (!strOptions.empty()) {
732 strOptions = rtrim(strOptions, ",");
733 os << '[' << strOptions << ']';
736 os << '{' << tclass.latexname() << "}\n";
738 // end of \documentclass defs
740 // font selection must be done before loading fontenc.sty
741 // The ae package is not needed when using OT1 font encoding.
742 if (fonts != "default" &&
743 (fonts != "ae" || lyxrc.fontenc != "default")) {
744 os << "\\usepackage{" << fonts << "}\n";
747 os << "\\usepackage{aecompl}\n";
751 // this one is not per buffer
752 if (lyxrc.fontenc != "default") {
753 os << "\\usepackage[" << lyxrc.fontenc
758 if (inputenc == "auto") {
759 string const doc_encoding =
760 language->encoding()->LatexName();
762 // Create a list with all the input encodings used
764 std::set<string> encodings =
765 features.getEncodingSet(doc_encoding);
767 os << "\\usepackage[";
768 std::copy(encodings.begin(), encodings.end(),
769 std::ostream_iterator<string>(os, ","));
770 os << doc_encoding << "]{inputenc}\n";
772 } else if (inputenc != "default") {
773 os << "\\usepackage[" << inputenc
778 // At the very beginning the text parameters.
779 if (paperpackage != PACKAGE_NONE) {
780 switch (paperpackage) {
784 os << "\\usepackage{a4}\n";
788 os << "\\usepackage{a4wide}\n";
791 case PACKAGE_WIDEMARGINSA4:
792 os << "\\usepackage[widemargins]{a4}\n";
798 os << "\\usepackage{geometry}\n";
800 os << "\\geometry{verbose";
801 if (orientation == ORIENTATION_LANDSCAPE)
803 switch (papersize2) {
804 case VM_PAPER_CUSTOM:
805 if (!paperwidth.empty())
808 if (!paperheight.empty())
809 os << ",paperheight="
812 case VM_PAPER_USLETTER:
813 os << ",letterpaper";
815 case VM_PAPER_USLEGAL:
818 case VM_PAPER_USEXECUTIVE:
819 os << ",executivepaper";
840 // default papersize ie VM_PAPER_DEFAULT
841 switch (lyxrc.default_papersize) {
842 case PAPER_DEFAULT: // keep compiler happy
844 os << ",letterpaper";
846 case PAPER_LEGALPAPER:
849 case PAPER_EXECUTIVEPAPER:
850 os << ",executivepaper";
866 if (!topmargin.empty())
867 os << ",tmargin=" << topmargin;
868 if (!bottommargin.empty())
869 os << ",bmargin=" << bottommargin;
870 if (!leftmargin.empty())
871 os << ",lmargin=" << leftmargin;
872 if (!rightmargin.empty())
873 os << ",rmargin=" << rightmargin;
874 if (!headheight.empty())
875 os << ",headheight=" << headheight;
876 if (!headsep.empty())
877 os << ",headsep=" << headsep;
878 if (!footskip.empty())
879 os << ",footskip=" << footskip;
884 if (tokenPos(tclass.opt_pagestyle(),
885 '|', pagestyle) >= 0) {
886 if (pagestyle == "fancy") {
887 os << "\\usepackage{fancyhdr}\n";
890 os << "\\pagestyle{" << pagestyle << "}\n";
894 if (secnumdepth != tclass.secnumdepth()) {
895 os << "\\setcounter{secnumdepth}{"
900 if (tocdepth != tclass.tocdepth()) {
901 os << "\\setcounter{tocdepth}{"
907 if (paragraph_separation) {
908 switch (getDefSkip().kind()) {
909 case VSpace::SMALLSKIP:
910 os << "\\setlength\\parskip{\\smallskipamount}\n";
912 case VSpace::MEDSKIP:
913 os << "\\setlength\\parskip{\\medskipamount}\n";
915 case VSpace::BIGSKIP:
916 os << "\\setlength\\parskip{\\bigskipamount}\n";
919 os << "\\setlength\\parskip{"
920 << getDefSkip().length().asLatexString()
923 default: // should never happen // Then delete it.
924 os << "\\setlength\\parskip{\\medskipamount}\n";
929 os << "\\setlength\\parindent{0pt}\n";
933 // If we use jurabib, we have to call babel here.
934 if (use_babel && features.isRequired("jurabib")) {
935 os << babelCall(language_options.str())
937 << features.getBabelOptions();
941 // Now insert the LyX specific LaTeX commands...
943 // The optional packages;
944 string lyxpreamble(features.getPackages());
946 // this might be useful...
947 lyxpreamble += "\n\\makeatletter\n";
949 // Some macros LyX will need
950 string tmppreamble(features.getMacros());
952 if (!tmppreamble.empty()) {
953 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
954 "LyX specific LaTeX commands.\n"
955 + tmppreamble + '\n';
958 // the text class specific preamble
959 tmppreamble = features.getTClassPreamble();
960 if (!tmppreamble.empty()) {
961 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
962 "Textclass specific LaTeX commands.\n"
963 + tmppreamble + '\n';
966 /* the user-defined preamble */
967 if (!preamble.empty()) {
968 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
969 "User specified LaTeX commands.\n"
973 // Itemize bullet settings need to be last in case the user
974 // defines their own bullets that use a package included
975 // in the user-defined preamble -- ARRae
976 // Actually it has to be done much later than that
977 // since some packages like frenchb make modifications
978 // at \begin{document} time -- JMarc
980 for (int i = 0; i < 4; ++i) {
981 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
982 if (bullets_def.empty())
983 bullets_def="\\AtBeginDocument{\n";
984 bullets_def += " \\renewcommand{\\labelitemi";
986 // `i' is one less than the item to modify
999 bullets_def += "}{" +
1000 user_defined_bullet(i).getText()
1005 if (!bullets_def.empty())
1006 lyxpreamble += bullets_def + "}\n\n";
1008 // We try to load babel late, in case it interferes
1009 // with other packages.
1010 // Jurabib has to be called after babel, though.
1011 if (use_babel && !features.isRequired("jurabib")) {
1012 lyxpreamble += babelCall(language_options.str()) + '\n';
1013 lyxpreamble += features.getBabelOptions();
1016 lyxpreamble += "\\makeatother\n";
1018 // dvipost settings come after everything else
1019 if (tracking_changes) {
1022 "\\dvipost{osstart color push Red}\n"
1023 "\\dvipost{osend color pop}\n"
1024 "\\dvipost{cbstart color push Blue}\n"
1025 "\\dvipost{cbend color pop} \n";
1029 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1030 for (int j = 0; j != nlines; ++j) {
1038 void BufferParams::setPaperStuff()
1040 papersize = PAPER_DEFAULT;
1041 char const c1 = paperpackage;
1042 if (c1 == PACKAGE_NONE) {
1043 char const c2 = papersize2;
1044 if (c2 == VM_PAPER_USLETTER)
1045 papersize = PAPER_USLETTER;
1046 else if (c2 == VM_PAPER_USLEGAL)
1047 papersize = PAPER_LEGALPAPER;
1048 else if (c2 == VM_PAPER_USEXECUTIVE)
1049 papersize = PAPER_EXECUTIVEPAPER;
1050 else if (c2 == VM_PAPER_A3)
1051 papersize = PAPER_A3PAPER;
1052 else if (c2 == VM_PAPER_A4)
1053 papersize = PAPER_A4PAPER;
1054 else if (c2 == VM_PAPER_A5)
1055 papersize = PAPER_A5PAPER;
1056 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1057 (c2 == VM_PAPER_B5))
1058 papersize = PAPER_B5PAPER;
1059 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1060 (c1 == PACKAGE_WIDEMARGINSA4))
1061 papersize = PAPER_A4PAPER;
1065 void BufferParams::useClassDefaults()
1067 LyXTextClass const & tclass = textclasslist[textclass];
1069 sides = tclass.sides();
1070 columns = tclass.columns();
1071 pagestyle = tclass.pagestyle();
1072 options = tclass.options();
1073 secnumdepth = tclass.secnumdepth();
1074 tocdepth = tclass.tocdepth();
1078 bool BufferParams::hasClassDefaults() const
1080 LyXTextClass const & tclass = textclasslist[textclass];
1082 return (sides == tclass.sides()
1083 && columns == tclass.columns()
1084 && pagestyle == tclass.pagestyle()
1085 && options == tclass.options()
1086 && secnumdepth == tclass.secnumdepth()
1087 && tocdepth == tclass.tocdepth());
1091 LyXTextClass const & BufferParams::getLyXTextClass() const
1093 return textclasslist[textclass];
1097 void BufferParams::readPreamble(LyXLex & lex)
1099 if (lex.getString() != "\\begin_preamble")
1100 lyxerr << "Error (BufferParams::readPreamble):"
1101 "consistency check failed." << endl;
1103 preamble = lex.getLongString("\\end_preamble");
1107 void BufferParams::readLanguage(LyXLex & lex)
1109 if (!lex.next()) return;
1111 string const tmptok = lex.getString();
1113 // check if tmptok is part of tex_babel in tex-defs.h
1114 language = languages.getLanguage(tmptok);
1116 // Language tmptok was not found
1117 language = default_language;
1118 lyxerr << "Warning: Setting language `"
1119 << tmptok << "' to `" << language->lang()
1125 void BufferParams::readGraphicsDriver(LyXLex & lex)
1127 if (!lex.next()) return;
1129 string const tmptok = lex.getString();
1130 // check if tmptok is part of tex_graphics in tex_defs.h
1133 string const test = tex_graphics[n++];
1135 if (test == tmptok) {
1136 graphicsDriver = tmptok;
1138 } else if (test == "last_item") {
1140 "Warning: graphics driver `$$Token' not recognized!\n"
1141 " Setting graphics driver to `default'.\n");
1142 graphicsDriver = "default";
1149 string const BufferParams::paperSizeName() const
1151 char real_papersize = papersize;
1152 if (real_papersize == PAPER_DEFAULT)
1153 real_papersize = lyxrc.default_papersize;
1155 switch (real_papersize) {
1164 case PAPER_EXECUTIVEPAPER:
1166 case PAPER_LEGALPAPER:
1168 case PAPER_USLETTER:
1175 string const BufferParams::dvips_options() const
1180 && papersize2 == VM_PAPER_CUSTOM
1181 && !lyxrc.print_paper_dimension_flag.empty()
1182 && !paperwidth.empty()
1183 && !paperheight.empty()) {
1184 // using a custom papersize
1185 result = lyxrc.print_paper_dimension_flag;
1186 result += ' ' + paperwidth;
1187 result += ',' + paperheight;
1189 string const paper_option = paperSizeName();
1190 if (paper_option != "letter" ||
1191 orientation != ORIENTATION_LANDSCAPE) {
1192 // dvips won't accept -t letter -t landscape.
1193 // In all other cases, include the paper size
1195 result = lyxrc.print_paper_flag;
1196 result += ' ' + paper_option;
1199 if (orientation == ORIENTATION_LANDSCAPE &&
1200 papersize2 != VM_PAPER_CUSTOM)
1201 result += ' ' + lyxrc.print_landscape_flag;
1206 string const BufferParams::babelCall(string const & lang_opts) const
1208 string tmp = lyxrc.language_package;
1209 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1210 tmp = string("\\usepackage[") + lang_opts + "]{babel}";