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 Branch * branch_ptr = branchlist().find(branch);
337 if (tok == "\\selected") {
340 branch_ptr->setSelected(lex.getInteger());
342 // not yet operational
343 if (tok == "\\color") {
345 string color = lex.getString();
347 branch_ptr->setColor(color);
348 // Update also the LColor table:
350 color = lcolor.getX11Name(LColor::background);
351 lcolor.setColor(lcolor.getFromLyXName(branch), color);
354 } else if (token == "\\author") {
356 istringstream ss(lex.getString());
359 author_map.push_back(pimpl_->authorlist.record(a));
360 } else if (token == "\\paperorientation") {
361 int tmpret = lex.findToken(string_orientation);
365 static_cast<PAPER_ORIENTATION>(tmpret);
366 } else if (token == "\\paperwidth") {
368 paperwidth = lex.getString();
369 } else if (token == "\\paperheight") {
371 paperheight = lex.getString();
372 } else if (token == "\\leftmargin") {
374 leftmargin = lex.getString();
375 } else if (token == "\\topmargin") {
377 topmargin = lex.getString();
378 } else if (token == "\\rightmargin") {
380 rightmargin = lex.getString();
381 } else if (token == "\\bottommargin") {
383 bottommargin = lex.getString();
384 } else if (token == "\\headheight") {
386 headheight = lex.getString();
387 } else if (token == "\\headsep") {
389 headsep = lex.getString();
390 } else if (token == "\\footskip") {
392 footskip = lex.getString();
393 } else if (token == "\\paperfontsize") {
395 fontsize = rtrim(lex.getString());
396 } else if (token == "\\papercolumns") {
398 columns = lex.getInteger();
399 } else if (token == "\\papersides") {
401 switch (lex.getInteger()) {
403 case 1: sides = LyXTextClass::OneSide; break;
404 case 2: sides = LyXTextClass::TwoSides; break;
406 } else if (token == "\\paperpagestyle") {
408 pagestyle = rtrim(lex.getString());
409 } else if (token == "\\bullet") {
410 // FIXME: should be params.readBullets()
412 int const index = lex.getInteger();
414 int temp_int = lex.getInteger();
415 user_defined_bullet(index).setFont(temp_int);
416 temp_bullet(index).setFont(temp_int);
418 temp_int = lex.getInteger();
419 user_defined_bullet(index).setCharacter(temp_int);
420 temp_bullet(index).setCharacter(temp_int);
422 temp_int = lex.getInteger();
423 user_defined_bullet(index).setSize(temp_int);
424 temp_bullet(index).setSize(temp_int);
426 string const temp_str = lex.getString();
427 if (temp_str != "\\end_bullet") {
428 // this element isn't really necessary for
429 // parsing but is easier for humans
430 // to understand bullets. Put it back and
431 // set a debug message?
432 lex.printError("\\end_bullet expected, got" + temp_str);
433 //how can I put it back?
435 } else if (token == "\\bulletLaTeX") {
436 // The bullet class should be able to read this.
438 int const index = lex.getInteger();
440 string temp_str = lex.getString();
442 while (temp_str != "\\end_bullet") {
443 // this loop structure is needed when user
444 // enters an empty string since the first
445 // thing returned will be the \\end_bullet
447 // if the LaTeX entry has spaces. Each element
448 // therefore needs to be read in turn
451 temp_str = lex.getString();
454 user_defined_bullet(index).setText(sum_str);
455 temp_bullet(index).setText(sum_str);
456 } else if (token == "\\secnumdepth") {
458 secnumdepth = lex.getInteger();
459 } else if (token == "\\tocdepth") {
461 tocdepth = lex.getInteger();
462 } else if (token == "\\spacing") {
464 string const tmp = rtrim(lex.getString());
465 Spacing::Space tmp_space = Spacing::Default;
467 if (tmp == "single") {
468 tmp_space = Spacing::Single;
469 } else if (tmp == "onehalf") {
470 tmp_space = Spacing::Onehalf;
471 } else if (tmp == "double") {
472 tmp_space = Spacing::Double;
473 } else if (tmp == "other") {
475 tmp_space = Spacing::Other;
476 tmp_val = lex.getFloat();
478 lex.printError("Unknown spacing token: '$$Token'");
480 #if 0 // FIXME: Handled in lyx2lyx ?
481 // Small hack so that files written with klyx will be
484 par->params().spacing(Spacing(tmp_space, tmp_val));
486 spacing().set(tmp_space, tmp_val);
487 } else if (token == "\\float_placement") {
489 float_placement = lex.getString();
498 void BufferParams::writeFile(ostream & os) const
500 // The top of the file is written by the buffer.
501 // Prints out the buffer info into the .lyx file given by file
504 os << "\\textclass " << textclasslist[textclass].name() << '\n';
506 // then the the preamble
507 if (!preamble.empty()) {
508 // remove '\n' from the end of preamble
509 string const tmppreamble = rtrim(preamble, "\n");
510 os << "\\begin_preamble\n"
512 << "\n\\end_preamble\n";
516 if (!options.empty()) {
517 os << "\\options " << options << '\n';
520 /* then the text parameters */
521 if (language != ignore_language)
522 os << "\\language " << language->lang() << '\n';
523 os << "\\inputencoding " << inputenc
524 << "\n\\fontscheme " << fonts
525 << "\n\\graphics " << graphicsDriver << '\n';
527 if (!float_placement.empty()) {
528 os << "\\float_placement " << float_placement << '\n';
530 os << "\\paperfontsize " << fontsize << '\n';
532 spacing().writeFile(os);
534 os << "\\papersize " << string_papersize[papersize2]
535 << "\n\\paperpackage " << string_paperpackages[paperpackage]
536 << "\n\\use_geometry " << use_geometry
537 << "\n\\use_amsmath " << use_amsmath
538 << "\n\\use_natbib " << use_natbib
539 << "\n\\use_numerical_citations " << use_numerical_citations
540 << "\n\\paperorientation " << string_orientation[orientation]
543 std::list<Branch>::const_iterator it = branchlist().begin();
544 std::list<Branch>::const_iterator end = branchlist().end();
545 for (; it != end; ++it) {
546 os << "\\branch " << it->getBranch()
547 << "\n\\selected " << it->getSelected()
548 << "\n\\color " << it->getColor()
553 if (!paperwidth.empty())
554 os << "\\paperwidth "
555 << VSpace(paperwidth).asLyXCommand() << '\n';
556 if (!paperheight.empty())
557 os << "\\paperheight "
558 << VSpace(paperheight).asLyXCommand() << '\n';
559 if (!leftmargin.empty())
560 os << "\\leftmargin "
561 << VSpace(leftmargin).asLyXCommand() << '\n';
562 if (!topmargin.empty())
564 << VSpace(topmargin).asLyXCommand() << '\n';
565 if (!rightmargin.empty())
566 os << "\\rightmargin "
567 << VSpace(rightmargin).asLyXCommand() << '\n';
568 if (!bottommargin.empty())
569 os << "\\bottommargin "
570 << VSpace(bottommargin).asLyXCommand() << '\n';
571 if (!headheight.empty())
572 os << "\\headheight "
573 << VSpace(headheight).asLyXCommand() << '\n';
574 if (!headsep.empty())
576 << VSpace(headsep).asLyXCommand() << '\n';
577 if (!footskip.empty())
579 << VSpace(footskip).asLyXCommand() << '\n';
580 os << "\\secnumdepth " << secnumdepth
581 << "\n\\tocdepth " << tocdepth
582 << "\n\\paragraph_separation "
583 << string_paragraph_separation[paragraph_separation]
584 << "\n\\defskip " << getDefSkip().asLyXCommand()
585 << "\n\\quotes_language "
586 << string_quotes_language[quotes_language] << '\n';
587 switch (quotes_times) {
588 // An output operator for insetquotes would be nice
589 case InsetQuotes::SingleQ:
590 os << "\\quotes_times 1\n"; break;
591 case InsetQuotes::DoubleQ:
592 os << "\\quotes_times 2\n"; break;
594 os << "\\papercolumns " << columns
595 << "\n\\papersides " << sides
596 << "\n\\paperpagestyle " << pagestyle << '\n';
597 for (int i = 0; i < 4; ++i) {
598 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
599 if (user_defined_bullet(i).getFont() != -1) {
600 os << "\\bullet " << i
602 << user_defined_bullet(i).getFont()
604 << user_defined_bullet(i).getCharacter()
606 << user_defined_bullet(i).getSize()
607 << "\n\\end_bullet\n";
610 os << "\\bulletLaTeX " << i
612 << user_defined_bullet(i).getText()
613 << "\"\n\\end_bullet\n";
618 os << "\\tracking_changes " << tracking_changes << "\n";
620 if (tracking_changes) {
621 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
622 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
623 for (; it != end; ++it) {
624 os << "\\author " << it->second << "\n";
630 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
631 TexRow & texrow) const
633 os << "\\documentclass";
635 LyXTextClass const & tclass = getLyXTextClass();
637 ostringstream clsoptions; // the document class options.
639 if (tokenPos(tclass.opt_fontsize(),
640 '|', fontsize) >= 0) {
641 // only write if existing in list (and not default)
642 clsoptions << fontsize << "pt,";
647 (paperpackage == PACKAGE_NONE)) {
650 clsoptions << "a3paper,";
653 clsoptions << "a4paper,";
656 clsoptions << "letterpaper,";
659 clsoptions << "a5paper,";
662 clsoptions << "b5paper,";
664 case PAPER_EXECUTIVEPAPER:
665 clsoptions << "executivepaper,";
667 case PAPER_LEGALPAPER:
668 clsoptions << "legalpaper,";
676 if (sides != tclass.sides()) {
678 case LyXTextClass::OneSide:
679 clsoptions << "oneside,";
681 case LyXTextClass::TwoSides:
682 clsoptions << "twoside,";
688 if (columns != tclass.columns()) {
690 clsoptions << "twocolumn,";
692 clsoptions << "onecolumn,";
696 && orientation == ORIENTATION_LANDSCAPE)
697 clsoptions << "landscape,";
699 // language should be a parameter to \documentclass
700 if (language->babel() == "hebrew"
701 && default_language->babel() != "hebrew")
702 // This seems necessary
703 features.useLanguage(default_language);
705 ostringstream language_options;
706 bool const use_babel = features.useBabel();
708 language_options << features.getLanguages();
709 language_options << language->babel();
710 if (lyxrc.language_global_options)
711 clsoptions << language_options.str() << ',';
714 // the user-defined options
715 if (!options.empty()) {
716 clsoptions << options << ',';
719 string strOptions(clsoptions.str());
720 if (!strOptions.empty()) {
721 strOptions = rtrim(strOptions, ",");
722 os << '[' << strOptions << ']';
725 os << '{' << tclass.latexname() << "}\n";
727 // end of \documentclass defs
729 // font selection must be done before loading fontenc.sty
730 // The ae package is not needed when using OT1 font encoding.
731 if (fonts != "default" &&
732 (fonts != "ae" || lyxrc.fontenc != "default")) {
733 os << "\\usepackage{" << fonts << "}\n";
736 os << "\\usepackage{aecompl}\n";
740 // this one is not per buffer
741 if (lyxrc.fontenc != "default") {
742 os << "\\usepackage[" << lyxrc.fontenc
747 if (inputenc == "auto") {
748 string const doc_encoding =
749 language->encoding()->LatexName();
751 // Create a list with all the input encodings used
753 std::set<string> encodings =
754 features.getEncodingSet(doc_encoding);
756 os << "\\usepackage[";
757 std::copy(encodings.begin(), encodings.end(),
758 std::ostream_iterator<string>(os, ","));
759 os << doc_encoding << "]{inputenc}\n";
761 } else if (inputenc != "default") {
762 os << "\\usepackage[" << inputenc
767 // At the very beginning the text parameters.
768 if (paperpackage != PACKAGE_NONE) {
769 switch (paperpackage) {
773 os << "\\usepackage{a4}\n";
777 os << "\\usepackage{a4wide}\n";
780 case PACKAGE_WIDEMARGINSA4:
781 os << "\\usepackage[widemargins]{a4}\n";
787 os << "\\usepackage{geometry}\n";
789 os << "\\geometry{verbose";
790 if (orientation == ORIENTATION_LANDSCAPE)
792 switch (papersize2) {
793 case VM_PAPER_CUSTOM:
794 if (!paperwidth.empty())
797 if (!paperheight.empty())
798 os << ",paperheight="
801 case VM_PAPER_USLETTER:
802 os << ",letterpaper";
804 case VM_PAPER_USLEGAL:
807 case VM_PAPER_USEXECUTIVE:
808 os << ",executivepaper";
829 // default papersize ie VM_PAPER_DEFAULT
830 switch (lyxrc.default_papersize) {
831 case PAPER_DEFAULT: // keep compiler happy
833 os << ",letterpaper";
835 case PAPER_LEGALPAPER:
838 case PAPER_EXECUTIVEPAPER:
839 os << ",executivepaper";
855 if (!topmargin.empty())
856 os << ",tmargin=" << topmargin;
857 if (!bottommargin.empty())
858 os << ",bmargin=" << bottommargin;
859 if (!leftmargin.empty())
860 os << ",lmargin=" << leftmargin;
861 if (!rightmargin.empty())
862 os << ",rmargin=" << rightmargin;
863 if (!headheight.empty())
864 os << ",headheight=" << headheight;
865 if (!headsep.empty())
866 os << ",headsep=" << headsep;
867 if (!footskip.empty())
868 os << ",footskip=" << footskip;
873 if (tokenPos(tclass.opt_pagestyle(),
874 '|', pagestyle) >= 0) {
875 if (pagestyle == "fancy") {
876 os << "\\usepackage{fancyhdr}\n";
879 os << "\\pagestyle{" << pagestyle << "}\n";
883 if (secnumdepth != tclass.secnumdepth()) {
884 os << "\\setcounter{secnumdepth}{"
889 if (tocdepth != tclass.tocdepth()) {
890 os << "\\setcounter{tocdepth}{"
896 if (paragraph_separation) {
897 switch (getDefSkip().kind()) {
898 case VSpace::SMALLSKIP:
899 os << "\\setlength\\parskip{\\smallskipamount}\n";
901 case VSpace::MEDSKIP:
902 os << "\\setlength\\parskip{\\medskipamount}\n";
904 case VSpace::BIGSKIP:
905 os << "\\setlength\\parskip{\\bigskipamount}\n";
908 os << "\\setlength\\parskip{"
909 << getDefSkip().length().asLatexString()
912 default: // should never happen // Then delete it.
913 os << "\\setlength\\parskip{\\medskipamount}\n";
918 os << "\\setlength\\parindent{0pt}\n";
922 // Now insert the LyX specific LaTeX commands...
924 // The optional packages;
925 string lyxpreamble(features.getPackages());
927 // this might be useful...
928 lyxpreamble += "\n\\makeatletter\n";
930 // Some macros LyX will need
931 string tmppreamble(features.getMacros());
933 if (!tmppreamble.empty()) {
934 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
935 "LyX specific LaTeX commands.\n"
936 + tmppreamble + '\n';
939 // the text class specific preamble
940 tmppreamble = features.getTClassPreamble();
941 if (!tmppreamble.empty()) {
942 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
943 "Textclass specific LaTeX commands.\n"
944 + tmppreamble + '\n';
947 /* the user-defined preamble */
948 if (!preamble.empty()) {
949 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
950 "User specified LaTeX commands.\n"
954 // Itemize bullet settings need to be last in case the user
955 // defines their own bullets that use a package included
956 // in the user-defined preamble -- ARRae
957 // Actually it has to be done much later than that
958 // since some packages like frenchb make modifications
959 // at \begin{document} time -- JMarc
961 for (int i = 0; i < 4; ++i) {
962 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
963 if (bullets_def.empty())
964 bullets_def="\\AtBeginDocument{\n";
965 bullets_def += " \\renewcommand{\\labelitemi";
967 // `i' is one less than the item to modify
980 bullets_def += "}{" +
981 user_defined_bullet(i).getText()
986 if (!bullets_def.empty())
987 lyxpreamble += bullets_def + "}\n\n";
989 // We try to load babel late, in case it interferes
990 // with other packages.
992 string tmp = lyxrc.language_package;
993 if (!lyxrc.language_global_options
994 && tmp == "\\usepackage{babel}")
995 tmp = string("\\usepackage[") +
996 language_options.str() +
998 lyxpreamble += tmp + "\n";
999 lyxpreamble += features.getBabelOptions();
1002 lyxpreamble += "\\makeatother\n";
1004 // dvipost settings come after everything else
1005 if (tracking_changes) {
1008 "\\dvipost{osstart color push Red}\n"
1009 "\\dvipost{osend color pop}\n"
1010 "\\dvipost{cbstart color push Blue}\n"
1011 "\\dvipost{cbend color pop} \n";
1015 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1016 for (int j = 0; j != nlines; ++j) {
1024 void BufferParams::setPaperStuff()
1026 papersize = PAPER_DEFAULT;
1027 char const c1 = paperpackage;
1028 if (c1 == PACKAGE_NONE) {
1029 char const c2 = papersize2;
1030 if (c2 == VM_PAPER_USLETTER)
1031 papersize = PAPER_USLETTER;
1032 else if (c2 == VM_PAPER_USLEGAL)
1033 papersize = PAPER_LEGALPAPER;
1034 else if (c2 == VM_PAPER_USEXECUTIVE)
1035 papersize = PAPER_EXECUTIVEPAPER;
1036 else if (c2 == VM_PAPER_A3)
1037 papersize = PAPER_A3PAPER;
1038 else if (c2 == VM_PAPER_A4)
1039 papersize = PAPER_A4PAPER;
1040 else if (c2 == VM_PAPER_A5)
1041 papersize = PAPER_A5PAPER;
1042 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1043 (c2 == VM_PAPER_B5))
1044 papersize = PAPER_B5PAPER;
1045 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1046 (c1 == PACKAGE_WIDEMARGINSA4))
1047 papersize = PAPER_A4PAPER;
1051 void BufferParams::useClassDefaults()
1053 LyXTextClass const & tclass = textclasslist[textclass];
1055 sides = tclass.sides();
1056 columns = tclass.columns();
1057 pagestyle = tclass.pagestyle();
1058 options = tclass.options();
1059 secnumdepth = tclass.secnumdepth();
1060 tocdepth = tclass.tocdepth();
1064 bool BufferParams::hasClassDefaults() const
1066 LyXTextClass const & tclass = textclasslist[textclass];
1068 return (sides == tclass.sides()
1069 && columns == tclass.columns()
1070 && pagestyle == tclass.pagestyle()
1071 && options == tclass.options()
1072 && secnumdepth == tclass.secnumdepth()
1073 && tocdepth == tclass.tocdepth());
1077 LyXTextClass const & BufferParams::getLyXTextClass() const
1079 return textclasslist[textclass];
1083 void BufferParams::readPreamble(LyXLex & lex)
1085 if (lex.getString() != "\\begin_preamble")
1086 lyxerr << "Error (BufferParams::readPreamble):"
1087 "consistency check failed." << endl;
1089 preamble = lex.getLongString("\\end_preamble");
1093 void BufferParams::readLanguage(LyXLex & lex)
1095 if (!lex.next()) return;
1097 string const tmptok = lex.getString();
1099 // check if tmptok is part of tex_babel in tex-defs.h
1100 language = languages.getLanguage(tmptok);
1102 // Language tmptok was not found
1103 language = default_language;
1104 lyxerr << "Warning: Setting language `"
1105 << tmptok << "' to `" << language->lang()
1111 void BufferParams::readGraphicsDriver(LyXLex & lex)
1113 if (!lex.next()) return;
1115 string const tmptok = lex.getString();
1116 // check if tmptok is part of tex_graphics in tex_defs.h
1119 string const test = tex_graphics[n++];
1121 if (test == tmptok) {
1122 graphicsDriver = tmptok;
1124 } else if (test == "last_item") {
1126 "Warning: graphics driver `$$Token' not recognized!\n"
1127 " Setting graphics driver to `default'.\n");
1128 graphicsDriver = "default";
1135 string const BufferParams::paperSizeName() const
1137 char real_papersize = papersize;
1138 if (real_papersize == PAPER_DEFAULT)
1139 real_papersize = lyxrc.default_papersize;
1141 switch (real_papersize) {
1150 case PAPER_EXECUTIVEPAPER:
1152 case PAPER_LEGALPAPER:
1154 case PAPER_USLETTER:
1161 string const BufferParams::dvips_options() const
1166 && papersize2 == VM_PAPER_CUSTOM
1167 && !lyxrc.print_paper_dimension_flag.empty()
1168 && !paperwidth.empty()
1169 && !paperheight.empty()) {
1170 // using a custom papersize
1171 result = lyxrc.print_paper_dimension_flag;
1172 result += ' ' + paperwidth;
1173 result += ',' + paperheight;
1175 string const paper_option = paperSizeName();
1176 if (paper_option != "letter" ||
1177 orientation != ORIENTATION_LANDSCAPE) {
1178 // dvips won't accept -t letter -t landscape.
1179 // In all other cases, include the paper size
1181 result = lyxrc.print_paper_flag;
1182 result += ' ' + paper_option;
1185 if (orientation == ORIENTATION_LANDSCAPE &&
1186 papersize2 != VM_PAPER_CUSTOM)
1187 result += ' ' + lyxrc.print_landscape_flag;