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 = rtrim(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 = rtrim(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);
438 string const temp_str = lex.getString();
439 if (temp_str != "\\end_bullet") {
440 // this element isn't really necessary for
441 // parsing but is easier for humans
442 // to understand bullets. Put it back and
443 // set a debug message?
444 lex.printError("\\end_bullet expected, got" + temp_str);
445 //how can I put it back?
447 } else if (token == "\\bulletLaTeX") {
448 // The bullet class should be able to read this.
450 int const index = lex.getInteger();
452 string temp_str = lex.getString();
454 while (temp_str != "\\end_bullet") {
455 // this loop structure is needed when user
456 // enters an empty string since the first
457 // thing returned will be the \\end_bullet
459 // if the LaTeX entry has spaces. Each element
460 // therefore needs to be read in turn
463 temp_str = lex.getString();
466 user_defined_bullet(index).setText(sum_str);
467 temp_bullet(index).setText(sum_str);
468 } else if (token == "\\secnumdepth") {
470 secnumdepth = lex.getInteger();
471 } else if (token == "\\tocdepth") {
473 tocdepth = lex.getInteger();
474 } else if (token == "\\spacing") {
476 string const tmp = rtrim(lex.getString());
477 Spacing::Space tmp_space = Spacing::Default;
479 if (tmp == "single") {
480 tmp_space = Spacing::Single;
481 } else if (tmp == "onehalf") {
482 tmp_space = Spacing::Onehalf;
483 } else if (tmp == "double") {
484 tmp_space = Spacing::Double;
485 } else if (tmp == "other") {
487 tmp_space = Spacing::Other;
488 tmp_val = lex.getFloat();
490 lex.printError("Unknown spacing token: '$$Token'");
492 #if 0 // FIXME: Handled in lyx2lyx ?
493 // Small hack so that files written with klyx will be
496 par->params().spacing(Spacing(tmp_space, tmp_val));
498 spacing().set(tmp_space, tmp_val);
499 } else if (token == "\\float_placement") {
501 float_placement = lex.getString();
510 void BufferParams::writeFile(ostream & os) const
512 // The top of the file is written by the buffer.
513 // Prints out the buffer info into the .lyx file given by file
516 os << "\\textclass " << textclasslist[textclass].name() << '\n';
518 // then the the preamble
519 if (!preamble.empty()) {
520 // remove '\n' from the end of preamble
521 string const tmppreamble = rtrim(preamble, "\n");
522 os << "\\begin_preamble\n"
524 << "\n\\end_preamble\n";
528 if (!options.empty()) {
529 os << "\\options " << options << '\n';
532 /* then the text parameters */
533 if (language != ignore_language)
534 os << "\\language " << language->lang() << '\n';
535 os << "\\inputencoding " << inputenc
536 << "\n\\fontscheme " << fonts
537 << "\n\\graphics " << graphicsDriver << '\n';
539 if (!float_placement.empty()) {
540 os << "\\float_placement " << float_placement << '\n';
542 os << "\\paperfontsize " << fontsize << '\n';
544 spacing().writeFile(os);
546 string cite_engine_str = "basic";
547 switch (cite_engine) {
548 case biblio::ENGINE_BASIC:
550 case biblio::ENGINE_NATBIB_NUMERICAL:
551 cite_engine_str = "natbib_numerical";
553 case biblio::ENGINE_NATBIB_AUTHORYEAR:
554 cite_engine_str = "natbib_authoryear";
556 case biblio::ENGINE_JURABIB:
557 cite_engine_str = "jurabib";
561 os << "\\papersize " << string_papersize[papersize2]
562 << "\n\\paperpackage " << string_paperpackages[paperpackage]
563 << "\n\\use_geometry " << use_geometry
564 << "\n\\use_amsmath " << use_amsmath
565 << "\n\\cite_engine " << cite_engine_str
566 << "\n\\use_bibtopic " << use_bibtopic
567 << "\n\\paperorientation " << string_orientation[orientation]
570 std::list<Branch>::const_iterator it = branchlist().begin();
571 std::list<Branch>::const_iterator end = branchlist().end();
572 for (; it != end; ++it) {
573 os << "\\branch " << it->getBranch()
574 << "\n\\selected " << it->getSelected()
575 << "\n\\color " << it->getColor()
580 if (!paperwidth.empty())
581 os << "\\paperwidth "
582 << VSpace(paperwidth).asLyXCommand() << '\n';
583 if (!paperheight.empty())
584 os << "\\paperheight "
585 << VSpace(paperheight).asLyXCommand() << '\n';
586 if (!leftmargin.empty())
587 os << "\\leftmargin "
588 << VSpace(leftmargin).asLyXCommand() << '\n';
589 if (!topmargin.empty())
591 << VSpace(topmargin).asLyXCommand() << '\n';
592 if (!rightmargin.empty())
593 os << "\\rightmargin "
594 << VSpace(rightmargin).asLyXCommand() << '\n';
595 if (!bottommargin.empty())
596 os << "\\bottommargin "
597 << VSpace(bottommargin).asLyXCommand() << '\n';
598 if (!headheight.empty())
599 os << "\\headheight "
600 << VSpace(headheight).asLyXCommand() << '\n';
601 if (!headsep.empty())
603 << VSpace(headsep).asLyXCommand() << '\n';
604 if (!footskip.empty())
606 << VSpace(footskip).asLyXCommand() << '\n';
607 os << "\\secnumdepth " << secnumdepth
608 << "\n\\tocdepth " << tocdepth
609 << "\n\\paragraph_separation "
610 << string_paragraph_separation[paragraph_separation]
611 << "\n\\defskip " << getDefSkip().asLyXCommand()
612 << "\n\\quotes_language "
613 << string_quotes_language[quotes_language] << '\n';
614 switch (quotes_times) {
615 // An output operator for insetquotes would be nice
616 case InsetQuotes::SingleQ:
617 os << "\\quotes_times 1\n"; break;
618 case InsetQuotes::DoubleQ:
619 os << "\\quotes_times 2\n"; break;
621 os << "\\papercolumns " << columns
622 << "\n\\papersides " << sides
623 << "\n\\paperpagestyle " << pagestyle << '\n';
624 for (int i = 0; i < 4; ++i) {
625 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
626 if (user_defined_bullet(i).getFont() != -1) {
627 os << "\\bullet " << i
629 << user_defined_bullet(i).getFont()
631 << user_defined_bullet(i).getCharacter()
633 << user_defined_bullet(i).getSize()
634 << "\n\\end_bullet\n";
637 os << "\\bulletLaTeX " << i
639 << user_defined_bullet(i).getText()
640 << "\"\n\\end_bullet\n";
645 os << "\\tracking_changes " << tracking_changes << "\n";
647 if (tracking_changes) {
648 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
649 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
650 for (; it != end; ++it) {
651 os << "\\author " << it->second << "\n";
657 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
658 TexRow & texrow) const
660 os << "\\documentclass";
662 LyXTextClass const & tclass = getLyXTextClass();
664 ostringstream clsoptions; // the document class options.
666 if (tokenPos(tclass.opt_fontsize(),
667 '|', fontsize) >= 0) {
668 // only write if existing in list (and not default)
669 clsoptions << fontsize << "pt,";
674 (paperpackage == PACKAGE_NONE)) {
677 clsoptions << "a3paper,";
680 clsoptions << "a4paper,";
683 clsoptions << "letterpaper,";
686 clsoptions << "a5paper,";
689 clsoptions << "b5paper,";
691 case PAPER_EXECUTIVEPAPER:
692 clsoptions << "executivepaper,";
694 case PAPER_LEGALPAPER:
695 clsoptions << "legalpaper,";
703 if (sides != tclass.sides()) {
705 case LyXTextClass::OneSide:
706 clsoptions << "oneside,";
708 case LyXTextClass::TwoSides:
709 clsoptions << "twoside,";
715 if (columns != tclass.columns()) {
717 clsoptions << "twocolumn,";
719 clsoptions << "onecolumn,";
723 && orientation == ORIENTATION_LANDSCAPE)
724 clsoptions << "landscape,";
726 // language should be a parameter to \documentclass
727 if (language->babel() == "hebrew"
728 && default_language->babel() != "hebrew")
729 // This seems necessary
730 features.useLanguage(default_language);
732 ostringstream language_options;
733 bool const use_babel = features.useBabel();
735 language_options << features.getLanguages();
736 language_options << language->babel();
737 if (lyxrc.language_global_options)
738 clsoptions << language_options.str() << ',';
741 // the user-defined options
742 if (!options.empty()) {
743 clsoptions << options << ',';
746 string strOptions(clsoptions.str());
747 if (!strOptions.empty()) {
748 strOptions = rtrim(strOptions, ",");
749 os << '[' << strOptions << ']';
752 os << '{' << tclass.latexname() << "}\n";
754 // end of \documentclass defs
756 // font selection must be done before loading fontenc.sty
757 // The ae package is not needed when using OT1 font encoding.
758 if (fonts != "default" &&
759 (fonts != "ae" || lyxrc.fontenc != "default")) {
760 os << "\\usepackage{" << fonts << "}\n";
763 os << "\\usepackage{aecompl}\n";
767 // this one is not per buffer
768 if (lyxrc.fontenc != "default") {
769 os << "\\usepackage[" << lyxrc.fontenc
774 if (inputenc == "auto") {
775 string const doc_encoding =
776 language->encoding()->LatexName();
778 // Create a list with all the input encodings used
780 std::set<string> encodings =
781 features.getEncodingSet(doc_encoding);
783 os << "\\usepackage[";
784 std::copy(encodings.begin(), encodings.end(),
785 std::ostream_iterator<string>(os, ","));
786 os << doc_encoding << "]{inputenc}\n";
788 } else if (inputenc != "default") {
789 os << "\\usepackage[" << inputenc
794 // At the very beginning the text parameters.
795 if (paperpackage != PACKAGE_NONE) {
796 switch (paperpackage) {
800 os << "\\usepackage{a4}\n";
804 os << "\\usepackage{a4wide}\n";
807 case PACKAGE_WIDEMARGINSA4:
808 os << "\\usepackage[widemargins]{a4}\n";
814 os << "\\usepackage{geometry}\n";
816 os << "\\geometry{verbose";
817 if (orientation == ORIENTATION_LANDSCAPE)
819 switch (papersize2) {
820 case VM_PAPER_CUSTOM:
821 if (!paperwidth.empty())
824 if (!paperheight.empty())
825 os << ",paperheight="
828 case VM_PAPER_USLETTER:
829 os << ",letterpaper";
831 case VM_PAPER_USLEGAL:
834 case VM_PAPER_USEXECUTIVE:
835 os << ",executivepaper";
856 // default papersize ie VM_PAPER_DEFAULT
857 switch (lyxrc.default_papersize) {
858 case PAPER_DEFAULT: // keep compiler happy
860 os << ",letterpaper";
862 case PAPER_LEGALPAPER:
865 case PAPER_EXECUTIVEPAPER:
866 os << ",executivepaper";
882 if (!topmargin.empty())
883 os << ",tmargin=" << topmargin;
884 if (!bottommargin.empty())
885 os << ",bmargin=" << bottommargin;
886 if (!leftmargin.empty())
887 os << ",lmargin=" << leftmargin;
888 if (!rightmargin.empty())
889 os << ",rmargin=" << rightmargin;
890 if (!headheight.empty())
891 os << ",headheight=" << headheight;
892 if (!headsep.empty())
893 os << ",headsep=" << headsep;
894 if (!footskip.empty())
895 os << ",footskip=" << footskip;
900 if (tokenPos(tclass.opt_pagestyle(),
901 '|', pagestyle) >= 0) {
902 if (pagestyle == "fancy") {
903 os << "\\usepackage{fancyhdr}\n";
906 os << "\\pagestyle{" << pagestyle << "}\n";
910 if (secnumdepth != tclass.secnumdepth()) {
911 os << "\\setcounter{secnumdepth}{"
916 if (tocdepth != tclass.tocdepth()) {
917 os << "\\setcounter{tocdepth}{"
923 if (paragraph_separation) {
924 switch (getDefSkip().kind()) {
925 case VSpace::SMALLSKIP:
926 os << "\\setlength\\parskip{\\smallskipamount}\n";
928 case VSpace::MEDSKIP:
929 os << "\\setlength\\parskip{\\medskipamount}\n";
931 case VSpace::BIGSKIP:
932 os << "\\setlength\\parskip{\\bigskipamount}\n";
935 os << "\\setlength\\parskip{"
936 << getDefSkip().length().asLatexString()
939 default: // should never happen // Then delete it.
940 os << "\\setlength\\parskip{\\medskipamount}\n";
945 os << "\\setlength\\parindent{0pt}\n";
949 // If we use jurabib, we have to call babel here.
950 if (use_babel && features.isRequired("jurabib")) {
951 os << babelCall(language_options.str())
953 << features.getBabelOptions();
957 // Now insert the LyX specific LaTeX commands...
959 // The optional packages;
960 string lyxpreamble(features.getPackages());
962 // this might be useful...
963 lyxpreamble += "\n\\makeatletter\n";
965 // Some macros LyX will need
966 string tmppreamble(features.getMacros());
968 if (!tmppreamble.empty()) {
969 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
970 "LyX specific LaTeX commands.\n"
971 + tmppreamble + '\n';
974 // the text class specific preamble
975 tmppreamble = features.getTClassPreamble();
976 if (!tmppreamble.empty()) {
977 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
978 "Textclass specific LaTeX commands.\n"
979 + tmppreamble + '\n';
982 /* the user-defined preamble */
983 if (!preamble.empty()) {
984 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
985 "User specified LaTeX commands.\n"
989 // Itemize bullet settings need to be last in case the user
990 // defines their own bullets that use a package included
991 // in the user-defined preamble -- ARRae
992 // Actually it has to be done much later than that
993 // since some packages like frenchb make modifications
994 // at \begin{document} time -- JMarc
996 for (int i = 0; i < 4; ++i) {
997 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
998 if (bullets_def.empty())
999 bullets_def="\\AtBeginDocument{\n";
1000 bullets_def += " \\renewcommand{\\labelitemi";
1002 // `i' is one less than the item to modify
1009 bullets_def += "ii";
1015 bullets_def += "}{" +
1016 user_defined_bullet(i).getText()
1021 if (!bullets_def.empty())
1022 lyxpreamble += bullets_def + "}\n\n";
1024 // We try to load babel late, in case it interferes
1025 // with other packages.
1026 // Jurabib has to be called after babel, though.
1027 if (use_babel && !features.isRequired("jurabib")) {
1028 lyxpreamble += babelCall(language_options.str()) + '\n';
1029 lyxpreamble += features.getBabelOptions();
1032 lyxpreamble += "\\makeatother\n";
1034 // dvipost settings come after everything else
1035 if (tracking_changes) {
1038 "\\dvipost{osstart color push Red}\n"
1039 "\\dvipost{osend color pop}\n"
1040 "\\dvipost{cbstart color push Blue}\n"
1041 "\\dvipost{cbend color pop} \n";
1045 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1046 for (int j = 0; j != nlines; ++j) {
1054 void BufferParams::setPaperStuff()
1056 papersize = PAPER_DEFAULT;
1057 char const c1 = paperpackage;
1058 if (c1 == PACKAGE_NONE) {
1059 char const c2 = papersize2;
1060 if (c2 == VM_PAPER_USLETTER)
1061 papersize = PAPER_USLETTER;
1062 else if (c2 == VM_PAPER_USLEGAL)
1063 papersize = PAPER_LEGALPAPER;
1064 else if (c2 == VM_PAPER_USEXECUTIVE)
1065 papersize = PAPER_EXECUTIVEPAPER;
1066 else if (c2 == VM_PAPER_A3)
1067 papersize = PAPER_A3PAPER;
1068 else if (c2 == VM_PAPER_A4)
1069 papersize = PAPER_A4PAPER;
1070 else if (c2 == VM_PAPER_A5)
1071 papersize = PAPER_A5PAPER;
1072 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1073 (c2 == VM_PAPER_B5))
1074 papersize = PAPER_B5PAPER;
1075 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1076 (c1 == PACKAGE_WIDEMARGINSA4))
1077 papersize = PAPER_A4PAPER;
1081 void BufferParams::useClassDefaults()
1083 LyXTextClass const & tclass = textclasslist[textclass];
1085 sides = tclass.sides();
1086 columns = tclass.columns();
1087 pagestyle = tclass.pagestyle();
1088 options = tclass.options();
1089 secnumdepth = tclass.secnumdepth();
1090 tocdepth = tclass.tocdepth();
1094 bool BufferParams::hasClassDefaults() const
1096 LyXTextClass const & tclass = textclasslist[textclass];
1098 return (sides == tclass.sides()
1099 && columns == tclass.columns()
1100 && pagestyle == tclass.pagestyle()
1101 && options == tclass.options()
1102 && secnumdepth == tclass.secnumdepth()
1103 && tocdepth == tclass.tocdepth());
1107 LyXTextClass const & BufferParams::getLyXTextClass() const
1109 return textclasslist[textclass];
1113 void BufferParams::readPreamble(LyXLex & lex)
1115 if (lex.getString() != "\\begin_preamble")
1116 lyxerr << "Error (BufferParams::readPreamble):"
1117 "consistency check failed." << endl;
1119 preamble = lex.getLongString("\\end_preamble");
1123 void BufferParams::readLanguage(LyXLex & lex)
1125 if (!lex.next()) return;
1127 string const tmptok = lex.getString();
1129 // check if tmptok is part of tex_babel in tex-defs.h
1130 language = languages.getLanguage(tmptok);
1132 // Language tmptok was not found
1133 language = default_language;
1134 lyxerr << "Warning: Setting language `"
1135 << tmptok << "' to `" << language->lang()
1141 void BufferParams::readGraphicsDriver(LyXLex & lex)
1143 if (!lex.next()) return;
1145 string const tmptok = lex.getString();
1146 // check if tmptok is part of tex_graphics in tex_defs.h
1149 string const test = tex_graphics[n++];
1151 if (test == tmptok) {
1152 graphicsDriver = tmptok;
1154 } else if (test == "last_item") {
1156 "Warning: graphics driver `$$Token' not recognized!\n"
1157 " Setting graphics driver to `default'.\n");
1158 graphicsDriver = "default";
1165 string const BufferParams::paperSizeName() const
1167 char real_papersize = papersize;
1168 if (real_papersize == PAPER_DEFAULT)
1169 real_papersize = lyxrc.default_papersize;
1171 switch (real_papersize) {
1180 case PAPER_EXECUTIVEPAPER:
1182 case PAPER_LEGALPAPER:
1184 case PAPER_USLETTER:
1191 string const BufferParams::dvips_options() const
1196 && papersize2 == VM_PAPER_CUSTOM
1197 && !lyxrc.print_paper_dimension_flag.empty()
1198 && !paperwidth.empty()
1199 && !paperheight.empty()) {
1200 // using a custom papersize
1201 result = lyxrc.print_paper_dimension_flag;
1202 result += ' ' + paperwidth;
1203 result += ',' + paperheight;
1205 string const paper_option = paperSizeName();
1206 if (paper_option != "letter" ||
1207 orientation != ORIENTATION_LANDSCAPE) {
1208 // dvips won't accept -t letter -t landscape.
1209 // In all other cases, include the paper size
1211 result = lyxrc.print_paper_flag;
1212 result += ' ' + paper_option;
1215 if (orientation == ORIENTATION_LANDSCAPE &&
1216 papersize2 != VM_PAPER_CUSTOM)
1217 result += ' ' + lyxrc.print_landscape_flag;
1222 string const BufferParams::babelCall(string const & lang_opts) const
1224 string tmp = lyxrc.language_package;
1225 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1226 tmp = string("\\usepackage[") + lang_opts + "]{babel}";