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;
119 tracking_changes = false;
122 language = default_language;
125 graphicsDriver = "default";
126 sides = LyXTextClass::OneSide;
128 pagestyle = "default";
130 for (int iter = 0; iter < 4; ++iter) {
131 user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
132 temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
137 BufferParams::~BufferParams()
141 AuthorList & BufferParams::authors()
143 return pimpl_->authorlist;
147 AuthorList const & BufferParams::authors() const
149 return pimpl_->authorlist;
153 BranchList & BufferParams::branchlist()
155 return pimpl_->branchlist;
159 BranchList const & BufferParams::branchlist() const
161 return pimpl_->branchlist;
165 Bullet & BufferParams::temp_bullet(lyx::size_type index)
167 BOOST_ASSERT(index < 4);
168 return pimpl_->temp_bullets[index];
172 Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
174 BOOST_ASSERT(index < 4);
175 return pimpl_->temp_bullets[index];
179 Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
181 BOOST_ASSERT(index < 4);
182 return pimpl_->user_defined_bullets[index];
186 Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
188 BOOST_ASSERT(index < 4);
189 return pimpl_->user_defined_bullets[index];
193 Spacing & BufferParams::spacing()
195 return pimpl_->spacing;
199 Spacing const & BufferParams::spacing() const
201 return pimpl_->spacing;
205 VSpace const & BufferParams::getDefSkip() const
207 return pimpl_->defskip;
211 void BufferParams::setDefSkip(VSpace const & vs)
213 pimpl_->defskip = vs;
217 string const BufferParams::readToken(LyXLex & lex, string const & token)
219 if (token == "\\textclass") {
221 string const classname = lex.getString();
222 pair<bool, lyx::textclass_type> pp =
223 textclasslist.NumberOfClass(classname);
225 textclass = pp.second;
230 if (!getLyXTextClass().isTeXClassAvailable()) {
231 string msg = bformat(_("The document uses a missing "
232 "TeX class \"%1$s\".\n"), classname);
233 Alert::warning(_("Document class not available"),
234 msg + _("LyX will not be able to produce output."));
236 } else if (token == "\\begin_preamble") {
238 } else if (token == "\\options") {
240 options = lex.getString();
241 } else if (token == "\\language") {
243 } else if (token == "\\inputencoding") {
245 inputenc = lex.getString();
246 } else if (token == "\\graphics") {
247 readGraphicsDriver(lex);
248 } else if (token == "\\fontscheme") {
250 fonts = lex.getString();
251 } else if (token == "\\paragraph_separation") {
252 int tmpret = lex.findToken(string_paragraph_separation);
255 paragraph_separation =
256 static_cast<PARSEP>(tmpret);
257 } else if (token == "\\defskip") {
259 pimpl_->defskip = VSpace(lex.getString());
260 } else if (token == "\\quotes_language") {
261 // FIXME: should be params.readQuotes()
262 int tmpret = lex.findToken(string_quotes_language);
265 InsetQuotes::quote_language tmpl =
266 InsetQuotes::EnglishQ;
269 tmpl = InsetQuotes::EnglishQ;
272 tmpl = InsetQuotes::SwedishQ;
275 tmpl = InsetQuotes::GermanQ;
278 tmpl = InsetQuotes::PolishQ;
281 tmpl = InsetQuotes::FrenchQ;
284 tmpl = InsetQuotes::DanishQ;
287 quotes_language = tmpl;
288 } else if (token == "\\quotes_times") {
289 // FIXME: should be params.readQuotes()
291 switch (lex.getInteger()) {
293 quotes_times = InsetQuotes::SingleQ;
296 quotes_times = InsetQuotes::DoubleQ;
299 } else if (token == "\\papersize") {
300 int tmpret = lex.findToken(string_papersize);
304 papersize2 = VMARGIN_PAPER_TYPE(tmpret);
305 } else if (token == "\\paperpackage") {
306 int tmpret = lex.findToken(string_paperpackages);
309 paperpackage = PACKAGE_NONE;
311 paperpackage = PAPER_PACKAGES(tmpret);
312 } else if (token == "\\use_geometry") {
314 use_geometry = lex.getInteger();
315 } else if (token == "\\use_amsmath") {
317 use_amsmath = static_cast<AMS>(
319 } else if (token == "\\use_natbib") {
321 use_natbib = lex.getInteger();
322 } else if (token == "\\use_numerical_citations") {
324 use_numerical_citations = lex.getInteger();
325 } else if (token == "\\use_jurabib") {
327 use_jurabib = lex.getInteger();
328 } else if (token == "\\tracking_changes") {
330 tracking_changes = lex.getInteger();
331 } else if (token == "\\branch") {
333 string branch = lex.getString();
334 branchlist().add(branch);
337 string const tok = lex.getString();
338 if (tok == "\\end_branch")
340 Branch * branch_ptr = branchlist().find(branch);
341 if (tok == "\\selected") {
344 branch_ptr->setSelected(lex.getInteger());
346 // not yet operational
347 if (tok == "\\color") {
349 string color = lex.getString();
351 branch_ptr->setColor(color);
352 // Update also the LColor table:
354 color = lcolor.getX11Name(LColor::background);
355 lcolor.setColor(lcolor.getFromLyXName(branch), color);
358 } else if (token == "\\author") {
360 istringstream ss(lex.getString());
363 author_map.push_back(pimpl_->authorlist.record(a));
364 } else if (token == "\\paperorientation") {
365 int tmpret = lex.findToken(string_orientation);
369 static_cast<PAPER_ORIENTATION>(tmpret);
370 } else if (token == "\\paperwidth") {
372 paperwidth = lex.getString();
373 } else if (token == "\\paperheight") {
375 paperheight = lex.getString();
376 } else if (token == "\\leftmargin") {
378 leftmargin = lex.getString();
379 } else if (token == "\\topmargin") {
381 topmargin = lex.getString();
382 } else if (token == "\\rightmargin") {
384 rightmargin = lex.getString();
385 } else if (token == "\\bottommargin") {
387 bottommargin = lex.getString();
388 } else if (token == "\\headheight") {
390 headheight = lex.getString();
391 } else if (token == "\\headsep") {
393 headsep = lex.getString();
394 } else if (token == "\\footskip") {
396 footskip = lex.getString();
397 } else if (token == "\\paperfontsize") {
399 fontsize = rtrim(lex.getString());
400 } else if (token == "\\papercolumns") {
402 columns = lex.getInteger();
403 } else if (token == "\\papersides") {
405 switch (lex.getInteger()) {
407 case 1: sides = LyXTextClass::OneSide; break;
408 case 2: sides = LyXTextClass::TwoSides; break;
410 } else if (token == "\\paperpagestyle") {
412 pagestyle = rtrim(lex.getString());
413 } else if (token == "\\bullet") {
414 // FIXME: should be params.readBullets()
416 int const index = lex.getInteger();
418 int temp_int = lex.getInteger();
419 user_defined_bullet(index).setFont(temp_int);
420 temp_bullet(index).setFont(temp_int);
422 temp_int = lex.getInteger();
423 user_defined_bullet(index).setCharacter(temp_int);
424 temp_bullet(index).setCharacter(temp_int);
426 temp_int = lex.getInteger();
427 user_defined_bullet(index).setSize(temp_int);
428 temp_bullet(index).setSize(temp_int);
430 string const temp_str = lex.getString();
431 if (temp_str != "\\end_bullet") {
432 // this element isn't really necessary for
433 // parsing but is easier for humans
434 // to understand bullets. Put it back and
435 // set a debug message?
436 lex.printError("\\end_bullet expected, got" + temp_str);
437 //how can I put it back?
439 } else if (token == "\\bulletLaTeX") {
440 // The bullet class should be able to read this.
442 int const index = lex.getInteger();
444 string temp_str = lex.getString();
446 while (temp_str != "\\end_bullet") {
447 // this loop structure is needed when user
448 // enters an empty string since the first
449 // thing returned will be the \\end_bullet
451 // if the LaTeX entry has spaces. Each element
452 // therefore needs to be read in turn
455 temp_str = lex.getString();
458 user_defined_bullet(index).setText(sum_str);
459 temp_bullet(index).setText(sum_str);
460 } else if (token == "\\secnumdepth") {
462 secnumdepth = lex.getInteger();
463 } else if (token == "\\tocdepth") {
465 tocdepth = lex.getInteger();
466 } else if (token == "\\spacing") {
468 string const tmp = rtrim(lex.getString());
469 Spacing::Space tmp_space = Spacing::Default;
471 if (tmp == "single") {
472 tmp_space = Spacing::Single;
473 } else if (tmp == "onehalf") {
474 tmp_space = Spacing::Onehalf;
475 } else if (tmp == "double") {
476 tmp_space = Spacing::Double;
477 } else if (tmp == "other") {
479 tmp_space = Spacing::Other;
480 tmp_val = lex.getFloat();
482 lex.printError("Unknown spacing token: '$$Token'");
484 #if 0 // FIXME: Handled in lyx2lyx ?
485 // Small hack so that files written with klyx will be
488 par->params().spacing(Spacing(tmp_space, tmp_val));
490 spacing().set(tmp_space, tmp_val);
491 } else if (token == "\\float_placement") {
493 float_placement = lex.getString();
502 void BufferParams::writeFile(ostream & os) const
504 // The top of the file is written by the buffer.
505 // Prints out the buffer info into the .lyx file given by file
508 os << "\\textclass " << textclasslist[textclass].name() << '\n';
510 // then the the preamble
511 if (!preamble.empty()) {
512 // remove '\n' from the end of preamble
513 string const tmppreamble = rtrim(preamble, "\n");
514 os << "\\begin_preamble\n"
516 << "\n\\end_preamble\n";
520 if (!options.empty()) {
521 os << "\\options " << options << '\n';
524 /* then the text parameters */
525 if (language != ignore_language)
526 os << "\\language " << language->lang() << '\n';
527 os << "\\inputencoding " << inputenc
528 << "\n\\fontscheme " << fonts
529 << "\n\\graphics " << graphicsDriver << '\n';
531 if (!float_placement.empty()) {
532 os << "\\float_placement " << float_placement << '\n';
534 os << "\\paperfontsize " << fontsize << '\n';
536 spacing().writeFile(os);
538 os << "\\papersize " << string_papersize[papersize2]
539 << "\n\\paperpackage " << string_paperpackages[paperpackage]
540 << "\n\\use_geometry " << use_geometry
541 << "\n\\use_amsmath " << use_amsmath
542 << "\n\\use_natbib " << use_natbib
543 << "\n\\use_numerical_citations " << use_numerical_citations
544 << "\n\\use_jurabib " << use_jurabib
545 << "\n\\paperorientation " << string_orientation[orientation]
548 std::list<Branch>::const_iterator it = branchlist().begin();
549 std::list<Branch>::const_iterator end = branchlist().end();
550 for (; it != end; ++it) {
551 os << "\\branch " << it->getBranch()
552 << "\n\\selected " << it->getSelected()
553 << "\n\\color " << it->getColor()
558 if (!paperwidth.empty())
559 os << "\\paperwidth "
560 << VSpace(paperwidth).asLyXCommand() << '\n';
561 if (!paperheight.empty())
562 os << "\\paperheight "
563 << VSpace(paperheight).asLyXCommand() << '\n';
564 if (!leftmargin.empty())
565 os << "\\leftmargin "
566 << VSpace(leftmargin).asLyXCommand() << '\n';
567 if (!topmargin.empty())
569 << VSpace(topmargin).asLyXCommand() << '\n';
570 if (!rightmargin.empty())
571 os << "\\rightmargin "
572 << VSpace(rightmargin).asLyXCommand() << '\n';
573 if (!bottommargin.empty())
574 os << "\\bottommargin "
575 << VSpace(bottommargin).asLyXCommand() << '\n';
576 if (!headheight.empty())
577 os << "\\headheight "
578 << VSpace(headheight).asLyXCommand() << '\n';
579 if (!headsep.empty())
581 << VSpace(headsep).asLyXCommand() << '\n';
582 if (!footskip.empty())
584 << VSpace(footskip).asLyXCommand() << '\n';
585 os << "\\secnumdepth " << secnumdepth
586 << "\n\\tocdepth " << tocdepth
587 << "\n\\paragraph_separation "
588 << string_paragraph_separation[paragraph_separation]
589 << "\n\\defskip " << getDefSkip().asLyXCommand()
590 << "\n\\quotes_language "
591 << string_quotes_language[quotes_language] << '\n';
592 switch (quotes_times) {
593 // An output operator for insetquotes would be nice
594 case InsetQuotes::SingleQ:
595 os << "\\quotes_times 1\n"; break;
596 case InsetQuotes::DoubleQ:
597 os << "\\quotes_times 2\n"; break;
599 os << "\\papercolumns " << columns
600 << "\n\\papersides " << sides
601 << "\n\\paperpagestyle " << pagestyle << '\n';
602 for (int i = 0; i < 4; ++i) {
603 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
604 if (user_defined_bullet(i).getFont() != -1) {
605 os << "\\bullet " << i
607 << user_defined_bullet(i).getFont()
609 << user_defined_bullet(i).getCharacter()
611 << user_defined_bullet(i).getSize()
612 << "\n\\end_bullet\n";
615 os << "\\bulletLaTeX " << i
617 << user_defined_bullet(i).getText()
618 << "\"\n\\end_bullet\n";
623 os << "\\tracking_changes " << tracking_changes << "\n";
625 if (tracking_changes) {
626 AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
627 AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
628 for (; it != end; ++it) {
629 os << "\\author " << it->second << "\n";
635 bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
636 TexRow & texrow) const
638 os << "\\documentclass";
640 LyXTextClass const & tclass = getLyXTextClass();
642 ostringstream clsoptions; // the document class options.
644 if (tokenPos(tclass.opt_fontsize(),
645 '|', fontsize) >= 0) {
646 // only write if existing in list (and not default)
647 clsoptions << fontsize << "pt,";
652 (paperpackage == PACKAGE_NONE)) {
655 clsoptions << "a3paper,";
658 clsoptions << "a4paper,";
661 clsoptions << "letterpaper,";
664 clsoptions << "a5paper,";
667 clsoptions << "b5paper,";
669 case PAPER_EXECUTIVEPAPER:
670 clsoptions << "executivepaper,";
672 case PAPER_LEGALPAPER:
673 clsoptions << "legalpaper,";
681 if (sides != tclass.sides()) {
683 case LyXTextClass::OneSide:
684 clsoptions << "oneside,";
686 case LyXTextClass::TwoSides:
687 clsoptions << "twoside,";
693 if (columns != tclass.columns()) {
695 clsoptions << "twocolumn,";
697 clsoptions << "onecolumn,";
701 && orientation == ORIENTATION_LANDSCAPE)
702 clsoptions << "landscape,";
704 // language should be a parameter to \documentclass
705 if (language->babel() == "hebrew"
706 && default_language->babel() != "hebrew")
707 // This seems necessary
708 features.useLanguage(default_language);
710 ostringstream language_options;
711 bool const use_babel = features.useBabel();
713 language_options << features.getLanguages();
714 language_options << language->babel();
715 if (lyxrc.language_global_options)
716 clsoptions << language_options.str() << ',';
719 // the user-defined options
720 if (!options.empty()) {
721 clsoptions << options << ',';
724 string strOptions(clsoptions.str());
725 if (!strOptions.empty()) {
726 strOptions = rtrim(strOptions, ",");
727 os << '[' << strOptions << ']';
730 os << '{' << tclass.latexname() << "}\n";
732 // end of \documentclass defs
734 // font selection must be done before loading fontenc.sty
735 // The ae package is not needed when using OT1 font encoding.
736 if (fonts != "default" &&
737 (fonts != "ae" || lyxrc.fontenc != "default")) {
738 os << "\\usepackage{" << fonts << "}\n";
741 os << "\\usepackage{aecompl}\n";
745 // this one is not per buffer
746 if (lyxrc.fontenc != "default") {
747 os << "\\usepackage[" << lyxrc.fontenc
752 if (inputenc == "auto") {
753 string const doc_encoding =
754 language->encoding()->LatexName();
756 // Create a list with all the input encodings used
758 std::set<string> encodings =
759 features.getEncodingSet(doc_encoding);
761 os << "\\usepackage[";
762 std::copy(encodings.begin(), encodings.end(),
763 std::ostream_iterator<string>(os, ","));
764 os << doc_encoding << "]{inputenc}\n";
766 } else if (inputenc != "default") {
767 os << "\\usepackage[" << inputenc
772 // At the very beginning the text parameters.
773 if (paperpackage != PACKAGE_NONE) {
774 switch (paperpackage) {
778 os << "\\usepackage{a4}\n";
782 os << "\\usepackage{a4wide}\n";
785 case PACKAGE_WIDEMARGINSA4:
786 os << "\\usepackage[widemargins]{a4}\n";
792 os << "\\usepackage{geometry}\n";
794 os << "\\geometry{verbose";
795 if (orientation == ORIENTATION_LANDSCAPE)
797 switch (papersize2) {
798 case VM_PAPER_CUSTOM:
799 if (!paperwidth.empty())
802 if (!paperheight.empty())
803 os << ",paperheight="
806 case VM_PAPER_USLETTER:
807 os << ",letterpaper";
809 case VM_PAPER_USLEGAL:
812 case VM_PAPER_USEXECUTIVE:
813 os << ",executivepaper";
834 // default papersize ie VM_PAPER_DEFAULT
835 switch (lyxrc.default_papersize) {
836 case PAPER_DEFAULT: // keep compiler happy
838 os << ",letterpaper";
840 case PAPER_LEGALPAPER:
843 case PAPER_EXECUTIVEPAPER:
844 os << ",executivepaper";
860 if (!topmargin.empty())
861 os << ",tmargin=" << topmargin;
862 if (!bottommargin.empty())
863 os << ",bmargin=" << bottommargin;
864 if (!leftmargin.empty())
865 os << ",lmargin=" << leftmargin;
866 if (!rightmargin.empty())
867 os << ",rmargin=" << rightmargin;
868 if (!headheight.empty())
869 os << ",headheight=" << headheight;
870 if (!headsep.empty())
871 os << ",headsep=" << headsep;
872 if (!footskip.empty())
873 os << ",footskip=" << footskip;
878 if (tokenPos(tclass.opt_pagestyle(),
879 '|', pagestyle) >= 0) {
880 if (pagestyle == "fancy") {
881 os << "\\usepackage{fancyhdr}\n";
884 os << "\\pagestyle{" << pagestyle << "}\n";
888 if (secnumdepth != tclass.secnumdepth()) {
889 os << "\\setcounter{secnumdepth}{"
894 if (tocdepth != tclass.tocdepth()) {
895 os << "\\setcounter{tocdepth}{"
901 if (paragraph_separation) {
902 switch (getDefSkip().kind()) {
903 case VSpace::SMALLSKIP:
904 os << "\\setlength\\parskip{\\smallskipamount}\n";
906 case VSpace::MEDSKIP:
907 os << "\\setlength\\parskip{\\medskipamount}\n";
909 case VSpace::BIGSKIP:
910 os << "\\setlength\\parskip{\\bigskipamount}\n";
913 os << "\\setlength\\parskip{"
914 << getDefSkip().length().asLatexString()
917 default: // should never happen // Then delete it.
918 os << "\\setlength\\parskip{\\medskipamount}\n";
923 os << "\\setlength\\parindent{0pt}\n";
927 // If we use jurabib, we have to call babel here.
928 if (use_babel && features.isRequired("jurabib")) {
929 os << babelCall(language_options.str())
931 << features.getBabelOptions();
935 // Now insert the LyX specific LaTeX commands...
937 // The optional packages;
938 string lyxpreamble(features.getPackages());
940 // this might be useful...
941 lyxpreamble += "\n\\makeatletter\n";
943 // Some macros LyX will need
944 string tmppreamble(features.getMacros());
946 if (!tmppreamble.empty()) {
947 lyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
948 "LyX specific LaTeX commands.\n"
949 + tmppreamble + '\n';
952 // the text class specific preamble
953 tmppreamble = features.getTClassPreamble();
954 if (!tmppreamble.empty()) {
955 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
956 "Textclass specific LaTeX commands.\n"
957 + tmppreamble + '\n';
960 /* the user-defined preamble */
961 if (!preamble.empty()) {
962 lyxpreamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
963 "User specified LaTeX commands.\n"
967 // Itemize bullet settings need to be last in case the user
968 // defines their own bullets that use a package included
969 // in the user-defined preamble -- ARRae
970 // Actually it has to be done much later than that
971 // since some packages like frenchb make modifications
972 // at \begin{document} time -- JMarc
974 for (int i = 0; i < 4; ++i) {
975 if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
976 if (bullets_def.empty())
977 bullets_def="\\AtBeginDocument{\n";
978 bullets_def += " \\renewcommand{\\labelitemi";
980 // `i' is one less than the item to modify
993 bullets_def += "}{" +
994 user_defined_bullet(i).getText()
999 if (!bullets_def.empty())
1000 lyxpreamble += bullets_def + "}\n\n";
1002 // We try to load babel late, in case it interferes
1003 // with other packages.
1004 // Jurabib has to be called after babel, though.
1005 if (use_babel && !features.isRequired("jurabib")) {
1006 lyxpreamble += babelCall(language_options.str()) + '\n';
1007 lyxpreamble += features.getBabelOptions();
1010 lyxpreamble += "\\makeatother\n";
1012 // dvipost settings come after everything else
1013 if (tracking_changes) {
1016 "\\dvipost{osstart color push Red}\n"
1017 "\\dvipost{osend color pop}\n"
1018 "\\dvipost{cbstart color push Blue}\n"
1019 "\\dvipost{cbend color pop} \n";
1023 int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n'));
1024 for (int j = 0; j != nlines; ++j) {
1032 void BufferParams::setPaperStuff()
1034 papersize = PAPER_DEFAULT;
1035 char const c1 = paperpackage;
1036 if (c1 == PACKAGE_NONE) {
1037 char const c2 = papersize2;
1038 if (c2 == VM_PAPER_USLETTER)
1039 papersize = PAPER_USLETTER;
1040 else if (c2 == VM_PAPER_USLEGAL)
1041 papersize = PAPER_LEGALPAPER;
1042 else if (c2 == VM_PAPER_USEXECUTIVE)
1043 papersize = PAPER_EXECUTIVEPAPER;
1044 else if (c2 == VM_PAPER_A3)
1045 papersize = PAPER_A3PAPER;
1046 else if (c2 == VM_PAPER_A4)
1047 papersize = PAPER_A4PAPER;
1048 else if (c2 == VM_PAPER_A5)
1049 papersize = PAPER_A5PAPER;
1050 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
1051 (c2 == VM_PAPER_B5))
1052 papersize = PAPER_B5PAPER;
1053 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
1054 (c1 == PACKAGE_WIDEMARGINSA4))
1055 papersize = PAPER_A4PAPER;
1059 void BufferParams::useClassDefaults()
1061 LyXTextClass const & tclass = textclasslist[textclass];
1063 sides = tclass.sides();
1064 columns = tclass.columns();
1065 pagestyle = tclass.pagestyle();
1066 options = tclass.options();
1067 secnumdepth = tclass.secnumdepth();
1068 tocdepth = tclass.tocdepth();
1072 bool BufferParams::hasClassDefaults() const
1074 LyXTextClass const & tclass = textclasslist[textclass];
1076 return (sides == tclass.sides()
1077 && columns == tclass.columns()
1078 && pagestyle == tclass.pagestyle()
1079 && options == tclass.options()
1080 && secnumdepth == tclass.secnumdepth()
1081 && tocdepth == tclass.tocdepth());
1085 LyXTextClass const & BufferParams::getLyXTextClass() const
1087 return textclasslist[textclass];
1091 void BufferParams::readPreamble(LyXLex & lex)
1093 if (lex.getString() != "\\begin_preamble")
1094 lyxerr << "Error (BufferParams::readPreamble):"
1095 "consistency check failed." << endl;
1097 preamble = lex.getLongString("\\end_preamble");
1101 void BufferParams::readLanguage(LyXLex & lex)
1103 if (!lex.next()) return;
1105 string const tmptok = lex.getString();
1107 // check if tmptok is part of tex_babel in tex-defs.h
1108 language = languages.getLanguage(tmptok);
1110 // Language tmptok was not found
1111 language = default_language;
1112 lyxerr << "Warning: Setting language `"
1113 << tmptok << "' to `" << language->lang()
1119 void BufferParams::readGraphicsDriver(LyXLex & lex)
1121 if (!lex.next()) return;
1123 string const tmptok = lex.getString();
1124 // check if tmptok is part of tex_graphics in tex_defs.h
1127 string const test = tex_graphics[n++];
1129 if (test == tmptok) {
1130 graphicsDriver = tmptok;
1132 } else if (test == "last_item") {
1134 "Warning: graphics driver `$$Token' not recognized!\n"
1135 " Setting graphics driver to `default'.\n");
1136 graphicsDriver = "default";
1143 string const BufferParams::paperSizeName() const
1145 char real_papersize = papersize;
1146 if (real_papersize == PAPER_DEFAULT)
1147 real_papersize = lyxrc.default_papersize;
1149 switch (real_papersize) {
1158 case PAPER_EXECUTIVEPAPER:
1160 case PAPER_LEGALPAPER:
1162 case PAPER_USLETTER:
1169 string const BufferParams::dvips_options() const
1174 && papersize2 == VM_PAPER_CUSTOM
1175 && !lyxrc.print_paper_dimension_flag.empty()
1176 && !paperwidth.empty()
1177 && !paperheight.empty()) {
1178 // using a custom papersize
1179 result = lyxrc.print_paper_dimension_flag;
1180 result += ' ' + paperwidth;
1181 result += ',' + paperheight;
1183 string const paper_option = paperSizeName();
1184 if (paper_option != "letter" ||
1185 orientation != ORIENTATION_LANDSCAPE) {
1186 // dvips won't accept -t letter -t landscape.
1187 // In all other cases, include the paper size
1189 result = lyxrc.print_paper_flag;
1190 result += ' ' + paper_option;
1193 if (orientation == ORIENTATION_LANDSCAPE &&
1194 papersize2 != VM_PAPER_CUSTOM)
1195 result += ' ' + lyxrc.print_landscape_flag;
1200 string const BufferParams::babelCall(string const & lang_opts) const
1202 string tmp = lyxrc.language_package;
1203 if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
1204 tmp = string("\\usepackage[") + lang_opts + "]{babel}";