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;
116 cite_engine = biblio::ENGINE_BASIC;
117 use_bibtopic = 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 == "\\cite_engine") {
320 string const engine = lex.getString();
322 cite_engine = biblio::ENGINE_BASIC;
323 if (engine == "natbib_numerical")
324 cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
325 else if (engine == "natbib_authoryear")
326 cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
327 else if (engine == "jurabib")
328 cite_engine = biblio::ENGINE_JURABIB;
330 } else if (token == "\\use_bibtopic") {
332 use_bibtopic = lex.getInteger();
333 } else if (token == "\\tracking_changes") {
335 tracking_changes = lex.getInteger();
336 } else if (token == "\\branch") {
338 string branch = lex.getString();
339 branchlist().add(branch);
342 string const tok = lex.getString();
343 if (tok == "\\end_branch")
345 Branch * branch_ptr = branchlist().find(branch);
346 if (tok == "\\selected") {
349 branch_ptr->setSelected(lex.getInteger());
351 // not yet operational
352 if (tok == "\\color") {
354 string color = lex.getString();
356 branch_ptr->setColor(color);
357 // Update also the LColor table:
359 color = lcolor.getX11Name(LColor::background);
360 lcolor.setColor(branch, color);
364 } else if (token == "\\author") {
366 istringstream ss(lex.getString());
369 author_map.push_back(pimpl_->authorlist.record(a));
370 } else if (token == "\\paperorientation") {
371 int tmpret = lex.findToken(string_orientation);
375 static_cast<PAPER_ORIENTATION>(tmpret);
376 } else if (token == "\\paperwidth") {
378 paperwidth = lex.getString();
379 } else if (token == "\\paperheight") {
381 paperheight = lex.getString();
382 } else if (token == "\\leftmargin") {
384 leftmargin = lex.getString();
385 } else if (token == "\\topmargin") {
387 topmargin = lex.getString();
388 } else if (token == "\\rightmargin") {
390 rightmargin = lex.getString();
391 } else if (token == "\\bottommargin") {
393 bottommargin = lex.getString();
394 } else if (token == "\\headheight") {
396 headheight = lex.getString();
397 } else if (token == "\\headsep") {
399 headsep = lex.getString();
400 } else if (token == "\\footskip") {
402 footskip = lex.getString();
403 } else if (token == "\\paperfontsize") {
405 fontsize = rtrim(lex.getString());
406 } else if (token == "\\papercolumns") {
408 columns = lex.getInteger();
409 } else if (token == "\\papersides") {
411 switch (lex.getInteger()) {
413 case 1: sides = LyXTextClass::OneSide; break;
414 case 2: sides = LyXTextClass::TwoSides; break;
416 } else if (token == "\\paperpagestyle") {
418 pagestyle = rtrim(lex.getString());
419 } else if (token == "\\bullet") {
420 // FIXME: should be params.readBullets()
422 int const index = lex.getInteger();
424 int temp_int = lex.getInteger();
425 user_defined_bullet(index).setFont(temp_int);
426 temp_bullet(index).setFont(temp_int);
428 temp_int = lex.getInteger();
429 user_defined_bullet(index).setCharacter(temp_int);
430 temp_bullet(index).setCharacter(temp_int);
432 temp_int = lex.getInteger();
433 user_defined_bullet(index).setSize(temp_int);
434 temp_bullet(index).setSize(temp_int);
436 string const temp_str = lex.getString();
437 if (temp_str != "\\end_bullet") {
438 // this element isn't really necessary for
439 // parsing but is easier for humans
440 // to understand bullets. Put it back and
441 // set a debug message?
442 lex.printError("\\end_bullet expected, got" + temp_str);
443 //how can I put it back?
445 } else if (token == "\\bulletLaTeX") {
446 // The bullet class should be able to read this.
448 int const index = lex.getInteger();
450 string temp_str = lex.getString();
452 while (temp_str != "\\end_bullet") {
453 // this loop structure is needed when user
454 // enters an empty string since the first
455 // thing returned will be the \\end_bullet
457 // if the LaTeX entry has spaces. Each element
458 // therefore needs to be read in turn
461 temp_str = lex.getString();
464 user_defined_bullet(index).setText(sum_str);
465 temp_bullet(index).setText(sum_str);
466 } else if (token == "\\secnumdepth") {
468 secnumdepth = lex.getInteger();
469 } else if (token == "\\tocdepth") {
471 tocdepth = lex.getInteger();
472 } else if (token == "\\spacing") {
474 string const tmp = rtrim(lex.getString());
475 Spacing::Space tmp_space = Spacing::Default;
477 if (tmp == "single") {
478 tmp_space = Spacing::Single;
479 } else if (tmp == "onehalf") {
480 tmp_space = Spacing::Onehalf;
481 } else if (tmp == "double") {
482 tmp_space = Spacing::Double;
483 } else if (tmp == "other") {
485 tmp_space = Spacing::Other;
486 tmp_val = lex.getFloat();
488 lex.printError("Unknown spacing token: '$$Token'");
490 #if 0 // FIXME: Handled in lyx2lyx ?
491 // Small hack so that files written with klyx will be
494 par->params().spacing(Spacing(tmp_space, tmp_val));
496 spacing().set(tmp_space, tmp_val);
497 } else if (token == "\\float_placement") {
499 float_placement = lex.getString();
508 void BufferParams::writeFile(ostream & os) const
510 // The top of the file is written by the buffer.
511 // Prints out the buffer info into the .lyx file given by file
514 os << "\\textclass " << textclasslist[textclass].name() << '\n';
516 // then the the preamble
517 if (!preamble.empty()) {
518 // remove '\n' from the end of preamble
519 string const tmppreamble = rtrim(preamble, "\n");
520 os << "\\begin_preamble\n"
522 << "\n\\end_preamble\n";
526 if (!options.empty()) {
527 os << "\\options " << options << '\n';
530 /* then the text parameters */
531 if (language != ignore_language)
532 os << "\\language " << language->lang() << '\n';
533 os << "\\inputencoding " << inputenc
534 << "\n\\fontscheme " << fonts
535 << "\n\\graphics " << graphicsDriver << '\n';
537 if (!float_placement.empty()) {
538 os << "\\float_placement " << float_placement << '\n';
540 os << "\\paperfontsize " << fontsize << '\n';
542 spacing().writeFile(os);
544 string cite_engine_str = "basic";
545 switch (cite_engine) {
546 case biblio::ENGINE_BASIC:
548 case biblio::ENGINE_NATBIB_NUMERICAL:
549 cite_engine_str = "natbib_numerical";
551 case biblio::ENGINE_NATBIB_AUTHORYEAR:
552 cite_engine_str = "natbib_authoryear";
554 case biblio::ENGINE_JURABIB:
555 cite_engine_str = "jurabib";
559 os << "\\papersize " << string_papersize[papersize2]
560 << "\n\\paperpackage " << string_paperpackages[paperpackage]
561 << "\n\\use_geometry " << use_geometry
562 << "\n\\use_amsmath " << use_amsmath
563 << "\n\\cite_engine " << cite_engine_str
564 << "\n\\use_bibtopic " << use_bibtopic
565 << "\n\\paperorientation " << string_orientation[orientation]
568 std::list<Branch>::const_iterator it = branchlist().begin();
569 std::list<Branch>::const_iterator end = branchlist().end();
570 for (; it != end; ++it) {
571 os << "\\branch " << it->getBranch()
572 << "\n\\selected " << it->getSelected()
573 << "\n\\color " << it->getColor()
578 if (!paperwidth.empty())
579 os << "\\paperwidth "
580 << VSpace(paperwidth).asLyXCommand() << '\n';
581 if (!paperheight.empty())
582 os << "\\paperheight "
583 << VSpace(paperheight).asLyXCommand() << '\n';
584 if (!leftmargin.empty())
585 os << "\\leftmargin "
586 << VSpace(leftmargin).asLyXCommand() << '\n';
587 if (!topmargin.empty())
589 << VSpace(topmargin).asLyXCommand() << '\n';
590 if (!rightmargin.empty())
591 os << "\\rightmargin "
592 << VSpace(rightmargin).asLyXCommand() << '\n';
593 if (!bottommargin.empty())
594 os << "\\bottommargin "
595 << VSpace(bottommargin).asLyXCommand() << '\n';
596 if (!headheight.empty())
597 os << "\\headheight "
598 << VSpace(headheight).asLyXCommand() << '\n';
599 if (!headsep.empty())
601 << VSpace(headsep).asLyXCommand() << '\n';
602 if (!footskip.empty())
604 << VSpace(footskip).asLyXCommand() << '\n';
605 os << "\\secnumdepth " << secnumdepth
606 << "\n\\tocdepth " << tocdepth
607 << "\n\\paragraph_separation "
608 << string_paragraph_separation[paragraph_separation]
609 << "\n\\defskip " << getDefSkip().asLyXCommand()
610 << "\n\\quotes_language "
611 << string_quotes_language[quotes_language] << '\n';
612 switch (quotes_times) {
613 // An output operator for insetquotes would be nice
614 case InsetQuotes::SingleQ:
615 os << "\\quotes_times 1\n"; break;
616 case InsetQuotes::DoubleQ:
617 os << "\\quotes_times 2\n"; break;
619 os << "\\papercolumns " << columns
620 << "\n\\papersides " << sides
621 << "\n\\paperpagestyle " << pagestyle << '\n';
622 for (int i = 0; i < 4; ++i) {
623 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
624 if (user_defined_bullet(i).getFont() != -1) {
625 os << "\\bullet " << i
627 << user_defined_bullet(i).getFont()
629 << user_defined_bullet(i).getCharacter()
631 << user_defined_bullet(i).getSize()
632 << "\n\\end_bullet\n";
635 os << "\\bulletLaTeX " << i
637 << user_defined_bullet(i).getText()
638 << "\"\n\\end_bullet\n";
643 os << "\\tracking_changes " << tracking_changes << "\n";
645 if (tracking_changes) {
646 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
647 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
648 for (; it != end; ++it) {
649 os << "\\author " << it->second << "\n";
655 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
656 TexRow & texrow) const
658 os << "\\documentclass";
660 LyXTextClass const & tclass = getLyXTextClass();
662 ostringstream clsoptions; // the document class options.
664 if (tokenPos(tclass.opt_fontsize(),
665 '|', fontsize) >= 0) {
666 // only write if existing in list (and not default)
667 clsoptions << fontsize << "pt,";
672 (paperpackage == PACKAGE_NONE)) {
675 clsoptions << "a3paper,";
678 clsoptions << "a4paper,";
681 clsoptions << "letterpaper,";
684 clsoptions << "a5paper,";
687 clsoptions << "b5paper,";
689 case PAPER_EXECUTIVEPAPER:
690 clsoptions << "executivepaper,";
692 case PAPER_LEGALPAPER:
693 clsoptions << "legalpaper,";
701 if (sides != tclass.sides()) {
703 case LyXTextClass::OneSide:
704 clsoptions << "oneside,";
706 case LyXTextClass::TwoSides:
707 clsoptions << "twoside,";
713 if (columns != tclass.columns()) {
715 clsoptions << "twocolumn,";
717 clsoptions << "onecolumn,";
721 && orientation == ORIENTATION_LANDSCAPE)
722 clsoptions << "landscape,";
724 // language should be a parameter to \documentclass
725 if (language->babel() == "hebrew"
726 && default_language->babel() != "hebrew")
727 // This seems necessary
728 features.useLanguage(default_language);
730 ostringstream language_options;
731 bool const use_babel = features.useBabel();
733 language_options << features.getLanguages();
734 language_options << language->babel();
735 if (lyxrc.language_global_options)
736 clsoptions << language_options.str() << ',';
739 // the user-defined options
740 if (!options.empty()) {
741 clsoptions << options << ',';
744 string strOptions(clsoptions.str());
745 if (!strOptions.empty()) {
746 strOptions = rtrim(strOptions, ",");
747 os << '[' << strOptions << ']';
750 os << '{' << tclass.latexname() << "}\n";
752 // end of \documentclass defs
754 // font selection must be done before loading fontenc.sty
755 // The ae package is not needed when using OT1 font encoding.
756 if (fonts != "default" &&
757 (fonts != "ae" || lyxrc.fontenc != "default")) {
758 os << "\\usepackage{" << fonts << "}\n";
761 os << "\\usepackage{aecompl}\n";
765 // this one is not per buffer
766 if (lyxrc.fontenc != "default") {
767 os << "\\usepackage[" << lyxrc.fontenc
772 if (inputenc == "auto") {
773 string const doc_encoding =
774 language->encoding()->LatexName();
776 // Create a list with all the input encodings used
778 std::set<string> encodings =
779 features.getEncodingSet(doc_encoding);
781 os << "\\usepackage[";
782 std::copy(encodings.begin(), encodings.end(),
783 std::ostream_iterator<string>(os, ","));
784 os << doc_encoding << "]{inputenc}\n";
786 } else if (inputenc != "default") {
787 os << "\\usepackage[" << inputenc
792 // At the very beginning the text parameters.
793 if (paperpackage != PACKAGE_NONE) {
794 switch (paperpackage) {
798 os << "\\usepackage{a4}\n";
802 os << "\\usepackage{a4wide}\n";
805 case PACKAGE_WIDEMARGINSA4:
806 os << "\\usepackage[widemargins]{a4}\n";
812 os << "\\usepackage{geometry}\n";
814 os << "\\geometry{verbose";
815 if (orientation == ORIENTATION_LANDSCAPE)
817 switch (papersize2) {
818 case VM_PAPER_CUSTOM:
819 if (!paperwidth.empty())
822 if (!paperheight.empty())
823 os << ",paperheight="
826 case VM_PAPER_USLETTER:
827 os << ",letterpaper";
829 case VM_PAPER_USLEGAL:
832 case VM_PAPER_USEXECUTIVE:
833 os << ",executivepaper";
854 // default papersize ie VM_PAPER_DEFAULT
855 switch (lyxrc.default_papersize) {
856 case PAPER_DEFAULT: // keep compiler happy
858 os << ",letterpaper";
860 case PAPER_LEGALPAPER:
863 case PAPER_EXECUTIVEPAPER:
864 os << ",executivepaper";
880 if (!topmargin.empty())
881 os << ",tmargin=" << topmargin;
882 if (!bottommargin.empty())
883 os << ",bmargin=" << bottommargin;
884 if (!leftmargin.empty())
885 os << ",lmargin=" << leftmargin;
886 if (!rightmargin.empty())
887 os << ",rmargin=" << rightmargin;
888 if (!headheight.empty())
889 os << ",headheight=" << headheight;
890 if (!headsep.empty())
891 os << ",headsep=" << headsep;
892 if (!footskip.empty())
893 os << ",footskip=" << footskip;
898 if (tokenPos(tclass.opt_pagestyle(),
899 '|', pagestyle) >= 0) {
900 if (pagestyle == "fancy") {
901 os << "\\usepackage{fancyhdr}\n";
904 os << "\\pagestyle{" << pagestyle << "}\n";
908 if (secnumdepth != tclass.secnumdepth()) {
909 os << "\\setcounter{secnumdepth}{"
914 if (tocdepth != tclass.tocdepth()) {
915 os << "\\setcounter{tocdepth}{"
921 if (paragraph_separation) {
922 switch (getDefSkip().kind()) {
923 case VSpace::SMALLSKIP:
924 os << "\\setlength\\parskip{\\smallskipamount}\n";
926 case VSpace::MEDSKIP:
927 os << "\\setlength\\parskip{\\medskipamount}\n";
929 case VSpace::BIGSKIP:
930 os << "\\setlength\\parskip{\\bigskipamount}\n";
933 os << "\\setlength\\parskip{"
934 << getDefSkip().length().asLatexString()
937 default: // should never happen // Then delete it.
938 os << "\\setlength\\parskip{\\medskipamount}\n";
943 os << "\\setlength\\parindent{0pt}\n";
947 // If we use jurabib, we have to call babel here.
948 if (use_babel && features.isRequired("jurabib")) {
949 os << babelCall(language_options.str())
951 << features.getBabelOptions();
955 // Now insert the LyX specific LaTeX commands...
957 // The optional packages;
958 string lyxpreamble(features.getPackages());
960 // this might be useful...
961 lyxpreamble += "\n\\makeatletter\n";
963 // Some macros LyX will need
964 string tmppreamble(features.getMacros());
966 if (!tmppreamble.empty()) {
967 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
968 "LyX specific LaTeX commands.\n"
969 + tmppreamble + '\n';
972 // the text class specific preamble
973 tmppreamble = features.getTClassPreamble();
974 if (!tmppreamble.empty()) {
975 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
976 "Textclass specific LaTeX commands.\n"
977 + tmppreamble + '\n';
980 /* the user-defined preamble */
981 if (!preamble.empty()) {
982 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
983 "User specified LaTeX commands.\n"
987 // Itemize bullet settings need to be last in case the user
988 // defines their own bullets that use a package included
989 // in the user-defined preamble -- ARRae
990 // Actually it has to be done much later than that
991 // since some packages like frenchb make modifications
992 // at \begin{document} time -- JMarc
994 for (int i = 0; i < 4; ++i) {
995 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
996 if (bullets_def.empty())
997 bullets_def="\\AtBeginDocument{\n";
998 bullets_def += " \\renewcommand{\\labelitemi";
1000 // `i' is one less than the item to modify
1007 bullets_def += "ii";
1013 bullets_def += "}{" +
1014 user_defined_bullet(i).getText()
1019 if (!bullets_def.empty())
1020 lyxpreamble += bullets_def + "}\n\n";
1022 // We try to load babel late, in case it interferes
1023 // with other packages.
1024 // Jurabib has to be called after babel, though.
1025 if (use_babel && !features.isRequired("jurabib")) {
1026 lyxpreamble += babelCall(language_options.str()) + '\n';
1027 lyxpreamble += features.getBabelOptions();
1030 lyxpreamble += "\\makeatother\n";
1032 // dvipost settings come after everything else
1033 if (tracking_changes) {
1036 "\\dvipost{osstart color push Red}\n"
1037 "\\dvipost{osend color pop}\n"
1038 "\\dvipost{cbstart color push Blue}\n"
1039 "\\dvipost{cbend color pop} \n";
1043 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1044 for (int j = 0; j != nlines; ++j) {
1052 void BufferParams::setPaperStuff()
1054 papersize = PAPER_DEFAULT;
1055 char const c1 = paperpackage;
1056 if (c1 == PACKAGE_NONE) {
1057 char const c2 = papersize2;
1058 if (c2 == VM_PAPER_USLETTER)
1059 papersize = PAPER_USLETTER;
1060 else if (c2 == VM_PAPER_USLEGAL)
1061 papersize = PAPER_LEGALPAPER;
1062 else if (c2 == VM_PAPER_USEXECUTIVE)
1063 papersize = PAPER_EXECUTIVEPAPER;
1064 else if (c2 == VM_PAPER_A3)
1065 papersize = PAPER_A3PAPER;
1066 else if (c2 == VM_PAPER_A4)
1067 papersize = PAPER_A4PAPER;
1068 else if (c2 == VM_PAPER_A5)
1069 papersize = PAPER_A5PAPER;
1070 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1071 (c2 == VM_PAPER_B5))
1072 papersize = PAPER_B5PAPER;
1073 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1074 (c1 == PACKAGE_WIDEMARGINSA4))
1075 papersize = PAPER_A4PAPER;
1079 void BufferParams::useClassDefaults()
1081 LyXTextClass const & tclass = textclasslist[textclass];
1083 sides = tclass.sides();
1084 columns = tclass.columns();
1085 pagestyle = tclass.pagestyle();
1086 options = tclass.options();
1087 secnumdepth = tclass.secnumdepth();
1088 tocdepth = tclass.tocdepth();
1092 bool BufferParams::hasClassDefaults() const
1094 LyXTextClass const & tclass = textclasslist[textclass];
1096 return (sides == tclass.sides()
1097 && columns == tclass.columns()
1098 && pagestyle == tclass.pagestyle()
1099 && options == tclass.options()
1100 && secnumdepth == tclass.secnumdepth()
1101 && tocdepth == tclass.tocdepth());
1105 LyXTextClass const & BufferParams::getLyXTextClass() const
1107 return textclasslist[textclass];
1111 void BufferParams::readPreamble(LyXLex & lex)
1113 if (lex.getString() != "\\begin_preamble")
1114 lyxerr << "Error (BufferParams::readPreamble):"
1115 "consistency check failed." << endl;
1117 preamble = lex.getLongString("\\end_preamble");
1121 void BufferParams::readLanguage(LyXLex & lex)
1123 if (!lex.next()) return;
1125 string const tmptok = lex.getString();
1127 // check if tmptok is part of tex_babel in tex-defs.h
1128 language = languages.getLanguage(tmptok);
1130 // Language tmptok was not found
1131 language = default_language;
1132 lyxerr << "Warning: Setting language `"
1133 << tmptok << "' to `" << language->lang()
1139 void BufferParams::readGraphicsDriver(LyXLex & lex)
1141 if (!lex.next()) return;
1143 string const tmptok = lex.getString();
1144 // check if tmptok is part of tex_graphics in tex_defs.h
1147 string const test = tex_graphics[n++];
1149 if (test == tmptok) {
1150 graphicsDriver = tmptok;
1152 } else if (test == "last_item") {
1154 "Warning: graphics driver `$$Token' not recognized!\n"
1155 " Setting graphics driver to `default'.\n");
1156 graphicsDriver = "default";
1163 string const BufferParams::paperSizeName() const
1165 char real_papersize = papersize;
1166 if (real_papersize == PAPER_DEFAULT)
1167 real_papersize = lyxrc.default_papersize;
1169 switch (real_papersize) {
1178 case PAPER_EXECUTIVEPAPER:
1180 case PAPER_LEGALPAPER:
1182 case PAPER_USLETTER:
1189 string const BufferParams::dvips_options() const
1194 && papersize2 == VM_PAPER_CUSTOM
1195 && !lyxrc.print_paper_dimension_flag.empty()
1196 && !paperwidth.empty()
1197 && !paperheight.empty()) {
1198 // using a custom papersize
1199 result = lyxrc.print_paper_dimension_flag;
1200 result += ' ' + paperwidth;
1201 result += ',' + paperheight;
1203 string const paper_option = paperSizeName();
1204 if (paper_option != "letter" ||
1205 orientation != ORIENTATION_LANDSCAPE) {
1206 // dvips won't accept -t letter -t landscape.
1207 // In all other cases, include the paper size
1209 result = lyxrc.print_paper_flag;
1210 result += ' ' + paper_option;
1213 if (orientation == ORIENTATION_LANDSCAPE &&
1214 papersize2 != VM_PAPER_CUSTOM)
1215 result += ' ' + lyxrc.print_landscape_flag;
1220 string const BufferParams::babelCall(string const & lang_opts) const
1222 string tmp = lyxrc.language_package;
1223 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1224 tmp = string("\\usepackage[") + lang_opts + "]{babel}";