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));
83 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
85 return new BufferParams::Impl(*ptr);
89 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
95 BufferParams::BufferParams()
96 : // Initialize textclass to point to article. if `first' is
97 // true in the returned pair, then `second' is the textclass
98 // number; if it is false, second is 0. In both cases, second
100 textclass(textclasslist.NumberOfClass("article").second),
103 paragraph_separation = PARSEP_INDENT;
104 quotes_language = InsetQuotes::EnglishQ;
105 quotes_times = InsetQuotes::DoubleQ;
106 fontsize = "default";
109 papersize = PAPER_DEFAULT;
110 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
111 paperpackage = PACKAGE_NONE;
112 orientation = ORIENTATION_PORTRAIT;
113 use_geometry = false;
114 use_amsmath = AMS_AUTO;
116 use_numerical_citations = false;
117 tracking_changes = false;
120 language = default_language;
123 graphicsDriver = "default";
124 sides = LyXTextClass::OneSide;
126 pagestyle = "default";
128 for (int iter = 0; iter < 4; ++iter) {
129 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
130 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
135 BufferParams::~BufferParams()
139 AuthorList & BufferParams::authors()
141 return pimpl_->authorlist;
145 AuthorList const & BufferParams::authors() const
147 return pimpl_->authorlist;
151 BranchList & BufferParams::branchlist()
153 return pimpl_->branchlist;
157 BranchList const & BufferParams::branchlist() const
159 return pimpl_->branchlist;
163 Bullet & BufferParams::temp_bullet(lyx::size_type index)
165 BOOST_ASSERT(index < 4);
166 return pimpl_->temp_bullets[index];
170 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
172 BOOST_ASSERT(index < 4);
173 return pimpl_->temp_bullets[index];
177 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
179 BOOST_ASSERT(index < 4);
180 return pimpl_->user_defined_bullets[index];
184 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
186 BOOST_ASSERT(index < 4);
187 return pimpl_->user_defined_bullets[index];
191 Spacing & BufferParams::spacing()
193 return pimpl_->spacing;
197 Spacing const & BufferParams::spacing() const
199 return pimpl_->spacing;
203 VSpace const & BufferParams::getDefSkip() const
205 return pimpl_->defskip;
209 void BufferParams::setDefSkip(VSpace const & vs)
211 pimpl_->defskip = vs;
215 string const BufferParams::readToken(LyXLex & lex, string const & token)
217 if (token == "\\textclass") {
219 string const classname = lex.getString();
220 pair<bool, lyx::textclass_type> pp =
221 textclasslist.NumberOfClass(classname);
223 textclass = pp.second;
228 if (!getLyXTextClass().isTeXClassAvailable()) {
229 string msg = bformat(_("The document uses a missing "
230 "TeX class \"%1$s\".\n"), classname);
231 Alert::warning(_("Document class not available"),
232 msg + _("LyX will not be able to produce output."));
234 } else if (token == "\\begin_preamble") {
236 } else if (token == "\\options") {
238 options = lex.getString();
239 } else if (token == "\\language") {
241 } else if (token == "\\inputencoding") {
243 inputenc = lex.getString();
244 } else if (token == "\\graphics") {
245 readGraphicsDriver(lex);
246 } else if (token == "\\fontscheme") {
248 fonts = lex.getString();
249 } else if (token == "\\paragraph_separation") {
250 int tmpret = lex.findToken(string_paragraph_separation);
253 paragraph_separation =
254 static_cast<PARSEP>(tmpret);
255 } else if (token == "\\defskip") {
257 pimpl_->defskip = VSpace(lex.getString());
258 } else if (token == "\\quotes_language") {
259 // FIXME: should be params.readQuotes()
260 int tmpret = lex.findToken(string_quotes_language);
263 InsetQuotes::quote_language tmpl =
264 InsetQuotes::EnglishQ;
267 tmpl = InsetQuotes::EnglishQ;
270 tmpl = InsetQuotes::SwedishQ;
273 tmpl = InsetQuotes::GermanQ;
276 tmpl = InsetQuotes::PolishQ;
279 tmpl = InsetQuotes::FrenchQ;
282 tmpl = InsetQuotes::DanishQ;
285 quotes_language = tmpl;
286 } else if (token == "\\quotes_times") {
287 // FIXME: should be params.readQuotes()
289 switch (lex.getInteger()) {
291 quotes_times = InsetQuotes::SingleQ;
294 quotes_times = InsetQuotes::DoubleQ;
297 } else if (token == "\\papersize") {
298 int tmpret = lex.findToken(string_papersize);
302 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
303 } else if (token == "\\paperpackage") {
304 int tmpret = lex.findToken(string_paperpackages);
307 paperpackage = PACKAGE_NONE;
309 paperpackage = PAPER_PACKAGES(tmpret);
310 } else if (token == "\\use_geometry") {
312 use_geometry = lex.getInteger();
313 } else if (token == "\\use_amsmath") {
315 use_amsmath = static_cast<AMS>(
317 } else if (token == "\\use_natbib") {
319 use_natbib = lex.getInteger();
320 } else if (token == "\\use_numerical_citations") {
322 use_numerical_citations = lex.getInteger();
323 } else if (token == "\\tracking_changes") {
325 tracking_changes = lex.getInteger();
326 } else if (token == "\\branch") {
328 string branch = lex.getString();
329 branchlist().add(branch);
332 string const tok = lex.getString();
333 if (tok == "\\end_branch")
335 if (tok == "\\selected") {
337 branchlist().setSelected(branch, lex.getInteger());
339 // not yet operational
340 if (tok == "\\color") {
342 string color = lex.getString();
343 branchlist().setColor(branch, color);
344 // Update also the LColor table:
346 color = lcolor.getX11Name(LColor::background);
347 lcolor.fill(static_cast<LColor::color>(lcolor.size()),
351 } else if (token == "\\author") {
353 istringstream ss(lex.getString());
356 author_map.push_back(pimpl_->authorlist.record(a));
357 } else if (token == "\\paperorientation") {
358 int tmpret = lex.findToken(string_orientation);
362 static_cast<PAPER_ORIENTATION>(tmpret);
363 } else if (token == "\\paperwidth") {
365 paperwidth = lex.getString();
366 } else if (token == "\\paperheight") {
368 paperheight = lex.getString();
369 } else if (token == "\\leftmargin") {
371 leftmargin = lex.getString();
372 } else if (token == "\\topmargin") {
374 topmargin = lex.getString();
375 } else if (token == "\\rightmargin") {
377 rightmargin = lex.getString();
378 } else if (token == "\\bottommargin") {
380 bottommargin = lex.getString();
381 } else if (token == "\\headheight") {
383 headheight = lex.getString();
384 } else if (token == "\\headsep") {
386 headsep = lex.getString();
387 } else if (token == "\\footskip") {
389 footskip = lex.getString();
390 } else if (token == "\\paperfontsize") {
392 fontsize = rtrim(lex.getString());
393 } else if (token == "\\papercolumns") {
395 columns = lex.getInteger();
396 } else if (token == "\\papersides") {
398 switch (lex.getInteger()) {
400 case 1: sides = LyXTextClass::OneSide; break;
401 case 2: sides = LyXTextClass::TwoSides; break;
403 } else if (token == "\\paperpagestyle") {
405 pagestyle = rtrim(lex.getString());
406 } else if (token == "\\bullet") {
407 // FIXME: should be params.readBullets()
409 int const index = lex.getInteger();
411 int temp_int = lex.getInteger();
412 user_defined_bullet(index).setFont(temp_int);
413 temp_bullet(index).setFont(temp_int);
415 temp_int = lex.getInteger();
416 user_defined_bullet(index).setCharacter(temp_int);
417 temp_bullet(index).setCharacter(temp_int);
419 temp_int = lex.getInteger();
420 user_defined_bullet(index).setSize(temp_int);
421 temp_bullet(index).setSize(temp_int);
423 string const temp_str = lex.getString();
424 if (temp_str != "\\end_bullet") {
425 // this element isn't really necessary for
426 // parsing but is easier for humans
427 // to understand bullets. Put it back and
428 // set a debug message?
429 lex.printError("\\end_bullet expected, got" + temp_str);
430 //how can I put it back?
432 } else if (token == "\\bulletLaTeX") {
433 // The bullet class should be able to read this.
435 int const index = lex.getInteger();
437 string temp_str = lex.getString();
439 while (temp_str != "\\end_bullet") {
440 // this loop structure is needed when user
441 // enters an empty string since the first
442 // thing returned will be the \\end_bullet
444 // if the LaTeX entry has spaces. Each element
445 // therefore needs to be read in turn
448 temp_str = lex.getString();
451 user_defined_bullet(index).setText(sum_str);
452 temp_bullet(index).setText(sum_str);
453 } else if (token == "\\secnumdepth") {
455 secnumdepth = lex.getInteger();
456 } else if (token == "\\tocdepth") {
458 tocdepth = lex.getInteger();
459 } else if (token == "\\spacing") {
461 string const tmp = rtrim(lex.getString());
462 Spacing::Space tmp_space = Spacing::Default;
464 if (tmp == "single") {
465 tmp_space = Spacing::Single;
466 } else if (tmp == "onehalf") {
467 tmp_space = Spacing::Onehalf;
468 } else if (tmp == "double") {
469 tmp_space = Spacing::Double;
470 } else if (tmp == "other") {
472 tmp_space = Spacing::Other;
473 tmp_val = lex.getFloat();
475 lex.printError("Unknown spacing token: '$$Token'");
477 #if 0 // FIXME: Handled in lyx2lyx ?
478 // Small hack so that files written with klyx will be
481 par->params().spacing(Spacing(tmp_space, tmp_val));
483 spacing().set(tmp_space, tmp_val);
484 } else if (token == "\\float_placement") {
486 float_placement = lex.getString();
495 void BufferParams::writeFile(ostream & os) const
497 // The top of the file is written by the buffer.
498 // Prints out the buffer info into the .lyx file given by file
501 os << "\\textclass " << textclasslist[textclass].name() << '\n';
503 // then the the preamble
504 if (!preamble.empty()) {
505 // remove '\n' from the end of preamble
506 string const tmppreamble = rtrim(preamble, "\n");
507 os << "\\begin_preamble\n"
509 << "\n\\end_preamble\n";
513 if (!options.empty()) {
514 os << "\\options " << options << '\n';
517 /* then the text parameters */
518 if (language != ignore_language)
519 os << "\\language " << language->lang() << '\n';
520 os << "\\inputencoding " << inputenc
521 << "\n\\fontscheme " << fonts
522 << "\n\\graphics " << graphicsDriver << '\n';
524 if (!float_placement.empty()) {
525 os << "\\float_placement " << float_placement << '\n';
527 os << "\\paperfontsize " << fontsize << '\n';
529 spacing().writeFile(os);
531 os << "\\papersize " << string_papersize[papersize2]
532 << "\n\\paperpackage " << string_paperpackages[paperpackage]
533 << "\n\\use_geometry " << use_geometry
534 << "\n\\use_amsmath " << use_amsmath
535 << "\n\\use_natbib " << use_natbib
536 << "\n\\use_numerical_citations " << use_numerical_citations
537 << "\n\\paperorientation " << string_orientation[orientation]
540 std::list<Branch>::const_iterator it = branchlist().begin();
541 std::list<Branch>::const_iterator end = branchlist().end();
542 for (; it != end; ++it) {
543 os << "\\branch " << it->getBranch()
544 << "\n\\selected " << it->getSelected()
545 << "\n\\color " << it->getColor()
550 if (!paperwidth.empty())
551 os << "\\paperwidth "
552 << VSpace(paperwidth).asLyXCommand() << '\n';
553 if (!paperheight.empty())
554 os << "\\paperheight "
555 << VSpace(paperheight).asLyXCommand() << '\n';
556 if (!leftmargin.empty())
557 os << "\\leftmargin "
558 << VSpace(leftmargin).asLyXCommand() << '\n';
559 if (!topmargin.empty())
561 << VSpace(topmargin).asLyXCommand() << '\n';
562 if (!rightmargin.empty())
563 os << "\\rightmargin "
564 << VSpace(rightmargin).asLyXCommand() << '\n';
565 if (!bottommargin.empty())
566 os << "\\bottommargin "
567 << VSpace(bottommargin).asLyXCommand() << '\n';
568 if (!headheight.empty())
569 os << "\\headheight "
570 << VSpace(headheight).asLyXCommand() << '\n';
571 if (!headsep.empty())
573 << VSpace(headsep).asLyXCommand() << '\n';
574 if (!footskip.empty())
576 << VSpace(footskip).asLyXCommand() << '\n';
577 os << "\\secnumdepth " << secnumdepth
578 << "\n\\tocdepth " << tocdepth
579 << "\n\\paragraph_separation "
580 << string_paragraph_separation[paragraph_separation]
581 << "\n\\defskip " << getDefSkip().asLyXCommand()
582 << "\n\\quotes_language "
583 << string_quotes_language[quotes_language] << '\n';
584 switch (quotes_times) {
585 // An output operator for insetquotes would be nice
586 case InsetQuotes::SingleQ:
587 os << "\\quotes_times 1\n"; break;
588 case InsetQuotes::DoubleQ:
589 os << "\\quotes_times 2\n"; break;
591 os << "\\papercolumns " << columns
592 << "\n\\papersides " << sides
593 << "\n\\paperpagestyle " << pagestyle << '\n';
594 for (int i = 0; i < 4; ++i) {
595 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
596 if (user_defined_bullet(i).getFont() != -1) {
597 os << "\\bullet " << i
599 << user_defined_bullet(i).getFont()
601 << user_defined_bullet(i).getCharacter()
603 << user_defined_bullet(i).getSize()
604 << "\n\\end_bullet\n";
607 os << "\\bulletLaTeX " << i
609 << user_defined_bullet(i).getText()
610 << "\"\n\\end_bullet\n";
615 os << "\\tracking_changes " << tracking_changes << "\n";
617 if (tracking_changes) {
618 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
619 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
620 for (; it != end; ++it) {
621 os << "\\author " << it->second << "\n";
627 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
628 TexRow & texrow) const
630 os << "\\documentclass";
632 LyXTextClass const & tclass = getLyXTextClass();
634 ostringstream clsoptions; // the document class options.
636 if (tokenPos(tclass.opt_fontsize(),
637 '|', fontsize) >= 0) {
638 // only write if existing in list (and not default)
639 clsoptions << fontsize << "pt,";
644 (paperpackage == PACKAGE_NONE)) {
647 clsoptions << "a3paper,";
650 clsoptions << "a4paper,";
653 clsoptions << "letterpaper,";
656 clsoptions << "a5paper,";
659 clsoptions << "b5paper,";
661 case PAPER_EXECUTIVEPAPER:
662 clsoptions << "executivepaper,";
664 case PAPER_LEGALPAPER:
665 clsoptions << "legalpaper,";
673 if (sides != tclass.sides()) {
675 case LyXTextClass::OneSide:
676 clsoptions << "oneside,";
678 case LyXTextClass::TwoSides:
679 clsoptions << "twoside,";
685 if (columns != tclass.columns()) {
687 clsoptions << "twocolumn,";
689 clsoptions << "onecolumn,";
693 && orientation == ORIENTATION_LANDSCAPE)
694 clsoptions << "landscape,";
696 // language should be a parameter to \documentclass
697 if (language->babel() == "hebrew"
698 && default_language->babel() != "hebrew")
699 // This seems necessary
700 features.useLanguage(default_language);
702 ostringstream language_options;
703 bool const use_babel = features.useBabel();
705 language_options << features.getLanguages();
706 language_options << language->babel();
707 if (lyxrc.language_global_options)
708 clsoptions << language_options.str() << ',';
711 // the user-defined options
712 if (!options.empty()) {
713 clsoptions << options << ',';
716 string strOptions(clsoptions.str());
717 if (!strOptions.empty()) {
718 strOptions = rtrim(strOptions, ",");
719 os << '[' << strOptions << ']';
722 os << '{' << tclass.latexname() << "}\n";
724 // end of \documentclass defs
726 // font selection must be done before loading fontenc.sty
727 // The ae package is not needed when using OT1 font encoding.
728 if (fonts != "default" &&
729 (fonts != "ae" || lyxrc.fontenc != "default")) {
730 os << "\\usepackage{" << fonts << "}\n";
733 os << "\\usepackage{aecompl}\n";
737 // this one is not per buffer
738 if (lyxrc.fontenc != "default") {
739 os << "\\usepackage[" << lyxrc.fontenc
744 if (inputenc == "auto") {
745 string const doc_encoding =
746 language->encoding()->LatexName();
748 // Create a list with all the input encodings used
750 std::set<string> encodings =
751 features.getEncodingSet(doc_encoding);
753 os << "\\usepackage[";
754 std::copy(encodings.begin(), encodings.end(),
755 std::ostream_iterator<string>(os, ","));
756 os << doc_encoding << "]{inputenc}\n";
758 } else if (inputenc != "default") {
759 os << "\\usepackage[" << inputenc
764 // At the very beginning the text parameters.
765 if (paperpackage != PACKAGE_NONE) {
766 switch (paperpackage) {
770 os << "\\usepackage{a4}\n";
774 os << "\\usepackage{a4wide}\n";
777 case PACKAGE_WIDEMARGINSA4:
778 os << "\\usepackage[widemargins]{a4}\n";
784 os << "\\usepackage{geometry}\n";
786 os << "\\geometry{verbose";
787 if (orientation == ORIENTATION_LANDSCAPE)
789 switch (papersize2) {
790 case VM_PAPER_CUSTOM:
791 if (!paperwidth.empty())
794 if (!paperheight.empty())
795 os << ",paperheight="
798 case VM_PAPER_USLETTER:
799 os << ",letterpaper";
801 case VM_PAPER_USLEGAL:
804 case VM_PAPER_USEXECUTIVE:
805 os << ",executivepaper";
826 // default papersize ie VM_PAPER_DEFAULT
827 switch (lyxrc.default_papersize) {
828 case PAPER_DEFAULT: // keep compiler happy
830 os << ",letterpaper";
832 case PAPER_LEGALPAPER:
835 case PAPER_EXECUTIVEPAPER:
836 os << ",executivepaper";
852 if (!topmargin.empty())
853 os << ",tmargin=" << topmargin;
854 if (!bottommargin.empty())
855 os << ",bmargin=" << bottommargin;
856 if (!leftmargin.empty())
857 os << ",lmargin=" << leftmargin;
858 if (!rightmargin.empty())
859 os << ",rmargin=" << rightmargin;
860 if (!headheight.empty())
861 os << ",headheight=" << headheight;
862 if (!headsep.empty())
863 os << ",headsep=" << headsep;
864 if (!footskip.empty())
865 os << ",footskip=" << footskip;
870 if (tokenPos(tclass.opt_pagestyle(),
871 '|', pagestyle) >= 0) {
872 if (pagestyle == "fancy") {
873 os << "\\usepackage{fancyhdr}\n";
876 os << "\\pagestyle{" << pagestyle << "}\n";
880 if (secnumdepth != tclass.secnumdepth()) {
881 os << "\\setcounter{secnumdepth}{"
886 if (tocdepth != tclass.tocdepth()) {
887 os << "\\setcounter{tocdepth}{"
893 if (paragraph_separation) {
894 switch (getDefSkip().kind()) {
895 case VSpace::SMALLSKIP:
896 os << "\\setlength\\parskip{\\smallskipamount}\n";
898 case VSpace::MEDSKIP:
899 os << "\\setlength\\parskip{\\medskipamount}\n";
901 case VSpace::BIGSKIP:
902 os << "\\setlength\\parskip{\\bigskipamount}\n";
905 os << "\\setlength\\parskip{"
906 << getDefSkip().length().asLatexString()
909 default: // should never happen // Then delete it.
910 os << "\\setlength\\parskip{\\medskipamount}\n";
915 os << "\\setlength\\parindent{0pt}\n";
919 // Now insert the LyX specific LaTeX commands...
921 // The optional packages;
922 string lyxpreamble(features.getPackages());
924 // this might be useful...
925 lyxpreamble += "\n\\makeatletter\n";
927 // Some macros LyX will need
928 string tmppreamble(features.getMacros());
930 if (!tmppreamble.empty()) {
931 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
932 "LyX specific LaTeX commands.\n"
933 + tmppreamble + '\n';
936 // the text class specific preamble
937 tmppreamble = features.getTClassPreamble();
938 if (!tmppreamble.empty()) {
939 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
940 "Textclass specific LaTeX commands.\n"
941 + tmppreamble + '\n';
944 /* the user-defined preamble */
945 if (!preamble.empty()) {
946 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
947 "User specified LaTeX commands.\n"
951 // Itemize bullet settings need to be last in case the user
952 // defines their own bullets that use a package included
953 // in the user-defined preamble -- ARRae
954 // Actually it has to be done much later than that
955 // since some packages like frenchb make modifications
956 // at \begin{document} time -- JMarc
958 for (int i = 0; i < 4; ++i) {
959 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
960 if (bullets_def.empty())
961 bullets_def="\\AtBeginDocument{\n";
962 bullets_def += " \\renewcommand{\\labelitemi";
964 // `i' is one less than the item to modify
977 bullets_def += "}{" +
978 user_defined_bullet(i).getText()
983 if (!bullets_def.empty())
984 lyxpreamble += bullets_def + "}\n\n";
986 // We try to load babel late, in case it interferes
987 // with other packages.
989 string tmp = lyxrc.language_package;
990 if (!lyxrc.language_global_options
991 && tmp == "\\usepackage{babel}")
992 tmp = string("\\usepackage[") +
993 language_options.str() +
995 lyxpreamble += tmp + "\n";
996 lyxpreamble += features.getBabelOptions();
999 lyxpreamble += "\\makeatother\n";
1001 // dvipost settings come after everything else
1002 if (tracking_changes) {
1005 "\\dvipost{osstart color push Red}\n"
1006 "\\dvipost{osend color pop}\n"
1007 "\\dvipost{cbstart color push Blue}\n"
1008 "\\dvipost{cbend color pop} \n";
1012 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1013 for (int j = 0; j != nlines; ++j) {
1021 void BufferParams::setPaperStuff()
1023 papersize = PAPER_DEFAULT;
1024 char const c1 = paperpackage;
1025 if (c1 == PACKAGE_NONE) {
1026 char const c2 = papersize2;
1027 if (c2 == VM_PAPER_USLETTER)
1028 papersize = PAPER_USLETTER;
1029 else if (c2 == VM_PAPER_USLEGAL)
1030 papersize = PAPER_LEGALPAPER;
1031 else if (c2 == VM_PAPER_USEXECUTIVE)
1032 papersize = PAPER_EXECUTIVEPAPER;
1033 else if (c2 == VM_PAPER_A3)
1034 papersize = PAPER_A3PAPER;
1035 else if (c2 == VM_PAPER_A4)
1036 papersize = PAPER_A4PAPER;
1037 else if (c2 == VM_PAPER_A5)
1038 papersize = PAPER_A5PAPER;
1039 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1040 (c2 == VM_PAPER_B5))
1041 papersize = PAPER_B5PAPER;
1042 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1043 (c1 == PACKAGE_WIDEMARGINSA4))
1044 papersize = PAPER_A4PAPER;
1048 void BufferParams::useClassDefaults()
1050 LyXTextClass const & tclass = textclasslist[textclass];
1052 sides = tclass.sides();
1053 columns = tclass.columns();
1054 pagestyle = tclass.pagestyle();
1055 options = tclass.options();
1056 secnumdepth = tclass.secnumdepth();
1057 tocdepth = tclass.tocdepth();
1061 bool BufferParams::hasClassDefaults() const
1063 LyXTextClass const & tclass = textclasslist[textclass];
1065 return (sides == tclass.sides()
1066 && columns == tclass.columns()
1067 && pagestyle == tclass.pagestyle()
1068 && options == tclass.options()
1069 && secnumdepth == tclass.secnumdepth()
1070 && tocdepth == tclass.tocdepth());
1074 LyXTextClass const & BufferParams::getLyXTextClass() const
1076 return textclasslist[textclass];
1080 void BufferParams::readPreamble(LyXLex & lex)
1082 if (lex.getString() != "\\begin_preamble")
1083 lyxerr << "Error (BufferParams::readPreamble):"
1084 "consistency check failed." << endl;
1086 preamble = lex.getLongString("\\end_preamble");
1090 void BufferParams::readLanguage(LyXLex & lex)
1092 if (!lex.next()) return;
1094 string const tmptok = lex.getString();
1096 // check if tmptok is part of tex_babel in tex-defs.h
1097 language = languages.getLanguage(tmptok);
1099 // Language tmptok was not found
1100 language = default_language;
1101 lyxerr << "Warning: Setting language `"
1102 << tmptok << "' to `" << language->lang()
1108 void BufferParams::readGraphicsDriver(LyXLex & lex)
1110 if (!lex.next()) return;
1112 string const tmptok = lex.getString();
1113 // check if tmptok is part of tex_graphics in tex_defs.h
1116 string const test = tex_graphics[n++];
1118 if (test == tmptok) {
1119 graphicsDriver = tmptok;
1121 } else if (test == "last_item") {
1123 "Warning: graphics driver `$$Token' not recognized!\n"
1124 " Setting graphics driver to `default'.\n");
1125 graphicsDriver = "default";
1132 string const BufferParams::paperSizeName() const
1134 char real_papersize = papersize;
1135 if (real_papersize == PAPER_DEFAULT)
1136 real_papersize = lyxrc.default_papersize;
1138 switch (real_papersize) {
1147 case PAPER_EXECUTIVEPAPER:
1149 case PAPER_LEGALPAPER:
1151 case PAPER_USLETTER:
1158 string const BufferParams::dvips_options() const
1163 && papersize2 == VM_PAPER_CUSTOM
1164 && !lyxrc.print_paper_dimension_flag.empty()
1165 && !paperwidth.empty()
1166 && !paperheight.empty()) {
1167 // using a custom papersize
1168 result = lyxrc.print_paper_dimension_flag;
1169 result += ' ' + paperwidth;
1170 result += ',' + paperheight;
1172 string const paper_option = paperSizeName();
1173 if (paper_option != "letter" ||
1174 orientation != ORIENTATION_LANDSCAPE) {
1175 // dvips won't accept -t letter -t landscape.
1176 // In all other cases, include the paper size
1178 result = lyxrc.print_paper_flag;
1179 result += ' ' + paper_option;
1182 if (orientation == ORIENTATION_LANDSCAPE &&
1183 papersize2 != VM_PAPER_CUSTOM)
1184 result += ' ' + lyxrc.print_landscape_flag;