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"
28 #include "latexrunparams.h"
31 #include "lyxtextclasslist.h"
32 #include "tex-strings.h"
37 #include "frontends/Alert.h"
39 #include "support/lyxalgo.h" // for lyx::count
41 #include <boost/array.hpp>
43 #include "support/std_sstream.h"
45 namespace support = lyx::support;
46 using lyx::support::bformat;
47 using lyx::support::rtrim;
48 using lyx::support::tokenPos;
52 using std::istringstream;
54 using std::ostringstream;
58 struct BufferParams::Impl
62 AuthorList authorlist;
63 BranchList branchlist;
64 boost::array<Bullet, 4> temp_bullets;
65 boost::array<Bullet, 4> user_defined_bullets;
67 /** This is the amount of space used for paragraph_separation "skip",
68 * and for detached paragraphs in "indented" documents.
74 BufferParams::Impl::Impl()
75 : defskip(VSpace::MEDSKIP)
78 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
82 BufferParams::BufferParams()
83 : // Initialize textclass to point to article. if `first' is
84 // true in the returned pair, then `second' is the textclass
85 // number; if it is false, second is 0. In both cases, second
87 textclass(textclasslist.NumberOfClass("article").second),
90 paragraph_separation = PARSEP_INDENT;
91 quotes_language = InsetQuotes::EnglishQ;
92 quotes_times = InsetQuotes::DoubleQ;
96 papersize = PAPER_DEFAULT;
97 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
98 paperpackage = PACKAGE_NONE;
99 orientation = ORIENTATION_PORTRAIT;
100 use_geometry = false;
101 use_amsmath = AMS_AUTO;
103 use_numerical_citations = false;
104 tracking_changes = false;
107 language = default_language;
110 graphicsDriver = "default";
111 sides = LyXTextClass::OneSide;
113 pagestyle = "default";
115 for (int iter = 0; iter < 4; ++iter) {
116 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
117 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
122 BufferParams::~BufferParams()
126 AuthorList & BufferParams::authors()
128 return pimpl_->authorlist;
132 AuthorList const & BufferParams::authors() const
134 return pimpl_->authorlist;
138 BranchList & BufferParams::branchlist()
140 return pimpl_->branchlist;
144 BranchList const & BufferParams::branchlist() const
146 return pimpl_->branchlist;
150 Bullet & BufferParams::temp_bullet(lyx::size_type index)
152 BOOST_ASSERT(index < 4);
153 return pimpl_->temp_bullets[index];
157 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
159 BOOST_ASSERT(index < 4);
160 return pimpl_->temp_bullets[index];
164 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
166 BOOST_ASSERT(index < 4);
167 return pimpl_->user_defined_bullets[index];
171 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
173 BOOST_ASSERT(index < 4);
174 return pimpl_->user_defined_bullets[index];
178 Spacing & BufferParams::spacing()
180 return pimpl_->spacing;
184 Spacing const & BufferParams::spacing() const
186 return pimpl_->spacing;
190 VSpace const & BufferParams::getDefSkip() const
192 return pimpl_->defskip;
196 void BufferParams::setDefSkip(VSpace const & vs)
198 pimpl_->defskip = vs;
202 string const BufferParams::readToken(LyXLex & lex, string const & token)
204 if (token == "\\textclass") {
206 string const classname = lex.getString();
207 pair<bool, lyx::textclass_type> pp =
208 textclasslist.NumberOfClass(classname);
210 textclass = pp.second;
215 if (!getLyXTextClass().isTeXClassAvailable()) {
216 string msg = bformat(_("The document uses a missing "
217 "TeX class \"%1$s\".\n"), classname);
218 Alert::warning(_("Document class not available"),
219 msg + _("LyX will not be able to produce output."));
221 } else if (token == "\\begin_preamble") {
223 } else if (token == "\\options") {
225 options = lex.getString();
226 } else if (token == "\\language") {
228 } else if (token == "\\inputencoding") {
230 inputenc = lex.getString();
231 } else if (token == "\\graphics") {
232 readGraphicsDriver(lex);
233 } else if (token == "\\fontscheme") {
235 fonts = lex.getString();
236 } else if (token == "\\paragraph_separation") {
237 int tmpret = lex.findToken(string_paragraph_separation);
240 paragraph_separation =
241 static_cast<PARSEP>(tmpret);
242 } else if (token == "\\defskip") {
244 pimpl_->defskip = VSpace(lex.getString());
245 } else if (token == "\\quotes_language") {
246 // FIXME: should be params.readQuotes()
247 int tmpret = lex.findToken(string_quotes_language);
250 InsetQuotes::quote_language tmpl =
251 InsetQuotes::EnglishQ;
254 tmpl = InsetQuotes::EnglishQ;
257 tmpl = InsetQuotes::SwedishQ;
260 tmpl = InsetQuotes::GermanQ;
263 tmpl = InsetQuotes::PolishQ;
266 tmpl = InsetQuotes::FrenchQ;
269 tmpl = InsetQuotes::DanishQ;
272 quotes_language = tmpl;
273 } else if (token == "\\quotes_times") {
274 // FIXME: should be params.readQuotes()
276 switch (lex.getInteger()) {
278 quotes_times = InsetQuotes::SingleQ;
281 quotes_times = InsetQuotes::DoubleQ;
284 } else if (token == "\\papersize") {
285 int tmpret = lex.findToken(string_papersize);
289 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
290 } else if (token == "\\paperpackage") {
291 int tmpret = lex.findToken(string_paperpackages);
294 paperpackage = PACKAGE_NONE;
296 paperpackage = PAPER_PACKAGES(tmpret);
297 } else if (token == "\\use_geometry") {
299 use_geometry = lex.getInteger();
300 } else if (token == "\\use_amsmath") {
302 use_amsmath = static_cast<AMS>(
304 } else if (token == "\\use_natbib") {
306 use_natbib = lex.getInteger();
307 } else if (token == "\\use_numerical_citations") {
309 use_numerical_citations = lex.getInteger();
310 } else if (token == "\\tracking_changes") {
312 tracking_changes = lex.getInteger();
313 } else if (token == "\\branch") {
315 string branch = lex.getString();
316 branchlist().add(branch);
319 string const tok = lex.getString();
320 if (tok == "\\end_branch")
322 if (tok == "\\selected") {
324 branchlist().setSelected(branch, lex.getInteger());
326 // not yet operational
327 if (tok == "\\color") {
329 string color = lex.getString();
330 branchlist().setColor(branch, color);
331 // Update also the LColor table:
333 color = lcolor.getX11Name(LColor::background);
334 lcolor.fill(static_cast<LColor::color>(lcolor.size()),
338 } else if (token == "\\author") {
340 istringstream ss(lex.getString());
343 author_map.push_back(pimpl_->authorlist.record(a));
344 } else if (token == "\\paperorientation") {
345 int tmpret = lex.findToken(string_orientation);
349 static_cast<PAPER_ORIENTATION>(tmpret);
350 } else if (token == "\\paperwidth") {
352 paperwidth = lex.getString();
353 } else if (token == "\\paperheight") {
355 paperheight = lex.getString();
356 } else if (token == "\\leftmargin") {
358 leftmargin = lex.getString();
359 } else if (token == "\\topmargin") {
361 topmargin = lex.getString();
362 } else if (token == "\\rightmargin") {
364 rightmargin = lex.getString();
365 } else if (token == "\\bottommargin") {
367 bottommargin = lex.getString();
368 } else if (token == "\\headheight") {
370 headheight = lex.getString();
371 } else if (token == "\\headsep") {
373 headsep = lex.getString();
374 } else if (token == "\\footskip") {
376 footskip = lex.getString();
377 } else if (token == "\\paperfontsize") {
379 fontsize = rtrim(lex.getString());
380 } else if (token == "\\papercolumns") {
382 columns = lex.getInteger();
383 } else if (token == "\\papersides") {
385 switch (lex.getInteger()) {
387 case 1: sides = LyXTextClass::OneSide; break;
388 case 2: sides = LyXTextClass::TwoSides; break;
390 } else if (token == "\\paperpagestyle") {
392 pagestyle = rtrim(lex.getString());
393 } else if (token == "\\bullet") {
394 // FIXME: should be params.readBullets()
396 int const index = lex.getInteger();
398 int temp_int = lex.getInteger();
399 user_defined_bullet(index).setFont(temp_int);
400 temp_bullet(index).setFont(temp_int);
402 temp_int = lex.getInteger();
403 user_defined_bullet(index).setCharacter(temp_int);
404 temp_bullet(index).setCharacter(temp_int);
406 temp_int = lex.getInteger();
407 user_defined_bullet(index).setSize(temp_int);
408 temp_bullet(index).setSize(temp_int);
410 string const temp_str = lex.getString();
411 if (temp_str != "\\end_bullet") {
412 // this element isn't really necessary for
413 // parsing but is easier for humans
414 // to understand bullets. Put it back and
415 // set a debug message?
416 lex.printError("\\end_bullet expected, got" + temp_str);
417 //how can I put it back?
419 } else if (token == "\\bulletLaTeX") {
420 // The bullet class should be able to read this.
422 int const index = lex.getInteger();
424 string temp_str = lex.getString();
426 while (temp_str != "\\end_bullet") {
427 // this loop structure is needed when user
428 // enters an empty string since the first
429 // thing returned will be the \\end_bullet
431 // if the LaTeX entry has spaces. Each element
432 // therefore needs to be read in turn
435 temp_str = lex.getString();
438 user_defined_bullet(index).setText(sum_str);
439 temp_bullet(index).setText(sum_str);
440 } else if (token == "\\secnumdepth") {
442 secnumdepth = lex.getInteger();
443 } else if (token == "\\tocdepth") {
445 tocdepth = lex.getInteger();
446 } else if (token == "\\spacing") {
448 string const tmp = rtrim(lex.getString());
449 Spacing::Space tmp_space = Spacing::Default;
451 if (tmp == "single") {
452 tmp_space = Spacing::Single;
453 } else if (tmp == "onehalf") {
454 tmp_space = Spacing::Onehalf;
455 } else if (tmp == "double") {
456 tmp_space = Spacing::Double;
457 } else if (tmp == "other") {
459 tmp_space = Spacing::Other;
460 tmp_val = lex.getFloat();
462 lex.printError("Unknown spacing token: '$$Token'");
464 #if 0 // FIXME: Handled in lyx2lyx ?
465 // Small hack so that files written with klyx will be
468 par->params().spacing(Spacing(tmp_space, tmp_val));
470 spacing().set(tmp_space, tmp_val);
471 } else if (token == "\\float_placement") {
473 float_placement = lex.getString();
482 void BufferParams::writeFile(ostream & os) const
484 // The top of the file is written by the buffer.
485 // Prints out the buffer info into the .lyx file given by file
488 os << "\\textclass " << textclasslist[textclass].name() << '\n';
490 // then the the preamble
491 if (!preamble.empty()) {
492 // remove '\n' from the end of preamble
493 string const tmppreamble = rtrim(preamble, "\n");
494 os << "\\begin_preamble\n"
496 << "\n\\end_preamble\n";
500 if (!options.empty()) {
501 os << "\\options " << options << '\n';
504 /* then the text parameters */
505 if (language != ignore_language)
506 os << "\\language " << language->lang() << '\n';
507 os << "\\inputencoding " << inputenc
508 << "\n\\fontscheme " << fonts
509 << "\n\\graphics " << graphicsDriver << '\n';
511 if (!float_placement.empty()) {
512 os << "\\float_placement " << float_placement << '\n';
514 os << "\\paperfontsize " << fontsize << '\n';
516 spacing().writeFile(os);
518 os << "\\papersize " << string_papersize[papersize2]
519 << "\n\\paperpackage " << string_paperpackages[paperpackage]
520 << "\n\\use_geometry " << use_geometry
521 << "\n\\use_amsmath " << use_amsmath
522 << "\n\\use_natbib " << use_natbib
523 << "\n\\use_numerical_citations " << use_numerical_citations
524 << "\n\\paperorientation " << string_orientation[orientation]
527 std::list<Branch>::const_iterator it = branchlist().begin();
528 std::list<Branch>::const_iterator end = branchlist().end();
529 for (; it != end; ++it) {
530 os << "\\branch " << it->getBranch()
531 << "\n\\selected " << it->getSelected()
532 << "\n\\color " << it->getColor()
537 if (!paperwidth.empty())
538 os << "\\paperwidth "
539 << VSpace(paperwidth).asLyXCommand() << '\n';
540 if (!paperheight.empty())
541 os << "\\paperheight "
542 << VSpace(paperheight).asLyXCommand() << '\n';
543 if (!leftmargin.empty())
544 os << "\\leftmargin "
545 << VSpace(leftmargin).asLyXCommand() << '\n';
546 if (!topmargin.empty())
548 << VSpace(topmargin).asLyXCommand() << '\n';
549 if (!rightmargin.empty())
550 os << "\\rightmargin "
551 << VSpace(rightmargin).asLyXCommand() << '\n';
552 if (!bottommargin.empty())
553 os << "\\bottommargin "
554 << VSpace(bottommargin).asLyXCommand() << '\n';
555 if (!headheight.empty())
556 os << "\\headheight "
557 << VSpace(headheight).asLyXCommand() << '\n';
558 if (!headsep.empty())
560 << VSpace(headsep).asLyXCommand() << '\n';
561 if (!footskip.empty())
563 << VSpace(footskip).asLyXCommand() << '\n';
564 os << "\\secnumdepth " << secnumdepth
565 << "\n\\tocdepth " << tocdepth
566 << "\n\\paragraph_separation "
567 << string_paragraph_separation[paragraph_separation]
568 << "\n\\defskip " << getDefSkip().asLyXCommand()
569 << "\n\\quotes_language "
570 << string_quotes_language[quotes_language] << '\n';
571 switch (quotes_times) {
572 // An output operator for insetquotes would be nice
573 case InsetQuotes::SingleQ:
574 os << "\\quotes_times 1\n"; break;
575 case InsetQuotes::DoubleQ:
576 os << "\\quotes_times 2\n"; break;
578 os << "\\papercolumns " << columns
579 << "\n\\papersides " << sides
580 << "\n\\paperpagestyle " << pagestyle << '\n';
581 for (int i = 0; i < 4; ++i) {
582 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
583 if (user_defined_bullet(i).getFont() != -1) {
584 os << "\\bullet " << i
586 << user_defined_bullet(i).getFont()
588 << user_defined_bullet(i).getCharacter()
590 << user_defined_bullet(i).getSize()
591 << "\n\\end_bullet\n";
594 os << "\\bulletLaTeX " << i
596 << user_defined_bullet(i).getText()
597 << "\"\n\\end_bullet\n";
602 os << "\\tracking_changes " << tracking_changes << "\n";
604 if (tracking_changes) {
605 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
606 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
607 for (; it != end; ++it) {
608 os << "\\author " << it->second << "\n";
614 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
615 TexRow & texrow) const
617 os << "\\documentclass";
619 LyXTextClass const & tclass = getLyXTextClass();
621 ostringstream clsoptions; // the document class options.
623 if (tokenPos(tclass.opt_fontsize(),
624 '|', fontsize) >= 0) {
625 // only write if existing in list (and not default)
626 clsoptions << fontsize << "pt,";
631 (paperpackage == PACKAGE_NONE)) {
634 clsoptions << "a3paper,";
637 clsoptions << "a4paper,";
640 clsoptions << "letterpaper,";
643 clsoptions << "a5paper,";
646 clsoptions << "b5paper,";
648 case PAPER_EXECUTIVEPAPER:
649 clsoptions << "executivepaper,";
651 case PAPER_LEGALPAPER:
652 clsoptions << "legalpaper,";
660 if (sides != tclass.sides()) {
662 case LyXTextClass::OneSide:
663 clsoptions << "oneside,";
665 case LyXTextClass::TwoSides:
666 clsoptions << "twoside,";
672 if (columns != tclass.columns()) {
674 clsoptions << "twocolumn,";
676 clsoptions << "onecolumn,";
680 && orientation == ORIENTATION_LANDSCAPE)
681 clsoptions << "landscape,";
683 // language should be a parameter to \documentclass
684 if (language->babel() == "hebrew"
685 && default_language->babel() != "hebrew")
686 // This seems necessary
687 features.useLanguage(default_language);
689 ostringstream language_options;
690 bool const use_babel = features.useBabel();
692 language_options << features.getLanguages();
693 language_options << language->babel();
694 if (lyxrc.language_global_options)
695 clsoptions << language_options.str() << ',';
698 // the user-defined options
699 if (!options.empty()) {
700 clsoptions << options << ',';
703 string strOptions(clsoptions.str());
704 if (!strOptions.empty()) {
705 strOptions = rtrim(strOptions, ",");
706 os << '[' << strOptions << ']';
709 os << '{' << tclass.latexname() << "}\n";
711 // end of \documentclass defs
713 // font selection must be done before loading fontenc.sty
714 // The ae package is not needed when using OT1 font encoding.
715 if (fonts != "default" &&
716 (fonts != "ae" || lyxrc.fontenc != "default")) {
717 os << "\\usepackage{" << fonts << "}\n";
720 os << "\\usepackage{aecompl}\n";
724 // this one is not per buffer
725 if (lyxrc.fontenc != "default") {
726 os << "\\usepackage[" << lyxrc.fontenc
731 if (inputenc == "auto") {
732 string const doc_encoding =
733 language->encoding()->LatexName();
735 // Create a list with all the input encodings used
737 std::set<string> encodings =
738 features.getEncodingSet(doc_encoding);
740 os << "\\usepackage[";
741 std::copy(encodings.begin(), encodings.end(),
742 std::ostream_iterator<string>(os, ","));
743 os << doc_encoding << "]{inputenc}\n";
745 } else if (inputenc != "default") {
746 os << "\\usepackage[" << inputenc
751 // At the very beginning the text parameters.
752 if (paperpackage != PACKAGE_NONE) {
753 switch (paperpackage) {
757 os << "\\usepackage{a4}\n";
761 os << "\\usepackage{a4wide}\n";
764 case PACKAGE_WIDEMARGINSA4:
765 os << "\\usepackage[widemargins]{a4}\n";
771 os << "\\usepackage{geometry}\n";
773 os << "\\geometry{verbose";
774 if (orientation == ORIENTATION_LANDSCAPE)
776 switch (papersize2) {
777 case VM_PAPER_CUSTOM:
778 if (!paperwidth.empty())
781 if (!paperheight.empty())
782 os << ",paperheight="
785 case VM_PAPER_USLETTER:
786 os << ",letterpaper";
788 case VM_PAPER_USLEGAL:
791 case VM_PAPER_USEXECUTIVE:
792 os << ",executivepaper";
813 // default papersize ie VM_PAPER_DEFAULT
814 switch (lyxrc.default_papersize) {
815 case PAPER_DEFAULT: // keep compiler happy
817 os << ",letterpaper";
819 case PAPER_LEGALPAPER:
822 case PAPER_EXECUTIVEPAPER:
823 os << ",executivepaper";
839 if (!topmargin.empty())
840 os << ",tmargin=" << topmargin;
841 if (!bottommargin.empty())
842 os << ",bmargin=" << bottommargin;
843 if (!leftmargin.empty())
844 os << ",lmargin=" << leftmargin;
845 if (!rightmargin.empty())
846 os << ",rmargin=" << rightmargin;
847 if (!headheight.empty())
848 os << ",headheight=" << headheight;
849 if (!headsep.empty())
850 os << ",headsep=" << headsep;
851 if (!footskip.empty())
852 os << ",footskip=" << footskip;
857 if (tokenPos(tclass.opt_pagestyle(),
858 '|', pagestyle) >= 0) {
859 if (pagestyle == "fancy") {
860 os << "\\usepackage{fancyhdr}\n";
863 os << "\\pagestyle{" << pagestyle << "}\n";
867 if (secnumdepth != tclass.secnumdepth()) {
868 os << "\\setcounter{secnumdepth}{"
873 if (tocdepth != tclass.tocdepth()) {
874 os << "\\setcounter{tocdepth}{"
880 if (paragraph_separation) {
881 switch (getDefSkip().kind()) {
882 case VSpace::SMALLSKIP:
883 os << "\\setlength\\parskip{\\smallskipamount}\n";
885 case VSpace::MEDSKIP:
886 os << "\\setlength\\parskip{\\medskipamount}\n";
888 case VSpace::BIGSKIP:
889 os << "\\setlength\\parskip{\\bigskipamount}\n";
892 os << "\\setlength\\parskip{"
893 << getDefSkip().length().asLatexString()
896 default: // should never happen // Then delete it.
897 os << "\\setlength\\parskip{\\medskipamount}\n";
902 os << "\\setlength\\parindent{0pt}\n";
906 // Now insert the LyX specific LaTeX commands...
908 // The optional packages;
909 string lyxpreamble(features.getPackages());
911 // this might be useful...
912 lyxpreamble += "\n\\makeatletter\n";
914 // Some macros LyX will need
915 string tmppreamble(features.getMacros());
917 if (!tmppreamble.empty()) {
918 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
919 "LyX specific LaTeX commands.\n"
920 + tmppreamble + '\n';
923 // the text class specific preamble
924 tmppreamble = features.getTClassPreamble();
925 if (!tmppreamble.empty()) {
926 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
927 "Textclass specific LaTeX commands.\n"
928 + tmppreamble + '\n';
931 /* the user-defined preamble */
932 if (!preamble.empty()) {
933 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
934 "User specified LaTeX commands.\n"
938 // Itemize bullet settings need to be last in case the user
939 // defines their own bullets that use a package included
940 // in the user-defined preamble -- ARRae
941 // Actually it has to be done much later than that
942 // since some packages like frenchb make modifications
943 // at \begin{document} time -- JMarc
945 for (int i = 0; i < 4; ++i) {
946 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
947 if (bullets_def.empty())
948 bullets_def="\\AtBeginDocument{\n";
949 bullets_def += " \\renewcommand{\\labelitemi";
951 // `i' is one less than the item to modify
964 bullets_def += "}{" +
965 user_defined_bullet(i).getText()
970 if (!bullets_def.empty())
971 lyxpreamble += bullets_def + "}\n\n";
973 // We try to load babel late, in case it interferes
974 // with other packages.
976 string tmp = lyxrc.language_package;
977 if (!lyxrc.language_global_options
978 && tmp == "\\usepackage{babel}")
979 tmp = string("\\usepackage[") +
980 language_options.str() +
982 lyxpreamble += tmp + "\n";
983 lyxpreamble += features.getBabelOptions();
986 lyxpreamble += "\\makeatother\n";
988 // dvipost settings come after everything else
989 if (tracking_changes) {
992 "\\dvipost{osstart color push Red}\n"
993 "\\dvipost{osend color pop}\n"
994 "\\dvipost{cbstart color push Blue}\n"
995 "\\dvipost{cbend color pop} \n";
999 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1000 for (int j = 0; j != nlines; ++j) {
1008 void BufferParams::setPaperStuff()
1010 papersize = PAPER_DEFAULT;
1011 char const c1 = paperpackage;
1012 if (c1 == PACKAGE_NONE) {
1013 char const c2 = papersize2;
1014 if (c2 == VM_PAPER_USLETTER)
1015 papersize = PAPER_USLETTER;
1016 else if (c2 == VM_PAPER_USLEGAL)
1017 papersize = PAPER_LEGALPAPER;
1018 else if (c2 == VM_PAPER_USEXECUTIVE)
1019 papersize = PAPER_EXECUTIVEPAPER;
1020 else if (c2 == VM_PAPER_A3)
1021 papersize = PAPER_A3PAPER;
1022 else if (c2 == VM_PAPER_A4)
1023 papersize = PAPER_A4PAPER;
1024 else if (c2 == VM_PAPER_A5)
1025 papersize = PAPER_A5PAPER;
1026 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1027 (c2 == VM_PAPER_B5))
1028 papersize = PAPER_B5PAPER;
1029 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1030 (c1 == PACKAGE_WIDEMARGINSA4))
1031 papersize = PAPER_A4PAPER;
1035 void BufferParams::useClassDefaults()
1037 LyXTextClass const & tclass = textclasslist[textclass];
1039 sides = tclass.sides();
1040 columns = tclass.columns();
1041 pagestyle = tclass.pagestyle();
1042 options = tclass.options();
1043 secnumdepth = tclass.secnumdepth();
1044 tocdepth = tclass.tocdepth();
1048 bool BufferParams::hasClassDefaults() const
1050 LyXTextClass const & tclass = textclasslist[textclass];
1052 return (sides == tclass.sides()
1053 && columns == tclass.columns()
1054 && pagestyle == tclass.pagestyle()
1055 && options == tclass.options()
1056 && secnumdepth == tclass.secnumdepth()
1057 && tocdepth == tclass.tocdepth());
1061 LyXTextClass const & BufferParams::getLyXTextClass() const
1063 return textclasslist[textclass];
1067 void BufferParams::readPreamble(LyXLex & lex)
1069 if (lex.getString() != "\\begin_preamble")
1070 lyxerr << "Error (BufferParams::readPreamble):"
1071 "consistency check failed." << endl;
1073 preamble = lex.getLongString("\\end_preamble");
1077 void BufferParams::readLanguage(LyXLex & lex)
1079 if (!lex.next()) return;
1081 string const tmptok = lex.getString();
1083 // check if tmptok is part of tex_babel in tex-defs.h
1084 language = languages.getLanguage(tmptok);
1086 // Language tmptok was not found
1087 language = default_language;
1088 lyxerr << "Warning: Setting language `"
1089 << tmptok << "' to `" << language->lang()
1095 void BufferParams::readGraphicsDriver(LyXLex & lex)
1097 if (!lex.next()) return;
1099 string const tmptok = lex.getString();
1100 // check if tmptok is part of tex_graphics in tex_defs.h
1103 string const test = tex_graphics[n++];
1105 if (test == tmptok) {
1106 graphicsDriver = tmptok;
1108 } else if (test == "last_item") {
1110 "Warning: graphics driver `$$Token' not recognized!\n"
1111 " Setting graphics driver to `default'.\n");
1112 graphicsDriver = "default";
1119 string const BufferParams::paperSizeName() const
1121 char real_papersize = papersize;
1122 if (real_papersize == PAPER_DEFAULT)
1123 real_papersize = lyxrc.default_papersize;
1125 switch (real_papersize) {
1134 case PAPER_EXECUTIVEPAPER:
1136 case PAPER_LEGALPAPER:
1138 case PAPER_USLETTER:
1145 string const BufferParams::dvips_options() const
1150 && papersize2 == VM_PAPER_CUSTOM
1151 && !lyxrc.print_paper_dimension_flag.empty()
1152 && !paperwidth.empty()
1153 && !paperheight.empty()) {
1154 // using a custom papersize
1155 result = lyxrc.print_paper_dimension_flag;
1156 result += ' ' + paperwidth;
1157 result += ',' + paperheight;
1159 string const paper_option = paperSizeName();
1160 if (paper_option != "letter" ||
1161 orientation != ORIENTATION_LANDSCAPE) {
1162 // dvips won't accept -t letter -t landscape.
1163 // In all other cases, include the paper size
1165 result = lyxrc.print_paper_flag;
1166 result += ' ' + paper_option;
1169 if (orientation == ORIENTATION_LANDSCAPE &&
1170 papersize2 != VM_PAPER_CUSTOM)
1171 result += ' ' + lyxrc.print_landscape_flag;