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;
118 tracking_changes = false;
121 language = default_language;
124 graphicsDriver = "default";
125 sides = LyXTextClass::OneSide;
127 pagestyle = "default";
129 for (int iter = 0; iter < 4; ++iter) {
130 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
131 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
136 BufferParams::~BufferParams()
140 AuthorList & BufferParams::authors()
142 return pimpl_->authorlist;
146 AuthorList const & BufferParams::authors() const
148 return pimpl_->authorlist;
152 BranchList & BufferParams::branchlist()
154 return pimpl_->branchlist;
158 BranchList const & BufferParams::branchlist() const
160 return pimpl_->branchlist;
164 Bullet & BufferParams::temp_bullet(lyx::size_type index)
166 BOOST_ASSERT(index < 4);
167 return pimpl_->temp_bullets[index];
171 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
173 BOOST_ASSERT(index < 4);
174 return pimpl_->temp_bullets[index];
178 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
180 BOOST_ASSERT(index < 4);
181 return pimpl_->user_defined_bullets[index];
185 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
187 BOOST_ASSERT(index < 4);
188 return pimpl_->user_defined_bullets[index];
192 Spacing & BufferParams::spacing()
194 return pimpl_->spacing;
198 Spacing const & BufferParams::spacing() const
200 return pimpl_->spacing;
204 VSpace const & BufferParams::getDefSkip() const
206 return pimpl_->defskip;
210 void BufferParams::setDefSkip(VSpace const & vs)
212 pimpl_->defskip = vs;
216 string const BufferParams::readToken(LyXLex & lex, string const & token)
218 if (token == "\\textclass") {
220 string const classname = lex.getString();
221 pair<bool, lyx::textclass_type> pp =
222 textclasslist.NumberOfClass(classname);
224 textclass = pp.second;
229 if (!getLyXTextClass().isTeXClassAvailable()) {
230 string msg = bformat(_("The document uses a missing "
231 "TeX class \"%1$s\".\n"), classname);
232 Alert::warning(_("Document class not available"),
233 msg + _("LyX will not be able to produce output."));
235 } else if (token == "\\begin_preamble") {
237 } else if (token == "\\options") {
239 options = lex.getString();
240 } else if (token == "\\language") {
242 } else if (token == "\\inputencoding") {
244 inputenc = lex.getString();
245 } else if (token == "\\graphics") {
246 readGraphicsDriver(lex);
247 } else if (token == "\\fontscheme") {
249 fonts = lex.getString();
250 } else if (token == "\\paragraph_separation") {
251 int tmpret = lex.findToken(string_paragraph_separation);
254 paragraph_separation =
255 static_cast<PARSEP>(tmpret);
256 } else if (token == "\\defskip") {
258 pimpl_->defskip = VSpace(lex.getString());
259 } else if (token == "\\quotes_language") {
260 // FIXME: should be params.readQuotes()
261 int tmpret = lex.findToken(string_quotes_language);
264 InsetQuotes::quote_language tmpl =
265 InsetQuotes::EnglishQ;
268 tmpl = InsetQuotes::EnglishQ;
271 tmpl = InsetQuotes::SwedishQ;
274 tmpl = InsetQuotes::GermanQ;
277 tmpl = InsetQuotes::PolishQ;
280 tmpl = InsetQuotes::FrenchQ;
283 tmpl = InsetQuotes::DanishQ;
286 quotes_language = tmpl;
287 } else if (token == "\\quotes_times") {
288 // FIXME: should be params.readQuotes()
290 switch (lex.getInteger()) {
292 quotes_times = InsetQuotes::SingleQ;
295 quotes_times = InsetQuotes::DoubleQ;
298 } else if (token == "\\papersize") {
299 int tmpret = lex.findToken(string_papersize);
303 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
304 } else if (token == "\\paperpackage") {
305 int tmpret = lex.findToken(string_paperpackages);
308 paperpackage = PACKAGE_NONE;
310 paperpackage = PAPER_PACKAGES(tmpret);
311 } else if (token == "\\use_geometry") {
313 use_geometry = lex.getInteger();
314 } else if (token == "\\use_amsmath") {
316 use_amsmath = static_cast<AMS>(
318 } else if (token == "\\use_natbib") {
320 use_natbib = lex.getInteger();
321 } else if (token == "\\use_numerical_citations") {
323 use_numerical_citations = lex.getInteger();
324 } else if (token == "\\tracking_changes") {
326 tracking_changes = lex.getInteger();
327 } else if (token == "\\branch") {
329 string branch = lex.getString();
330 branchlist().add(branch);
333 string const tok = lex.getString();
334 if (tok == "\\end_branch")
336 if (tok == "\\selected") {
338 branchlist().setSelected(branch, lex.getInteger());
340 // not yet operational
341 if (tok == "\\color") {
343 string color = lex.getString();
344 branchlist().setColor(branch, color);
345 // Update also the LColor table:
347 color = lcolor.getX11Name(LColor::background);
348 lcolor.fill(static_cast<LColor::color>(lcolor.size()),
352 } else if (token == "\\author") {
354 istringstream ss(lex.getString());
357 author_map.push_back(pimpl_->authorlist.record(a));
358 } else if (token == "\\paperorientation") {
359 int tmpret = lex.findToken(string_orientation);
363 static_cast<PAPER_ORIENTATION>(tmpret);
364 } else if (token == "\\paperwidth") {
366 paperwidth = lex.getString();
367 } else if (token == "\\paperheight") {
369 paperheight = lex.getString();
370 } else if (token == "\\leftmargin") {
372 leftmargin = lex.getString();
373 } else if (token == "\\topmargin") {
375 topmargin = lex.getString();
376 } else if (token == "\\rightmargin") {
378 rightmargin = lex.getString();
379 } else if (token == "\\bottommargin") {
381 bottommargin = lex.getString();
382 } else if (token == "\\headheight") {
384 headheight = lex.getString();
385 } else if (token == "\\headsep") {
387 headsep = lex.getString();
388 } else if (token == "\\footskip") {
390 footskip = lex.getString();
391 } else if (token == "\\paperfontsize") {
393 fontsize = rtrim(lex.getString());
394 } else if (token == "\\papercolumns") {
396 columns = lex.getInteger();
397 } else if (token == "\\papersides") {
399 switch (lex.getInteger()) {
401 case 1: sides = LyXTextClass::OneSide; break;
402 case 2: sides = LyXTextClass::TwoSides; break;
404 } else if (token == "\\paperpagestyle") {
406 pagestyle = rtrim(lex.getString());
407 } else if (token == "\\bullet") {
408 // FIXME: should be params.readBullets()
410 int const index = lex.getInteger();
412 int temp_int = lex.getInteger();
413 user_defined_bullet(index).setFont(temp_int);
414 temp_bullet(index).setFont(temp_int);
416 temp_int = lex.getInteger();
417 user_defined_bullet(index).setCharacter(temp_int);
418 temp_bullet(index).setCharacter(temp_int);
420 temp_int = lex.getInteger();
421 user_defined_bullet(index).setSize(temp_int);
422 temp_bullet(index).setSize(temp_int);
424 string const temp_str = lex.getString();
425 if (temp_str != "\\end_bullet") {
426 // this element isn't really necessary for
427 // parsing but is easier for humans
428 // to understand bullets. Put it back and
429 // set a debug message?
430 lex.printError("\\end_bullet expected, got" + temp_str);
431 //how can I put it back?
433 } else if (token == "\\bulletLaTeX") {
434 // The bullet class should be able to read this.
436 int const index = lex.getInteger();
438 string temp_str = lex.getString();
440 while (temp_str != "\\end_bullet") {
441 // this loop structure is needed when user
442 // enters an empty string since the first
443 // thing returned will be the \\end_bullet
445 // if the LaTeX entry has spaces. Each element
446 // therefore needs to be read in turn
449 temp_str = lex.getString();
452 user_defined_bullet(index).setText(sum_str);
453 temp_bullet(index).setText(sum_str);
454 } else if (token == "\\secnumdepth") {
456 secnumdepth = lex.getInteger();
457 } else if (token == "\\tocdepth") {
459 tocdepth = lex.getInteger();
460 } else if (token == "\\spacing") {
462 string const tmp = rtrim(lex.getString());
463 Spacing::Space tmp_space = Spacing::Default;
465 if (tmp == "single") {
466 tmp_space = Spacing::Single;
467 } else if (tmp == "onehalf") {
468 tmp_space = Spacing::Onehalf;
469 } else if (tmp == "double") {
470 tmp_space = Spacing::Double;
471 } else if (tmp == "other") {
473 tmp_space = Spacing::Other;
474 tmp_val = lex.getFloat();
476 lex.printError("Unknown spacing token: '$$Token'");
478 #if 0 // FIXME: Handled in lyx2lyx ?
479 // Small hack so that files written with klyx will be
482 par->params().spacing(Spacing(tmp_space, tmp_val));
484 spacing().set(tmp_space, tmp_val);
485 } else if (token == "\\float_placement") {
487 float_placement = lex.getString();
496 void BufferParams::writeFile(ostream & os) const
498 // The top of the file is written by the buffer.
499 // Prints out the buffer info into the .lyx file given by file
502 os << "\\textclass " << textclasslist[textclass].name() << '\n';
504 // then the the preamble
505 if (!preamble.empty()) {
506 // remove '\n' from the end of preamble
507 string const tmppreamble = rtrim(preamble, "\n");
508 os << "\\begin_preamble\n"
510 << "\n\\end_preamble\n";
514 if (!options.empty()) {
515 os << "\\options " << options << '\n';
518 /* then the text parameters */
519 if (language != ignore_language)
520 os << "\\language " << language->lang() << '\n';
521 os << "\\inputencoding " << inputenc
522 << "\n\\fontscheme " << fonts
523 << "\n\\graphics " << graphicsDriver << '\n';
525 if (!float_placement.empty()) {
526 os << "\\float_placement " << float_placement << '\n';
528 os << "\\paperfontsize " << fontsize << '\n';
530 spacing().writeFile(os);
532 os << "\\papersize " << string_papersize[papersize2]
533 << "\n\\paperpackage " << string_paperpackages[paperpackage]
534 << "\n\\use_geometry " << use_geometry
535 << "\n\\use_amsmath " << use_amsmath
536 << "\n\\use_natbib " << use_natbib
537 << "\n\\use_numerical_citations " << use_numerical_citations
538 << "\n\\paperorientation " << string_orientation[orientation]
541 std::list<Branch>::const_iterator it = branchlist().begin();
542 std::list<Branch>::const_iterator end = branchlist().end();
543 for (; it != end; ++it) {
544 os << "\\branch " << it->getBranch()
545 << "\n\\selected " << it->getSelected()
546 << "\n\\color " << it->getColor()
551 if (!paperwidth.empty())
552 os << "\\paperwidth "
553 << VSpace(paperwidth).asLyXCommand() << '\n';
554 if (!paperheight.empty())
555 os << "\\paperheight "
556 << VSpace(paperheight).asLyXCommand() << '\n';
557 if (!leftmargin.empty())
558 os << "\\leftmargin "
559 << VSpace(leftmargin).asLyXCommand() << '\n';
560 if (!topmargin.empty())
562 << VSpace(topmargin).asLyXCommand() << '\n';
563 if (!rightmargin.empty())
564 os << "\\rightmargin "
565 << VSpace(rightmargin).asLyXCommand() << '\n';
566 if (!bottommargin.empty())
567 os << "\\bottommargin "
568 << VSpace(bottommargin).asLyXCommand() << '\n';
569 if (!headheight.empty())
570 os << "\\headheight "
571 << VSpace(headheight).asLyXCommand() << '\n';
572 if (!headsep.empty())
574 << VSpace(headsep).asLyXCommand() << '\n';
575 if (!footskip.empty())
577 << VSpace(footskip).asLyXCommand() << '\n';
578 os << "\\secnumdepth " << secnumdepth
579 << "\n\\tocdepth " << tocdepth
580 << "\n\\paragraph_separation "
581 << string_paragraph_separation[paragraph_separation]
582 << "\n\\defskip " << getDefSkip().asLyXCommand()
583 << "\n\\quotes_language "
584 << string_quotes_language[quotes_language] << '\n';
585 switch (quotes_times) {
586 // An output operator for insetquotes would be nice
587 case InsetQuotes::SingleQ:
588 os << "\\quotes_times 1\n"; break;
589 case InsetQuotes::DoubleQ:
590 os << "\\quotes_times 2\n"; break;
592 os << "\\papercolumns " << columns
593 << "\n\\papersides " << sides
594 << "\n\\paperpagestyle " << pagestyle << '\n';
595 for (int i = 0; i < 4; ++i) {
596 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
597 if (user_defined_bullet(i).getFont() != -1) {
598 os << "\\bullet " << i
600 << user_defined_bullet(i).getFont()
602 << user_defined_bullet(i).getCharacter()
604 << user_defined_bullet(i).getSize()
605 << "\n\\end_bullet\n";
608 os << "\\bulletLaTeX " << i
610 << user_defined_bullet(i).getText()
611 << "\"\n\\end_bullet\n";
616 os << "\\tracking_changes " << tracking_changes << "\n";
618 if (tracking_changes) {
619 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
620 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
621 for (; it != end; ++it) {
622 os << "\\author " << it->second << "\n";
628 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
629 TexRow & texrow) const
631 os << "\\documentclass";
633 LyXTextClass const & tclass = getLyXTextClass();
635 ostringstream clsoptions; // the document class options.
637 if (tokenPos(tclass.opt_fontsize(),
638 '|', fontsize) >= 0) {
639 // only write if existing in list (and not default)
640 clsoptions << fontsize << "pt,";
645 (paperpackage == PACKAGE_NONE)) {
648 clsoptions << "a3paper,";
651 clsoptions << "a4paper,";
654 clsoptions << "letterpaper,";
657 clsoptions << "a5paper,";
660 clsoptions << "b5paper,";
662 case PAPER_EXECUTIVEPAPER:
663 clsoptions << "executivepaper,";
665 case PAPER_LEGALPAPER:
666 clsoptions << "legalpaper,";
674 if (sides != tclass.sides()) {
676 case LyXTextClass::OneSide:
677 clsoptions << "oneside,";
679 case LyXTextClass::TwoSides:
680 clsoptions << "twoside,";
686 if (columns != tclass.columns()) {
688 clsoptions << "twocolumn,";
690 clsoptions << "onecolumn,";
694 && orientation == ORIENTATION_LANDSCAPE)
695 clsoptions << "landscape,";
697 // language should be a parameter to \documentclass
698 if (language->babel() == "hebrew"
699 && default_language->babel() != "hebrew")
700 // This seems necessary
701 features.useLanguage(default_language);
703 ostringstream language_options;
704 bool const use_babel = features.useBabel();
706 language_options << features.getLanguages();
707 language_options << language->babel();
708 if (lyxrc.language_global_options)
709 clsoptions << language_options.str() << ',';
712 // the user-defined options
713 if (!options.empty()) {
714 clsoptions << options << ',';
717 string strOptions(clsoptions.str());
718 if (!strOptions.empty()) {
719 strOptions = rtrim(strOptions, ",");
720 os << '[' << strOptions << ']';
723 os << '{' << tclass.latexname() << "}\n";
725 // end of \documentclass defs
727 // font selection must be done before loading fontenc.sty
728 // The ae package is not needed when using OT1 font encoding.
729 if (fonts != "default" &&
730 (fonts != "ae" || lyxrc.fontenc != "default")) {
731 os << "\\usepackage{" << fonts << "}\n";
734 os << "\\usepackage{aecompl}\n";
738 // this one is not per buffer
739 if (lyxrc.fontenc != "default") {
740 os << "\\usepackage[" << lyxrc.fontenc
745 if (inputenc == "auto") {
746 string const doc_encoding =
747 language->encoding()->LatexName();
749 // Create a list with all the input encodings used
751 std::set<string> encodings =
752 features.getEncodingSet(doc_encoding);
754 os << "\\usepackage[";
755 std::copy(encodings.begin(), encodings.end(),
756 std::ostream_iterator<string>(os, ","));
757 os << doc_encoding << "]{inputenc}\n";
759 } else if (inputenc != "default") {
760 os << "\\usepackage[" << inputenc
765 // At the very beginning the text parameters.
766 if (paperpackage != PACKAGE_NONE) {
767 switch (paperpackage) {
771 os << "\\usepackage{a4}\n";
775 os << "\\usepackage{a4wide}\n";
778 case PACKAGE_WIDEMARGINSA4:
779 os << "\\usepackage[widemargins]{a4}\n";
785 os << "\\usepackage{geometry}\n";
787 os << "\\geometry{verbose";
788 if (orientation == ORIENTATION_LANDSCAPE)
790 switch (papersize2) {
791 case VM_PAPER_CUSTOM:
792 if (!paperwidth.empty())
795 if (!paperheight.empty())
796 os << ",paperheight="
799 case VM_PAPER_USLETTER:
800 os << ",letterpaper";
802 case VM_PAPER_USLEGAL:
805 case VM_PAPER_USEXECUTIVE:
806 os << ",executivepaper";
827 // default papersize ie VM_PAPER_DEFAULT
828 switch (lyxrc.default_papersize) {
829 case PAPER_DEFAULT: // keep compiler happy
831 os << ",letterpaper";
833 case PAPER_LEGALPAPER:
836 case PAPER_EXECUTIVEPAPER:
837 os << ",executivepaper";
853 if (!topmargin.empty())
854 os << ",tmargin=" << topmargin;
855 if (!bottommargin.empty())
856 os << ",bmargin=" << bottommargin;
857 if (!leftmargin.empty())
858 os << ",lmargin=" << leftmargin;
859 if (!rightmargin.empty())
860 os << ",rmargin=" << rightmargin;
861 if (!headheight.empty())
862 os << ",headheight=" << headheight;
863 if (!headsep.empty())
864 os << ",headsep=" << headsep;
865 if (!footskip.empty())
866 os << ",footskip=" << footskip;
871 if (tokenPos(tclass.opt_pagestyle(),
872 '|', pagestyle) >= 0) {
873 if (pagestyle == "fancy") {
874 os << "\\usepackage{fancyhdr}\n";
877 os << "\\pagestyle{" << pagestyle << "}\n";
881 if (secnumdepth != tclass.secnumdepth()) {
882 os << "\\setcounter{secnumdepth}{"
887 if (tocdepth != tclass.tocdepth()) {
888 os << "\\setcounter{tocdepth}{"
894 if (paragraph_separation) {
895 switch (getDefSkip().kind()) {
896 case VSpace::SMALLSKIP:
897 os << "\\setlength\\parskip{\\smallskipamount}\n";
899 case VSpace::MEDSKIP:
900 os << "\\setlength\\parskip{\\medskipamount}\n";
902 case VSpace::BIGSKIP:
903 os << "\\setlength\\parskip{\\bigskipamount}\n";
906 os << "\\setlength\\parskip{"
907 << getDefSkip().length().asLatexString()
910 default: // should never happen // Then delete it.
911 os << "\\setlength\\parskip{\\medskipamount}\n";
916 os << "\\setlength\\parindent{0pt}\n";
920 // Now insert the LyX specific LaTeX commands...
922 // The optional packages;
923 string lyxpreamble(features.getPackages());
925 // this might be useful...
926 lyxpreamble += "\n\\makeatletter\n";
928 // Some macros LyX will need
929 string tmppreamble(features.getMacros());
931 if (!tmppreamble.empty()) {
932 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
933 "LyX specific LaTeX commands.\n"
934 + tmppreamble + '\n';
937 // the text class specific preamble
938 tmppreamble = features.getTClassPreamble();
939 if (!tmppreamble.empty()) {
940 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
941 "Textclass specific LaTeX commands.\n"
942 + tmppreamble + '\n';
945 /* the user-defined preamble */
946 if (!preamble.empty()) {
947 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
948 "User specified LaTeX commands.\n"
952 // Itemize bullet settings need to be last in case the user
953 // defines their own bullets that use a package included
954 // in the user-defined preamble -- ARRae
955 // Actually it has to be done much later than that
956 // since some packages like frenchb make modifications
957 // at \begin{document} time -- JMarc
959 for (int i = 0; i < 4; ++i) {
960 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
961 if (bullets_def.empty())
962 bullets_def="\\AtBeginDocument{\n";
963 bullets_def += " \\renewcommand{\\labelitemi";
965 // `i' is one less than the item to modify
978 bullets_def += "}{" +
979 user_defined_bullet(i).getText()
984 if (!bullets_def.empty())
985 lyxpreamble += bullets_def + "}\n\n";
987 // We try to load babel late, in case it interferes
988 // with other packages.
990 string tmp = lyxrc.language_package;
991 if (!lyxrc.language_global_options
992 && tmp == "\\usepackage{babel}")
993 tmp = string("\\usepackage[") +
994 language_options.str() +
996 lyxpreamble += tmp + "\n";
997 lyxpreamble += features.getBabelOptions();
1000 lyxpreamble += "\\makeatother\n";
1002 // dvipost settings come after everything else
1003 if (tracking_changes) {
1006 "\\dvipost{osstart color push Red}\n"
1007 "\\dvipost{osend color pop}\n"
1008 "\\dvipost{cbstart color push Blue}\n"
1009 "\\dvipost{cbend color pop} \n";
1013 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1014 for (int j = 0; j != nlines; ++j) {
1022 void BufferParams::setPaperStuff()
1024 papersize = PAPER_DEFAULT;
1025 char const c1 = paperpackage;
1026 if (c1 == PACKAGE_NONE) {
1027 char const c2 = papersize2;
1028 if (c2 == VM_PAPER_USLETTER)
1029 papersize = PAPER_USLETTER;
1030 else if (c2 == VM_PAPER_USLEGAL)
1031 papersize = PAPER_LEGALPAPER;
1032 else if (c2 == VM_PAPER_USEXECUTIVE)
1033 papersize = PAPER_EXECUTIVEPAPER;
1034 else if (c2 == VM_PAPER_A3)
1035 papersize = PAPER_A3PAPER;
1036 else if (c2 == VM_PAPER_A4)
1037 papersize = PAPER_A4PAPER;
1038 else if (c2 == VM_PAPER_A5)
1039 papersize = PAPER_A5PAPER;
1040 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1041 (c2 == VM_PAPER_B5))
1042 papersize = PAPER_B5PAPER;
1043 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1044 (c1 == PACKAGE_WIDEMARGINSA4))
1045 papersize = PAPER_A4PAPER;
1049 void BufferParams::useClassDefaults()
1051 LyXTextClass const & tclass = textclasslist[textclass];
1053 sides = tclass.sides();
1054 columns = tclass.columns();
1055 pagestyle = tclass.pagestyle();
1056 options = tclass.options();
1057 secnumdepth = tclass.secnumdepth();
1058 tocdepth = tclass.tocdepth();
1062 bool BufferParams::hasClassDefaults() const
1064 LyXTextClass const & tclass = textclasslist[textclass];
1066 return (sides == tclass.sides()
1067 && columns == tclass.columns()
1068 && pagestyle == tclass.pagestyle()
1069 && options == tclass.options()
1070 && secnumdepth == tclass.secnumdepth()
1071 && tocdepth == tclass.tocdepth());
1075 LyXTextClass const & BufferParams::getLyXTextClass() const
1077 return textclasslist[textclass];
1081 void BufferParams::readPreamble(LyXLex & lex)
1083 if (lex.getString() != "\\begin_preamble")
1084 lyxerr << "Error (BufferParams::readPreamble):"
1085 "consistency check failed." << endl;
1087 preamble = lex.getLongString("\\end_preamble");
1091 void BufferParams::readLanguage(LyXLex & lex)
1093 if (!lex.next()) return;
1095 string const tmptok = lex.getString();
1097 // check if tmptok is part of tex_babel in tex-defs.h
1098 language = languages.getLanguage(tmptok);
1100 // Language tmptok was not found
1101 language = default_language;
1102 lyxerr << "Warning: Setting language `"
1103 << tmptok << "' to `" << language->lang()
1109 void BufferParams::readGraphicsDriver(LyXLex & lex)
1111 if (!lex.next()) return;
1113 string const tmptok = lex.getString();
1114 // check if tmptok is part of tex_graphics in tex_defs.h
1117 string const test = tex_graphics[n++];
1119 if (test == tmptok) {
1120 graphicsDriver = tmptok;
1122 } else if (test == "last_item") {
1124 "Warning: graphics driver `$$Token' not recognized!\n"
1125 " Setting graphics driver to `default'.\n");
1126 graphicsDriver = "default";
1133 string const BufferParams::paperSizeName() const
1135 char real_papersize = papersize;
1136 if (real_papersize == PAPER_DEFAULT)
1137 real_papersize = lyxrc.default_papersize;
1139 switch (real_papersize) {
1148 case PAPER_EXECUTIVEPAPER:
1150 case PAPER_LEGALPAPER:
1152 case PAPER_USLETTER:
1159 string const BufferParams::dvips_options() const
1164 && papersize2 == VM_PAPER_CUSTOM
1165 && !lyxrc.print_paper_dimension_flag.empty()
1166 && !paperwidth.empty()
1167 && !paperheight.empty()) {
1168 // using a custom papersize
1169 result = lyxrc.print_paper_dimension_flag;
1170 result += ' ' + paperwidth;
1171 result += ',' + paperheight;
1173 string const paper_option = paperSizeName();
1174 if (paper_option != "letter" ||
1175 orientation != ORIENTATION_LANDSCAPE) {
1176 // dvips won't accept -t letter -t landscape.
1177 // In all other cases, include the paper size
1179 result = lyxrc.print_paper_flag;
1180 result += ' ' + paper_option;
1183 if (orientation == ORIENTATION_LANDSCAPE &&
1184 papersize2 != VM_PAPER_CUSTOM)
1185 result += ' ' + lyxrc.print_landscape_flag;