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>
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;
58 namespace biblio = lyx::biblio;
61 struct BufferParams::Impl
65 AuthorList authorlist;
66 BranchList branchlist;
67 boost::array<Bullet, 4> temp_bullets;
68 boost::array<Bullet, 4> user_defined_bullets;
70 /** This is the amount of space used for paragraph_separation "skip",
71 * and for detached paragraphs in "indented" documents.
77 BufferParams::Impl::Impl()
78 : defskip(VSpace::MEDSKIP)
81 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
86 BufferParams::MemoryTraits::clone(BufferParams::Impl const * ptr)
88 return new BufferParams::Impl(*ptr);
92 void BufferParams::MemoryTraits::destroy(BufferParams::Impl * ptr)
98 BufferParams::BufferParams()
99 : // Initialize textclass to point to article. if `first' is
100 // true in the returned pair, then `second' is the textclass
101 // number; if it is false, second is 0. In both cases, second
103 textclass(textclasslist.NumberOfClass("article").second),
106 paragraph_separation = PARSEP_INDENT;
107 quotes_language = InsetQuotes::EnglishQ;
108 quotes_times = InsetQuotes::DoubleQ;
109 fontsize = "default";
112 papersize = PAPER_DEFAULT;
113 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
114 paperpackage = PACKAGE_NONE;
115 orientation = ORIENTATION_PORTRAIT;
116 use_geometry = false;
117 use_amsmath = AMS_AUTO;
118 cite_engine = biblio::ENGINE_BASIC;
119 use_bibtopic = false;
120 tracking_changes = false;
123 language = default_language;
126 graphicsDriver = "default";
127 sides = LyXTextClass::OneSide;
129 pagestyle = "default";
131 for (int iter = 0; iter < 4; ++iter) {
132 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
133 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
138 BufferParams::~BufferParams()
142 AuthorList & BufferParams::authors()
144 return pimpl_->authorlist;
148 AuthorList const & BufferParams::authors() const
150 return pimpl_->authorlist;
154 BranchList & BufferParams::branchlist()
156 return pimpl_->branchlist;
160 BranchList const & BufferParams::branchlist() const
162 return pimpl_->branchlist;
166 Bullet & BufferParams::temp_bullet(lyx::size_type index)
168 BOOST_ASSERT(index < 4);
169 return pimpl_->temp_bullets[index];
173 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
175 BOOST_ASSERT(index < 4);
176 return pimpl_->temp_bullets[index];
180 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
182 BOOST_ASSERT(index < 4);
183 return pimpl_->user_defined_bullets[index];
187 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
189 BOOST_ASSERT(index < 4);
190 return pimpl_->user_defined_bullets[index];
194 Spacing & BufferParams::spacing()
196 return pimpl_->spacing;
200 Spacing const & BufferParams::spacing() const
202 return pimpl_->spacing;
206 VSpace const & BufferParams::getDefSkip() const
208 return pimpl_->defskip;
212 void BufferParams::setDefSkip(VSpace const & vs)
214 pimpl_->defskip = vs;
218 string const BufferParams::readToken(LyXLex & lex, string const & token)
220 if (token == "\\textclass") {
222 string const classname = lex.getString();
223 pair<bool, lyx::textclass_type> pp =
224 textclasslist.NumberOfClass(classname);
226 textclass = pp.second;
231 if (!getLyXTextClass().isTeXClassAvailable()) {
232 string msg = bformat(_("The document uses a missing "
233 "TeX class \"%1$s\".\n"), classname);
234 Alert::warning(_("Document class not available"),
235 msg + _("LyX will not be able to produce output."));
237 } else if (token == "\\begin_preamble") {
239 } else if (token == "\\options") {
241 options = lex.getString();
242 } else if (token == "\\language") {
244 } else if (token == "\\inputencoding") {
246 inputenc = lex.getString();
247 } else if (token == "\\graphics") {
248 readGraphicsDriver(lex);
249 } else if (token == "\\fontscheme") {
251 fonts = lex.getString();
252 } else if (token == "\\paragraph_separation") {
253 int tmpret = lex.findToken(string_paragraph_separation);
256 paragraph_separation =
257 static_cast<PARSEP>(tmpret);
258 } else if (token == "\\defskip") {
260 pimpl_->defskip = VSpace(lex.getString());
261 } else if (token == "\\quotes_language") {
262 // FIXME: should be params.readQuotes()
263 int tmpret = lex.findToken(string_quotes_language);
266 InsetQuotes::quote_language tmpl =
267 InsetQuotes::EnglishQ;
270 tmpl = InsetQuotes::EnglishQ;
273 tmpl = InsetQuotes::SwedishQ;
276 tmpl = InsetQuotes::GermanQ;
279 tmpl = InsetQuotes::PolishQ;
282 tmpl = InsetQuotes::FrenchQ;
285 tmpl = InsetQuotes::DanishQ;
288 quotes_language = tmpl;
289 } else if (token == "\\quotes_times") {
290 // FIXME: should be params.readQuotes()
292 switch (lex.getInteger()) {
294 quotes_times = InsetQuotes::SingleQ;
297 quotes_times = InsetQuotes::DoubleQ;
300 } else if (token == "\\papersize") {
301 int tmpret = lex.findToken(string_papersize);
305 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
306 } else if (token == "\\paperpackage") {
307 int tmpret = lex.findToken(string_paperpackages);
310 paperpackage = PACKAGE_NONE;
312 paperpackage = PAPER_PACKAGES(tmpret);
313 } else if (token == "\\use_geometry") {
315 use_geometry = lex.getInteger();
316 } else if (token == "\\use_amsmath") {
318 use_amsmath = static_cast<AMS>(
320 } else if (token == "\\cite_engine") {
322 string const engine = lex.getString();
324 cite_engine = biblio::ENGINE_BASIC;
325 if (engine == "natbib_numerical")
326 cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
327 else if (engine == "natbib_authoryear")
328 cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
329 else if (engine == "jurabib")
330 cite_engine = biblio::ENGINE_JURABIB;
332 } else if (token == "\\use_bibtopic") {
334 use_bibtopic = lex.getInteger();
335 } else if (token == "\\tracking_changes") {
337 tracking_changes = lex.getInteger();
338 } else if (token == "\\branch") {
340 string branch = lex.getString();
341 branchlist().add(branch);
344 string const tok = lex.getString();
345 if (tok == "\\end_branch")
347 Branch * branch_ptr = branchlist().find(branch);
348 if (tok == "\\selected") {
351 branch_ptr->setSelected(lex.getInteger());
353 // not yet operational
354 if (tok == "\\color") {
356 string color = lex.getString();
358 branch_ptr->setColor(color);
359 // Update also the LColor table:
361 color = lcolor.getX11Name(LColor::background);
362 lcolor.setColor(branch, color);
366 } else if (token == "\\author") {
368 istringstream ss(lex.getString());
371 author_map.push_back(pimpl_->authorlist.record(a));
372 } else if (token == "\\paperorientation") {
373 int tmpret = lex.findToken(string_orientation);
377 static_cast<PAPER_ORIENTATION>(tmpret);
378 } else if (token == "\\paperwidth") {
380 paperwidth = lex.getString();
381 } else if (token == "\\paperheight") {
383 paperheight = lex.getString();
384 } else if (token == "\\leftmargin") {
386 leftmargin = lex.getString();
387 } else if (token == "\\topmargin") {
389 topmargin = lex.getString();
390 } else if (token == "\\rightmargin") {
392 rightmargin = lex.getString();
393 } else if (token == "\\bottommargin") {
395 bottommargin = lex.getString();
396 } else if (token == "\\headheight") {
398 headheight = lex.getString();
399 } else if (token == "\\headsep") {
401 headsep = lex.getString();
402 } else if (token == "\\footskip") {
404 footskip = lex.getString();
405 } else if (token == "\\paperfontsize") {
407 fontsize = lex.getString();
408 } else if (token == "\\papercolumns") {
410 columns = lex.getInteger();
411 } else if (token == "\\papersides") {
413 switch (lex.getInteger()) {
415 case 1: sides = LyXTextClass::OneSide; break;
416 case 2: sides = LyXTextClass::TwoSides; break;
418 } else if (token == "\\paperpagestyle") {
420 pagestyle = lex.getString();
421 } else if (token == "\\bullet") {
422 // FIXME: should be params.readBullets()
424 int const index = lex.getInteger();
426 int temp_int = lex.getInteger();
427 user_defined_bullet(index).setFont(temp_int);
428 temp_bullet(index).setFont(temp_int);
430 temp_int = lex.getInteger();
431 user_defined_bullet(index).setCharacter(temp_int);
432 temp_bullet(index).setCharacter(temp_int);
434 temp_int = lex.getInteger();
435 user_defined_bullet(index).setSize(temp_int);
436 temp_bullet(index).setSize(temp_int);
437 } else if (token == "\\bulletLaTeX") {
438 // The bullet class should be able to read this.
440 int const index = lex.getInteger();
442 string temp_str = lex.getString();
444 user_defined_bullet(index).setText(temp_str);
445 temp_bullet(index).setText(temp_str);
446 } else if (token == "\\secnumdepth") {
448 secnumdepth = lex.getInteger();
449 } else if (token == "\\tocdepth") {
451 tocdepth = lex.getInteger();
452 } else if (token == "\\spacing") {
454 string const tmp = lex.getString();
455 Spacing::Space tmp_space = Spacing::Default;
457 if (tmp == "single") {
458 tmp_space = Spacing::Single;
459 } else if (tmp == "onehalf") {
460 tmp_space = Spacing::Onehalf;
461 } else if (tmp == "double") {
462 tmp_space = Spacing::Double;
463 } else if (tmp == "other") {
465 tmp_space = Spacing::Other;
466 tmp_val = lex.getFloat();
468 lex.printError("Unknown spacing token: '$$Token'");
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 string cite_engine_str = "basic";
519 switch (cite_engine) {
520 case biblio::ENGINE_BASIC:
522 case biblio::ENGINE_NATBIB_NUMERICAL:
523 cite_engine_str = "natbib_numerical";
525 case biblio::ENGINE_NATBIB_AUTHORYEAR:
526 cite_engine_str = "natbib_authoryear";
528 case biblio::ENGINE_JURABIB:
529 cite_engine_str = "jurabib";
533 os << "\\papersize " << string_papersize[papersize2]
534 << "\n\\paperpackage " << string_paperpackages[paperpackage]
535 << "\n\\use_geometry " << use_geometry
536 << "\n\\use_amsmath " << use_amsmath
537 << "\n\\cite_engine " << cite_engine_str
538 << "\n\\use_bibtopic " << use_bibtopic
539 << "\n\\paperorientation " << string_orientation[orientation]
542 std::list<Branch>::const_iterator it = branchlist().begin();
543 std::list<Branch>::const_iterator end = branchlist().end();
544 for (; it != end; ++it) {
545 os << "\\branch " << it->getBranch()
546 << "\n\\selected " << it->getSelected()
547 << "\n\\color " << it->getColor()
552 if (!paperwidth.empty())
553 os << "\\paperwidth "
554 << VSpace(paperwidth).asLyXCommand() << '\n';
555 if (!paperheight.empty())
556 os << "\\paperheight "
557 << VSpace(paperheight).asLyXCommand() << '\n';
558 if (!leftmargin.empty())
559 os << "\\leftmargin "
560 << VSpace(leftmargin).asLyXCommand() << '\n';
561 if (!topmargin.empty())
563 << VSpace(topmargin).asLyXCommand() << '\n';
564 if (!rightmargin.empty())
565 os << "\\rightmargin "
566 << VSpace(rightmargin).asLyXCommand() << '\n';
567 if (!bottommargin.empty())
568 os << "\\bottommargin "
569 << VSpace(bottommargin).asLyXCommand() << '\n';
570 if (!headheight.empty())
571 os << "\\headheight "
572 << VSpace(headheight).asLyXCommand() << '\n';
573 if (!headsep.empty())
575 << VSpace(headsep).asLyXCommand() << '\n';
576 if (!footskip.empty())
578 << VSpace(footskip).asLyXCommand() << '\n';
579 os << "\\secnumdepth " << secnumdepth
580 << "\n\\tocdepth " << tocdepth
581 << "\n\\paragraph_separation "
582 << string_paragraph_separation[paragraph_separation]
583 << "\n\\defskip " << getDefSkip().asLyXCommand()
584 << "\n\\quotes_language "
585 << string_quotes_language[quotes_language] << '\n';
586 switch (quotes_times) {
587 // An output operator for insetquotes would be nice
588 case InsetQuotes::SingleQ:
589 os << "\\quotes_times 1\n"; break;
590 case InsetQuotes::DoubleQ:
591 os << "\\quotes_times 2\n"; break;
593 os << "\\papercolumns " << columns
594 << "\n\\papersides " << sides
595 << "\n\\paperpagestyle " << pagestyle << '\n';
596 for (int i = 0; i < 4; ++i) {
597 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
598 if (user_defined_bullet(i).getFont() != -1) {
599 os << "\\bullet " << i << " "
600 << user_defined_bullet(i).getFont() << " "
601 << user_defined_bullet(i).getCharacter() << " "
602 << user_defined_bullet(i).getSize() << "\n";
605 os << "\\bulletLaTeX " << i << " \""
606 << user_defined_bullet(i).getText()
612 os << "\\tracking_changes " << tracking_changes << "\n";
614 if (tracking_changes) {
615 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
616 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
617 for (; it != end; ++it) {
618 os << "\\author " << it->second << "\n";
624 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
625 TexRow & texrow) const
627 os << "\\documentclass";
629 LyXTextClass const & tclass = getLyXTextClass();
631 ostringstream clsoptions; // the document class options.
633 if (tokenPos(tclass.opt_fontsize(),
634 '|', fontsize) >= 0) {
635 // only write if existing in list (and not default)
636 clsoptions << fontsize << "pt,";
641 (paperpackage == PACKAGE_NONE)) {
644 clsoptions << "a3paper,";
647 clsoptions << "a4paper,";
650 clsoptions << "letterpaper,";
653 clsoptions << "a5paper,";
656 clsoptions << "b5paper,";
658 case PAPER_EXECUTIVEPAPER:
659 clsoptions << "executivepaper,";
661 case PAPER_LEGALPAPER:
662 clsoptions << "legalpaper,";
670 if (sides != tclass.sides()) {
672 case LyXTextClass::OneSide:
673 clsoptions << "oneside,";
675 case LyXTextClass::TwoSides:
676 clsoptions << "twoside,";
682 if (columns != tclass.columns()) {
684 clsoptions << "twocolumn,";
686 clsoptions << "onecolumn,";
690 && orientation == ORIENTATION_LANDSCAPE)
691 clsoptions << "landscape,";
693 // language should be a parameter to \documentclass
694 if (language->babel() == "hebrew"
695 && default_language->babel() != "hebrew")
696 // This seems necessary
697 features.useLanguage(default_language);
699 ostringstream language_options;
700 bool const use_babel = features.useBabel();
702 language_options << features.getLanguages();
703 language_options << language->babel();
704 if (lyxrc.language_global_options)
705 clsoptions << language_options.str() << ',';
708 // the user-defined options
709 if (!options.empty()) {
710 clsoptions << options << ',';
713 string strOptions(clsoptions.str());
714 if (!strOptions.empty()) {
715 strOptions = rtrim(strOptions, ",");
716 os << '[' << strOptions << ']';
719 os << '{' << tclass.latexname() << "}\n";
721 // end of \documentclass defs
723 // font selection must be done before loading fontenc.sty
724 // The ae package is not needed when using OT1 font encoding.
725 if (fonts != "default" &&
726 (fonts != "ae" || lyxrc.fontenc != "default")) {
727 os << "\\usepackage{" << fonts << "}\n";
730 os << "\\usepackage{aecompl}\n";
734 // this one is not per buffer
735 if (lyxrc.fontenc != "default") {
736 os << "\\usepackage[" << lyxrc.fontenc
741 if (inputenc == "auto") {
742 string const doc_encoding =
743 language->encoding()->LatexName();
745 // Create a list with all the input encodings used
747 std::set<string> encodings =
748 features.getEncodingSet(doc_encoding);
750 os << "\\usepackage[";
751 std::copy(encodings.begin(), encodings.end(),
752 std::ostream_iterator<string>(os, ","));
753 os << doc_encoding << "]{inputenc}\n";
755 } else if (inputenc != "default") {
756 os << "\\usepackage[" << inputenc
761 // At the very beginning the text parameters.
762 if (paperpackage != PACKAGE_NONE) {
763 switch (paperpackage) {
767 os << "\\usepackage{a4}\n";
771 os << "\\usepackage{a4wide}\n";
774 case PACKAGE_WIDEMARGINSA4:
775 os << "\\usepackage[widemargins]{a4}\n";
781 os << "\\usepackage{geometry}\n";
783 os << "\\geometry{verbose";
784 if (orientation == ORIENTATION_LANDSCAPE)
786 switch (papersize2) {
787 case VM_PAPER_CUSTOM:
788 if (!paperwidth.empty())
791 if (!paperheight.empty())
792 os << ",paperheight="
795 case VM_PAPER_USLETTER:
796 os << ",letterpaper";
798 case VM_PAPER_USLEGAL:
801 case VM_PAPER_USEXECUTIVE:
802 os << ",executivepaper";
823 // default papersize ie VM_PAPER_DEFAULT
824 switch (lyxrc.default_papersize) {
825 case PAPER_DEFAULT: // keep compiler happy
827 os << ",letterpaper";
829 case PAPER_LEGALPAPER:
832 case PAPER_EXECUTIVEPAPER:
833 os << ",executivepaper";
849 if (!topmargin.empty())
850 os << ",tmargin=" << topmargin;
851 if (!bottommargin.empty())
852 os << ",bmargin=" << bottommargin;
853 if (!leftmargin.empty())
854 os << ",lmargin=" << leftmargin;
855 if (!rightmargin.empty())
856 os << ",rmargin=" << rightmargin;
857 if (!headheight.empty())
858 os << ",headheight=" << headheight;
859 if (!headsep.empty())
860 os << ",headsep=" << headsep;
861 if (!footskip.empty())
862 os << ",footskip=" << footskip;
867 if (tokenPos(tclass.opt_pagestyle(),
868 '|', pagestyle) >= 0) {
869 if (pagestyle == "fancy") {
870 os << "\\usepackage{fancyhdr}\n";
873 os << "\\pagestyle{" << pagestyle << "}\n";
877 if (secnumdepth != tclass.secnumdepth()) {
878 os << "\\setcounter{secnumdepth}{"
883 if (tocdepth != tclass.tocdepth()) {
884 os << "\\setcounter{tocdepth}{"
890 if (paragraph_separation) {
891 switch (getDefSkip().kind()) {
892 case VSpace::SMALLSKIP:
893 os << "\\setlength\\parskip{\\smallskipamount}\n";
895 case VSpace::MEDSKIP:
896 os << "\\setlength\\parskip{\\medskipamount}\n";
898 case VSpace::BIGSKIP:
899 os << "\\setlength\\parskip{\\bigskipamount}\n";
902 os << "\\setlength\\parskip{"
903 << getDefSkip().length().asLatexString()
906 default: // should never happen // Then delete it.
907 os << "\\setlength\\parskip{\\medskipamount}\n";
912 os << "\\setlength\\parindent{0pt}\n";
916 // If we use jurabib, we have to call babel here.
917 if (use_babel && features.isRequired("jurabib")) {
918 os << babelCall(language_options.str())
920 << features.getBabelOptions();
924 // Now insert the LyX specific LaTeX commands...
926 // The optional packages;
927 string lyxpreamble(features.getPackages());
929 // this might be useful...
930 lyxpreamble += "\n\\makeatletter\n";
932 // Some macros LyX will need
933 string tmppreamble(features.getMacros());
935 if (!tmppreamble.empty()) {
936 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
937 "LyX specific LaTeX commands.\n"
938 + tmppreamble + '\n';
941 // the text class specific preamble
942 tmppreamble = features.getTClassPreamble();
943 if (!tmppreamble.empty()) {
944 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
945 "Textclass specific LaTeX commands.\n"
946 + tmppreamble + '\n';
949 /* the user-defined preamble */
950 if (!preamble.empty()) {
951 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
952 "User specified LaTeX commands.\n"
956 // Itemize bullet settings need to be last in case the user
957 // defines their own bullets that use a package included
958 // in the user-defined preamble -- ARRae
959 // Actually it has to be done much later than that
960 // since some packages like frenchb make modifications
961 // at \begin{document} time -- JMarc
963 for (int i = 0; i < 4; ++i) {
964 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
965 if (bullets_def.empty())
966 bullets_def="\\AtBeginDocument{\n";
967 bullets_def += " \\renewcommand{\\labelitemi";
969 // `i' is one less than the item to modify
982 bullets_def += "}{" +
983 user_defined_bullet(i).getText()
988 if (!bullets_def.empty())
989 lyxpreamble += bullets_def + "}\n\n";
991 // We try to load babel late, in case it interferes
992 // with other packages.
993 // Jurabib has to be called after babel, though.
994 if (use_babel && !features.isRequired("jurabib")) {
995 lyxpreamble += babelCall(language_options.str()) + '\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;
1189 string const BufferParams::babelCall(string const & lang_opts) const
1191 string tmp = lyxrc.language_package;
1192 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1193 tmp = string("\\usepackage[") + lang_opts + "]{babel}";