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 tracking_changes = false;
122 language = default_language;
125 graphicsDriver = "default";
126 sides = LyXTextClass::OneSide;
128 pagestyle = "default";
130 for (int iter = 0; iter < 4; ++iter) {
131 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
132 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
137 BufferParams::~BufferParams()
141 AuthorList & BufferParams::authors()
143 return pimpl_->authorlist;
147 AuthorList const & BufferParams::authors() const
149 return pimpl_->authorlist;
153 BranchList & BufferParams::branchlist()
155 return pimpl_->branchlist;
159 BranchList const & BufferParams::branchlist() const
161 return pimpl_->branchlist;
165 Bullet & BufferParams::temp_bullet(lyx::size_type index)
167 BOOST_ASSERT(index < 4);
168 return pimpl_->temp_bullets[index];
172 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
174 BOOST_ASSERT(index < 4);
175 return pimpl_->temp_bullets[index];
179 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
181 BOOST_ASSERT(index < 4);
182 return pimpl_->user_defined_bullets[index];
186 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
188 BOOST_ASSERT(index < 4);
189 return pimpl_->user_defined_bullets[index];
193 Spacing & BufferParams::spacing()
195 return pimpl_->spacing;
199 Spacing const & BufferParams::spacing() const
201 return pimpl_->spacing;
205 VSpace const & BufferParams::getDefSkip() const
207 return pimpl_->defskip;
211 void BufferParams::setDefSkip(VSpace const & vs)
213 pimpl_->defskip = vs;
217 string const BufferParams::readToken(LyXLex & lex, string const & token)
219 if (token == "\\textclass") {
221 string const classname = lex.getString();
222 pair<bool, lyx::textclass_type> pp =
223 textclasslist.NumberOfClass(classname);
225 textclass = pp.second;
230 if (!getLyXTextClass().isTeXClassAvailable()) {
231 string msg = bformat(_("The document uses a missing "
232 "TeX class \"%1$s\".\n"), classname);
233 Alert::warning(_("Document class not available"),
234 msg + _("LyX will not be able to produce output."));
236 } else if (token == "\\begin_preamble") {
238 } else if (token == "\\options") {
240 options = lex.getString();
241 } else if (token == "\\language") {
243 } else if (token == "\\inputencoding") {
245 inputenc = lex.getString();
246 } else if (token == "\\graphics") {
247 readGraphicsDriver(lex);
248 } else if (token == "\\fontscheme") {
250 fonts = lex.getString();
251 } else if (token == "\\paragraph_separation") {
252 int tmpret = lex.findToken(string_paragraph_separation);
255 paragraph_separation =
256 static_cast<PARSEP>(tmpret);
257 } else if (token == "\\defskip") {
259 pimpl_->defskip = VSpace(lex.getString());
260 } else if (token == "\\quotes_language") {
261 // FIXME: should be params.readQuotes()
262 int tmpret = lex.findToken(string_quotes_language);
265 InsetQuotes::quote_language tmpl =
266 InsetQuotes::EnglishQ;
269 tmpl = InsetQuotes::EnglishQ;
272 tmpl = InsetQuotes::SwedishQ;
275 tmpl = InsetQuotes::GermanQ;
278 tmpl = InsetQuotes::PolishQ;
281 tmpl = InsetQuotes::FrenchQ;
284 tmpl = InsetQuotes::DanishQ;
287 quotes_language = tmpl;
288 } else if (token == "\\quotes_times") {
289 // FIXME: should be params.readQuotes()
291 switch (lex.getInteger()) {
293 quotes_times = InsetQuotes::SingleQ;
296 quotes_times = InsetQuotes::DoubleQ;
299 } else if (token == "\\papersize") {
300 int tmpret = lex.findToken(string_papersize);
304 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
305 } else if (token == "\\paperpackage") {
306 int tmpret = lex.findToken(string_paperpackages);
309 paperpackage = PACKAGE_NONE;
311 paperpackage = PAPER_PACKAGES(tmpret);
312 } else if (token == "\\use_geometry") {
314 use_geometry = lex.getInteger();
315 } else if (token == "\\use_amsmath") {
317 use_amsmath = static_cast<AMS>(
319 } else if (token == "\\use_natbib") {
321 use_natbib = lex.getInteger();
322 } else if (token == "\\use_numerical_citations") {
324 use_numerical_citations = lex.getInteger();
325 } else if (token == "\\use_jurabib") {
327 use_jurabib = lex.getInteger();
328 } else if (token == "\\tracking_changes") {
330 tracking_changes = lex.getInteger();
331 } else if (token == "\\branch") {
333 string branch = lex.getString();
334 branchlist().add(branch);
337 string const tok = lex.getString();
338 if (tok == "\\end_branch")
340 Branch * branch_ptr = branchlist().find(branch);
341 if (tok == "\\selected") {
344 branch_ptr->setSelected(lex.getInteger());
346 // not yet operational
347 if (tok == "\\color") {
349 string color = lex.getString();
351 branch_ptr->setColor(color);
352 // Update also the LColor table:
354 color = lcolor.getX11Name(LColor::background);
355 lcolor.setColor(branch, color);
359 } else if (token == "\\author") {
361 istringstream ss(lex.getString());
364 author_map.push_back(pimpl_->authorlist.record(a));
365 } else if (token == "\\paperorientation") {
366 int tmpret = lex.findToken(string_orientation);
370 static_cast<PAPER_ORIENTATION>(tmpret);
371 } else if (token == "\\paperwidth") {
373 paperwidth = lex.getString();
374 } else if (token == "\\paperheight") {
376 paperheight = lex.getString();
377 } else if (token == "\\leftmargin") {
379 leftmargin = lex.getString();
380 } else if (token == "\\topmargin") {
382 topmargin = lex.getString();
383 } else if (token == "\\rightmargin") {
385 rightmargin = lex.getString();
386 } else if (token == "\\bottommargin") {
388 bottommargin = lex.getString();
389 } else if (token == "\\headheight") {
391 headheight = lex.getString();
392 } else if (token == "\\headsep") {
394 headsep = lex.getString();
395 } else if (token == "\\footskip") {
397 footskip = lex.getString();
398 } else if (token == "\\paperfontsize") {
400 fontsize = rtrim(lex.getString());
401 } else if (token == "\\papercolumns") {
403 columns = lex.getInteger();
404 } else if (token == "\\papersides") {
406 switch (lex.getInteger()) {
408 case 1: sides = LyXTextClass::OneSide; break;
409 case 2: sides = LyXTextClass::TwoSides; break;
411 } else if (token == "\\paperpagestyle") {
413 pagestyle = rtrim(lex.getString());
414 } else if (token == "\\bullet") {
415 // FIXME: should be params.readBullets()
417 int const index = lex.getInteger();
419 int temp_int = lex.getInteger();
420 user_defined_bullet(index).setFont(temp_int);
421 temp_bullet(index).setFont(temp_int);
423 temp_int = lex.getInteger();
424 user_defined_bullet(index).setCharacter(temp_int);
425 temp_bullet(index).setCharacter(temp_int);
427 temp_int = lex.getInteger();
428 user_defined_bullet(index).setSize(temp_int);
429 temp_bullet(index).setSize(temp_int);
431 string const temp_str = lex.getString();
432 if (temp_str != "\\end_bullet") {
433 // this element isn't really necessary for
434 // parsing but is easier for humans
435 // to understand bullets. Put it back and
436 // set a debug message?
437 lex.printError("\\end_bullet expected, got" + temp_str);
438 //how can I put it back?
440 } else if (token == "\\bulletLaTeX") {
441 // The bullet class should be able to read this.
443 int const index = lex.getInteger();
445 string temp_str = lex.getString();
447 while (temp_str != "\\end_bullet") {
448 // this loop structure is needed when user
449 // enters an empty string since the first
450 // thing returned will be the \\end_bullet
452 // if the LaTeX entry has spaces. Each element
453 // therefore needs to be read in turn
456 temp_str = lex.getString();
459 user_defined_bullet(index).setText(sum_str);
460 temp_bullet(index).setText(sum_str);
461 } else if (token == "\\secnumdepth") {
463 secnumdepth = lex.getInteger();
464 } else if (token == "\\tocdepth") {
466 tocdepth = lex.getInteger();
467 } else if (token == "\\spacing") {
469 string const tmp = rtrim(lex.getString());
470 Spacing::Space tmp_space = Spacing::Default;
472 if (tmp == "single") {
473 tmp_space = Spacing::Single;
474 } else if (tmp == "onehalf") {
475 tmp_space = Spacing::Onehalf;
476 } else if (tmp == "double") {
477 tmp_space = Spacing::Double;
478 } else if (tmp == "other") {
480 tmp_space = Spacing::Other;
481 tmp_val = lex.getFloat();
483 lex.printError("Unknown spacing token: '$$Token'");
485 #if 0 // FIXME: Handled in lyx2lyx ?
486 // Small hack so that files written with klyx will be
489 par->params().spacing(Spacing(tmp_space, tmp_val));
491 spacing().set(tmp_space, tmp_val);
492 } else if (token == "\\float_placement") {
494 float_placement = lex.getString();
503 void BufferParams::writeFile(ostream & os) const
505 // The top of the file is written by the buffer.
506 // Prints out the buffer info into the .lyx file given by file
509 os << "\\textclass " << textclasslist[textclass].name() << '\n';
511 // then the the preamble
512 if (!preamble.empty()) {
513 // remove '\n' from the end of preamble
514 string const tmppreamble = rtrim(preamble, "\n");
515 os << "\\begin_preamble\n"
517 << "\n\\end_preamble\n";
521 if (!options.empty()) {
522 os << "\\options " << options << '\n';
525 /* then the text parameters */
526 if (language != ignore_language)
527 os << "\\language " << language->lang() << '\n';
528 os << "\\inputencoding " << inputenc
529 << "\n\\fontscheme " << fonts
530 << "\n\\graphics " << graphicsDriver << '\n';
532 if (!float_placement.empty()) {
533 os << "\\float_placement " << float_placement << '\n';
535 os << "\\paperfontsize " << fontsize << '\n';
537 spacing().writeFile(os);
539 os << "\\papersize " << string_papersize[papersize2]
540 << "\n\\paperpackage " << string_paperpackages[paperpackage]
541 << "\n\\use_geometry " << use_geometry
542 << "\n\\use_amsmath " << use_amsmath
543 << "\n\\use_natbib " << use_natbib
544 << "\n\\use_numerical_citations " << use_numerical_citations
545 << "\n\\use_jurabib " << use_jurabib
546 << "\n\\paperorientation " << string_orientation[orientation]
549 std::list<Branch>::const_iterator it = branchlist().begin();
550 std::list<Branch>::const_iterator end = branchlist().end();
551 for (; it != end; ++it) {
552 os << "\\branch " << it->getBranch()
553 << "\n\\selected " << it->getSelected()
554 << "\n\\color " << it->getColor()
559 if (!paperwidth.empty())
560 os << "\\paperwidth "
561 << VSpace(paperwidth).asLyXCommand() << '\n';
562 if (!paperheight.empty())
563 os << "\\paperheight "
564 << VSpace(paperheight).asLyXCommand() << '\n';
565 if (!leftmargin.empty())
566 os << "\\leftmargin "
567 << VSpace(leftmargin).asLyXCommand() << '\n';
568 if (!topmargin.empty())
570 << VSpace(topmargin).asLyXCommand() << '\n';
571 if (!rightmargin.empty())
572 os << "\\rightmargin "
573 << VSpace(rightmargin).asLyXCommand() << '\n';
574 if (!bottommargin.empty())
575 os << "\\bottommargin "
576 << VSpace(bottommargin).asLyXCommand() << '\n';
577 if (!headheight.empty())
578 os << "\\headheight "
579 << VSpace(headheight).asLyXCommand() << '\n';
580 if (!headsep.empty())
582 << VSpace(headsep).asLyXCommand() << '\n';
583 if (!footskip.empty())
585 << VSpace(footskip).asLyXCommand() << '\n';
586 os << "\\secnumdepth " << secnumdepth
587 << "\n\\tocdepth " << tocdepth
588 << "\n\\paragraph_separation "
589 << string_paragraph_separation[paragraph_separation]
590 << "\n\\defskip " << getDefSkip().asLyXCommand()
591 << "\n\\quotes_language "
592 << string_quotes_language[quotes_language] << '\n';
593 switch (quotes_times) {
594 // An output operator for insetquotes would be nice
595 case InsetQuotes::SingleQ:
596 os << "\\quotes_times 1\n"; break;
597 case InsetQuotes::DoubleQ:
598 os << "\\quotes_times 2\n"; break;
600 os << "\\papercolumns " << columns
601 << "\n\\papersides " << sides
602 << "\n\\paperpagestyle " << pagestyle << '\n';
603 for (int i = 0; i < 4; ++i) {
604 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
605 if (user_defined_bullet(i).getFont() != -1) {
606 os << "\\bullet " << i
608 << user_defined_bullet(i).getFont()
610 << user_defined_bullet(i).getCharacter()
612 << user_defined_bullet(i).getSize()
613 << "\n\\end_bullet\n";
616 os << "\\bulletLaTeX " << i
618 << user_defined_bullet(i).getText()
619 << "\"\n\\end_bullet\n";
624 os << "\\tracking_changes " << tracking_changes << "\n";
626 if (tracking_changes) {
627 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
628 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
629 for (; it != end; ++it) {
630 os << "\\author " << it->second << "\n";
636 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
637 TexRow & texrow) const
639 os << "\\documentclass";
641 LyXTextClass const & tclass = getLyXTextClass();
643 ostringstream clsoptions; // the document class options.
645 if (tokenPos(tclass.opt_fontsize(),
646 '|', fontsize) >= 0) {
647 // only write if existing in list (and not default)
648 clsoptions << fontsize << "pt,";
653 (paperpackage == PACKAGE_NONE)) {
656 clsoptions << "a3paper,";
659 clsoptions << "a4paper,";
662 clsoptions << "letterpaper,";
665 clsoptions << "a5paper,";
668 clsoptions << "b5paper,";
670 case PAPER_EXECUTIVEPAPER:
671 clsoptions << "executivepaper,";
673 case PAPER_LEGALPAPER:
674 clsoptions << "legalpaper,";
682 if (sides != tclass.sides()) {
684 case LyXTextClass::OneSide:
685 clsoptions << "oneside,";
687 case LyXTextClass::TwoSides:
688 clsoptions << "twoside,";
694 if (columns != tclass.columns()) {
696 clsoptions << "twocolumn,";
698 clsoptions << "onecolumn,";
702 && orientation == ORIENTATION_LANDSCAPE)
703 clsoptions << "landscape,";
705 // language should be a parameter to \documentclass
706 if (language->babel() == "hebrew"
707 && default_language->babel() != "hebrew")
708 // This seems necessary
709 features.useLanguage(default_language);
711 ostringstream language_options;
712 bool const use_babel = features.useBabel();
714 language_options << features.getLanguages();
715 language_options << language->babel();
716 if (lyxrc.language_global_options)
717 clsoptions << language_options.str() << ',';
720 // the user-defined options
721 if (!options.empty()) {
722 clsoptions << options << ',';
725 string strOptions(clsoptions.str());
726 if (!strOptions.empty()) {
727 strOptions = rtrim(strOptions, ",");
728 os << '[' << strOptions << ']';
731 os << '{' << tclass.latexname() << "}\n";
733 // end of \documentclass defs
735 // font selection must be done before loading fontenc.sty
736 // The ae package is not needed when using OT1 font encoding.
737 if (fonts != "default" &&
738 (fonts != "ae" || lyxrc.fontenc != "default")) {
739 os << "\\usepackage{" << fonts << "}\n";
742 os << "\\usepackage{aecompl}\n";
746 // this one is not per buffer
747 if (lyxrc.fontenc != "default") {
748 os << "\\usepackage[" << lyxrc.fontenc
753 if (inputenc == "auto") {
754 string const doc_encoding =
755 language->encoding()->LatexName();
757 // Create a list with all the input encodings used
759 std::set<string> encodings =
760 features.getEncodingSet(doc_encoding);
762 os << "\\usepackage[";
763 std::copy(encodings.begin(), encodings.end(),
764 std::ostream_iterator<string>(os, ","));
765 os << doc_encoding << "]{inputenc}\n";
767 } else if (inputenc != "default") {
768 os << "\\usepackage[" << inputenc
773 // At the very beginning the text parameters.
774 if (paperpackage != PACKAGE_NONE) {
775 switch (paperpackage) {
779 os << "\\usepackage{a4}\n";
783 os << "\\usepackage{a4wide}\n";
786 case PACKAGE_WIDEMARGINSA4:
787 os << "\\usepackage[widemargins]{a4}\n";
793 os << "\\usepackage{geometry}\n";
795 os << "\\geometry{verbose";
796 if (orientation == ORIENTATION_LANDSCAPE)
798 switch (papersize2) {
799 case VM_PAPER_CUSTOM:
800 if (!paperwidth.empty())
803 if (!paperheight.empty())
804 os << ",paperheight="
807 case VM_PAPER_USLETTER:
808 os << ",letterpaper";
810 case VM_PAPER_USLEGAL:
813 case VM_PAPER_USEXECUTIVE:
814 os << ",executivepaper";
835 // default papersize ie VM_PAPER_DEFAULT
836 switch (lyxrc.default_papersize) {
837 case PAPER_DEFAULT: // keep compiler happy
839 os << ",letterpaper";
841 case PAPER_LEGALPAPER:
844 case PAPER_EXECUTIVEPAPER:
845 os << ",executivepaper";
861 if (!topmargin.empty())
862 os << ",tmargin=" << topmargin;
863 if (!bottommargin.empty())
864 os << ",bmargin=" << bottommargin;
865 if (!leftmargin.empty())
866 os << ",lmargin=" << leftmargin;
867 if (!rightmargin.empty())
868 os << ",rmargin=" << rightmargin;
869 if (!headheight.empty())
870 os << ",headheight=" << headheight;
871 if (!headsep.empty())
872 os << ",headsep=" << headsep;
873 if (!footskip.empty())
874 os << ",footskip=" << footskip;
879 if (tokenPos(tclass.opt_pagestyle(),
880 '|', pagestyle) >= 0) {
881 if (pagestyle == "fancy") {
882 os << "\\usepackage{fancyhdr}\n";
885 os << "\\pagestyle{" << pagestyle << "}\n";
889 if (secnumdepth != tclass.secnumdepth()) {
890 os << "\\setcounter{secnumdepth}{"
895 if (tocdepth != tclass.tocdepth()) {
896 os << "\\setcounter{tocdepth}{"
902 if (paragraph_separation) {
903 switch (getDefSkip().kind()) {
904 case VSpace::SMALLSKIP:
905 os << "\\setlength\\parskip{\\smallskipamount}\n";
907 case VSpace::MEDSKIP:
908 os << "\\setlength\\parskip{\\medskipamount}\n";
910 case VSpace::BIGSKIP:
911 os << "\\setlength\\parskip{\\bigskipamount}\n";
914 os << "\\setlength\\parskip{"
915 << getDefSkip().length().asLatexString()
918 default: // should never happen // Then delete it.
919 os << "\\setlength\\parskip{\\medskipamount}\n";
924 os << "\\setlength\\parindent{0pt}\n";
928 // If we use jurabib, we have to call babel here.
929 if (use_babel && features.isRequired("jurabib")) {
930 os << babelCall(language_options.str())
932 << features.getBabelOptions();
936 // Now insert the LyX specific LaTeX commands...
938 // The optional packages;
939 string lyxpreamble(features.getPackages());
941 // this might be useful...
942 lyxpreamble += "\n\\makeatletter\n";
944 // Some macros LyX will need
945 string tmppreamble(features.getMacros());
947 if (!tmppreamble.empty()) {
948 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
949 "LyX specific LaTeX commands.\n"
950 + tmppreamble + '\n';
953 // the text class specific preamble
954 tmppreamble = features.getTClassPreamble();
955 if (!tmppreamble.empty()) {
956 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
957 "Textclass specific LaTeX commands.\n"
958 + tmppreamble + '\n';
961 /* the user-defined preamble */
962 if (!preamble.empty()) {
963 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
964 "User specified LaTeX commands.\n"
968 // Itemize bullet settings need to be last in case the user
969 // defines their own bullets that use a package included
970 // in the user-defined preamble -- ARRae
971 // Actually it has to be done much later than that
972 // since some packages like frenchb make modifications
973 // at \begin{document} time -- JMarc
975 for (int i = 0; i < 4; ++i) {
976 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
977 if (bullets_def.empty())
978 bullets_def="\\AtBeginDocument{\n";
979 bullets_def += " \\renewcommand{\\labelitemi";
981 // `i' is one less than the item to modify
994 bullets_def += "}{" +
995 user_defined_bullet(i).getText()
1000 if (!bullets_def.empty())
1001 lyxpreamble += bullets_def + "}\n\n";
1003 // We try to load babel late, in case it interferes
1004 // with other packages.
1005 // Jurabib has to be called after babel, though.
1006 if (use_babel && !features.isRequired("jurabib")) {
1007 lyxpreamble += babelCall(language_options.str()) + '\n';
1008 lyxpreamble += features.getBabelOptions();
1011 lyxpreamble += "\\makeatother\n";
1013 // dvipost settings come after everything else
1014 if (tracking_changes) {
1017 "\\dvipost{osstart color push Red}\n"
1018 "\\dvipost{osend color pop}\n"
1019 "\\dvipost{cbstart color push Blue}\n"
1020 "\\dvipost{cbend color pop} \n";
1024 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1025 for (int j = 0; j != nlines; ++j) {
1033 void BufferParams::setPaperStuff()
1035 papersize = PAPER_DEFAULT;
1036 char const c1 = paperpackage;
1037 if (c1 == PACKAGE_NONE) {
1038 char const c2 = papersize2;
1039 if (c2 == VM_PAPER_USLETTER)
1040 papersize = PAPER_USLETTER;
1041 else if (c2 == VM_PAPER_USLEGAL)
1042 papersize = PAPER_LEGALPAPER;
1043 else if (c2 == VM_PAPER_USEXECUTIVE)
1044 papersize = PAPER_EXECUTIVEPAPER;
1045 else if (c2 == VM_PAPER_A3)
1046 papersize = PAPER_A3PAPER;
1047 else if (c2 == VM_PAPER_A4)
1048 papersize = PAPER_A4PAPER;
1049 else if (c2 == VM_PAPER_A5)
1050 papersize = PAPER_A5PAPER;
1051 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1052 (c2 == VM_PAPER_B5))
1053 papersize = PAPER_B5PAPER;
1054 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1055 (c1 == PACKAGE_WIDEMARGINSA4))
1056 papersize = PAPER_A4PAPER;
1060 void BufferParams::useClassDefaults()
1062 LyXTextClass const & tclass = textclasslist[textclass];
1064 sides = tclass.sides();
1065 columns = tclass.columns();
1066 pagestyle = tclass.pagestyle();
1067 options = tclass.options();
1068 secnumdepth = tclass.secnumdepth();
1069 tocdepth = tclass.tocdepth();
1073 bool BufferParams::hasClassDefaults() const
1075 LyXTextClass const & tclass = textclasslist[textclass];
1077 return (sides == tclass.sides()
1078 && columns == tclass.columns()
1079 && pagestyle == tclass.pagestyle()
1080 && options == tclass.options()
1081 && secnumdepth == tclass.secnumdepth()
1082 && tocdepth == tclass.tocdepth());
1086 LyXTextClass const & BufferParams::getLyXTextClass() const
1088 return textclasslist[textclass];
1092 void BufferParams::readPreamble(LyXLex & lex)
1094 if (lex.getString() != "\\begin_preamble")
1095 lyxerr << "Error (BufferParams::readPreamble):"
1096 "consistency check failed." << endl;
1098 preamble = lex.getLongString("\\end_preamble");
1102 void BufferParams::readLanguage(LyXLex & lex)
1104 if (!lex.next()) return;
1106 string const tmptok = lex.getString();
1108 // check if tmptok is part of tex_babel in tex-defs.h
1109 language = languages.getLanguage(tmptok);
1111 // Language tmptok was not found
1112 language = default_language;
1113 lyxerr << "Warning: Setting language `"
1114 << tmptok << "' to `" << language->lang()
1120 void BufferParams::readGraphicsDriver(LyXLex & lex)
1122 if (!lex.next()) return;
1124 string const tmptok = lex.getString();
1125 // check if tmptok is part of tex_graphics in tex_defs.h
1128 string const test = tex_graphics[n++];
1130 if (test == tmptok) {
1131 graphicsDriver = tmptok;
1133 } else if (test == "last_item") {
1135 "Warning: graphics driver `$$Token' not recognized!\n"
1136 " Setting graphics driver to `default'.\n");
1137 graphicsDriver = "default";
1144 string const BufferParams::paperSizeName() const
1146 char real_papersize = papersize;
1147 if (real_papersize == PAPER_DEFAULT)
1148 real_papersize = lyxrc.default_papersize;
1150 switch (real_papersize) {
1159 case PAPER_EXECUTIVEPAPER:
1161 case PAPER_LEGALPAPER:
1163 case PAPER_USLETTER:
1170 string const BufferParams::dvips_options() const
1175 && papersize2 == VM_PAPER_CUSTOM
1176 && !lyxrc.print_paper_dimension_flag.empty()
1177 && !paperwidth.empty()
1178 && !paperheight.empty()) {
1179 // using a custom papersize
1180 result = lyxrc.print_paper_dimension_flag;
1181 result += ' ' + paperwidth;
1182 result += ',' + paperheight;
1184 string const paper_option = paperSizeName();
1185 if (paper_option != "letter" ||
1186 orientation != ORIENTATION_LANDSCAPE) {
1187 // dvips won't accept -t letter -t landscape.
1188 // In all other cases, include the paper size
1190 result = lyxrc.print_paper_flag;
1191 result += ' ' + paper_option;
1194 if (orientation == ORIENTATION_LANDSCAPE &&
1195 papersize2 != VM_PAPER_CUSTOM)
1196 result += ' ' + lyxrc.print_landscape_flag;
1201 string const BufferParams::babelCall(string const & lang_opts) const
1203 string tmp = lyxrc.language_package;
1204 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1205 tmp = string("\\usepackage[") + lang_opts + "]{babel}";