2 * \file LaTeXFeatures.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
17 #include "LaTeXFeatures.h"
20 #include "BufferParams.h"
22 #include "Converter.h"
25 #include "FloatList.h"
30 #include "TextClass.h"
32 #include "insets/InsetLayout.h"
34 #include "support/debug.h"
35 #include "support/docstream.h"
36 #include "support/FileName.h"
37 #include "support/filetools.h"
38 #include "support/gettext.h"
39 #include "support/lstrings.h"
42 using namespace lyx::support;
47 /////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////
53 //\NeedsTeXFormat{LaTeX2e}
54 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
55 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
57 static docstring const lyx_def = from_ascii(
58 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
60 static docstring const lyxline_def = from_ascii(
61 "\\newcommand{\\lyxline}[1][1pt]{%\n"
63 " \\rule[.5ex]{\\linewidth}{#1}\\par}");
65 static docstring const noun_def = from_ascii(
66 "\\newcommand{\\noun}[1]{\\textsc{#1}}");
68 static docstring const lyxarrow_def = from_ascii(
69 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
71 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
72 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
74 // for quotes without babel. This does not give perfect results, but
75 // anybody serious about non-english quotes should use babel (JMarc).
77 static docstring const quotedblbase_def = from_ascii(
78 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
79 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
80 " \\penalty10000\\hskip0em\\relax%\n"
83 static docstring const quotesinglbase_def = from_ascii(
84 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
85 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
86 " \\penalty10000\\hskip0em\\relax%\n"
89 static docstring const guillemotleft_def = from_ascii(
90 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
91 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
92 "\\penalty10000\\hskip0pt\\relax%\n"
95 static docstring const guillemotright_def = from_ascii(
96 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
97 " \\penalty10000\\hskip0pt%\n"
98 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
101 static docstring const guilsinglleft_def = from_ascii(
102 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
103 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
104 " \\penalty10000\\hskip0pt\\relax%\n"
107 static docstring const guilsinglright_def = from_ascii(
108 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
109 " \\penalty10000\\hskip0pt%\n"
110 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
113 static docstring const paragraphleftindent_def = from_ascii(
114 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
116 " \\begin{list}{}{%\n"
117 " \\setlength{\\topsep}{0pt}%\n"
118 " \\addtolength{\\leftmargin}{#1}\n"
119 // ho hum, yet more things commented out with no hint as to why they
120 // weren't just removed
121 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
122 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
123 // "%% \\setlength\\listparindent\\parindent%\n"
124 // "%% \\setlength\\itemindent\\parindent%\n"
125 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
131 static docstring const floatingfootnote_def = from_ascii(
132 "%% Special footnote code from the package 'stblftnt.sty'\n"
133 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
134 "\\let\\SF@@footnote\\footnote\n"
135 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
136 " \\expandafter\\SF@@footnote\n"
138 " \\expandafter\\SF@gobble@opt\n"
141 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
142 " \\SF@gobble@twobracket\n"
145 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
146 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
147 "\\def\\SF@gobble@twobracket[#1]#2{}\n");
149 static docstring const binom_def = from_ascii(
150 "%% Binom macro for standard LaTeX users\n"
151 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
153 static docstring const mathcircumflex_def = from_ascii(
154 "%% For printing a cirumflex inside a formula\n"
155 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
157 static docstring const tabularnewline_def = from_ascii(
158 "%% Because html converters don't know tabularnewline\n"
159 "\\providecommand{\\tabularnewline}{\\\\}\n");
161 static docstring const lyxgreyedout_def = from_ascii(
162 "%% The greyedout annotation environment\n"
163 "\\newenvironment{lyxgreyedout}{\\textcolor[gray]{0.8}\\bgroup}{\\egroup}\n");
165 // We want to omit the file extension for includegraphics, but this does not
166 // work when the filename contains other dots.
167 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
168 static docstring const lyxdot_def = from_ascii(
169 "%% A simple dot to overcome graphicx limitations\n"
170 "\\newcommand{\\lyxdot}{.}\n");
172 static docstring const changetracking_dvipost_def = from_ascii(
173 "%% Change tracking with dvipost\n"
175 "\\dvipost{osstart color push Red}\n"
176 "\\dvipost{osend color pop}\n"
177 "\\dvipost{cbstart color push Blue}\n"
178 "\\dvipost{cbend color pop}\n"
179 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
180 "\\newcommand{\\lyxdeleted}[3]{%\n"
181 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n");
183 static docstring const changetracking_xcolor_ulem_def = from_ascii(
184 "%% Change tracking with ulem\n"
185 "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}{}#3}}\n"
186 "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
188 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
189 "%% Change tracking with ulem\n"
190 "\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}{}}{}#3}}\n"
191 "\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
193 static docstring const changetracking_none_def = from_ascii(
194 "\\newcommand{\\lyxadded}[3]{#3}\n"
195 "\\newcommand{\\lyxdeleted}[3]{}\n");
197 static docstring const textgreek_def = from_ascii(
198 "\\AtBeginDocument{\\DeclareRobustCommand{\\greektext}{%\n"
199 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}%\n"
200 " \\renewcommand{\\~}{\\char126}%\n"
202 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
203 "\\DeclareFontEncoding{LGR}{}{}\n");
205 static docstring const textcyr_def = from_ascii(
206 "\\DeclareRobustCommand{\\cyrtext}{%\n"
207 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
208 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
209 "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n");
211 static docstring const lyxmathsym_def = from_ascii(
212 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
213 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
215 static docstring const papersizedvi_def = from_ascii(
216 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
218 static docstring const papersizepdf_def = from_ascii(
219 "\\pdfpageheight\\paperheight\n"
220 "\\pdfpagewidth\\paperwidth\n");
222 static docstring const cedilla_def = from_ascii(
223 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
224 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
226 static docstring const subring_def = from_ascii(
227 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
228 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
230 static docstring const subdot_def = from_ascii(
231 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
232 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
234 static docstring const subhat_def = from_ascii(
235 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
236 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
238 static docstring const subtilde_def = from_ascii(
239 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
240 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
242 static docstring const dacute_def = from_ascii(
243 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
245 static docstring const tipasymb_def = from_ascii(
246 "\\DeclareFontEncoding{T3}{}{}\n"
247 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
249 static docstring const dgrave_def = from_ascii(
250 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
252 static docstring const rcap_def = from_ascii(
253 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
255 static docstring const ogonek_def = from_ascii(
256 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
257 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
258 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
259 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
260 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
262 /////////////////////////////////////////////////////////////////////
266 /////////////////////////////////////////////////////////////////////
268 LaTeXFeatures::Packages LaTeXFeatures::packages_;
271 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
272 OutputParams const & r)
273 : buffer_(&b), params_(p), runparams_(r), in_float_(false)
277 bool LaTeXFeatures::useBabel() const
279 return lyxrc.language_use_babel ||
280 (bufferParams().language->lang() != lyxrc.default_language &&
281 !bufferParams().language->babel().empty()) ||
282 this->hasLanguages();
286 void LaTeXFeatures::require(string const & name)
288 features_.insert(name);
292 void LaTeXFeatures::require(set<string> const & names)
294 features_.insert(names.begin(), names.end());
298 void LaTeXFeatures::getAvailable()
301 support::FileName const real_file = libFileSearch("", "packages.lst");
303 if (real_file.empty())
306 lex.setFile(real_file);
311 // Make sure that we are clean
314 bool finished = false;
316 while (lex.isOK() && !finished) {
318 case Lexer::LEX_FEOF:
322 packages_.insert(lex.getString());
328 void LaTeXFeatures::useLayout(docstring const & layoutname)
330 // Some code to avoid loops in dependency definition
331 static int level = 0;
332 const int maxlevel = 30;
333 if (level > maxlevel) {
334 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
335 << "recursion attained by layout "
336 << to_utf8(layoutname) << endl;
340 DocumentClass const & tclass = params_.documentClass();
341 if (tclass.hasLayout(layoutname)) {
342 // Is this layout already in usedLayouts?
343 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
344 != usedLayouts_.end())
347 Layout const & layout = tclass[layoutname];
348 require(layout.requires());
350 if (!layout.depends_on().empty()) {
352 useLayout(layout.depends_on());
355 usedLayouts_.push_back(layoutname);
357 lyxerr << "LaTeXFeatures::useLayout: layout `"
358 << to_utf8(layoutname) << "' does not exist in this class"
366 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
368 docstring const & lname = lay.name();
369 DocumentClass const & tclass = params_.documentClass();
371 // this is a default inset layout, nothing useful here
372 if (!tclass.hasInsetLayout(lname))
374 // Is this layout already in usedInsetLayouts?
375 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
376 != usedInsetLayouts_.end())
379 require(lay.requires());
380 usedInsetLayouts_.push_back(lname);
384 bool LaTeXFeatures::isRequired(string const & name) const
386 return features_.find(name) != features_.end();
390 bool LaTeXFeatures::mustProvide(string const & name) const
392 return isRequired(name) && !params_.documentClass().provides(name);
396 bool LaTeXFeatures::isAvailable(string const & name)
398 string::size_type const i = name.find("->");
399 if (i != string::npos) {
400 string const from = name.substr(0,i);
401 string const to = name.substr(i+2);
402 //LYXERR0("from=[" << from << "] to=[" << to << "]");
403 return theConverters().isReachable(from, to);
406 if (packages_.empty())
409 if (suffixIs(n, ".sty"))
410 n.erase(name.length() - 4);
411 return packages_.find(n) != packages_.end();
415 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
418 SnippetList::const_iterator begin = preamble_snippets_.begin();
419 SnippetList::const_iterator end = preamble_snippets_.end();
420 if (find(begin, end, preamble) == end)
421 preamble_snippets_.push_back(preamble);
425 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
427 if (!usedFloats_[name])
428 usedFloats_[name] = subfloat;
431 // We only need float.sty if we use non builtin floats, or if we
432 // use the "H" modifier. This includes modified table and
433 // figure floats. (Lgb)
434 Floating const & fl = params_.documentClass().floats().getType(name);
435 if (!fl.type().empty() && !fl.builtin()) {
441 void LaTeXFeatures::useLanguage(Language const * lang)
443 if (!lang->babel().empty())
444 UsedLanguages_.insert(lang);
445 if (lang->lang() == "vietnamese")
446 require("vietnamese");
447 // CJK languages do not have a babel name.
448 // They use the CJK package
449 if (lang->encoding()->package() == Encoding::CJK)
451 // japanese package is special
452 if (lang->encoding()->package() == Encoding::japanese)
457 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
459 IncludedFiles_[key] = name;
463 bool LaTeXFeatures::hasLanguages() const
465 return !UsedLanguages_.empty();
469 string LaTeXFeatures::getLanguages() const
471 ostringstream languages;
473 LanguageList::const_iterator const begin = UsedLanguages_.begin();
474 for (LanguageList::const_iterator cit = begin;
475 cit != UsedLanguages_.end();
479 languages << (*cit)->babel();
481 return languages.str();
485 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
487 // This does only find encodings of languages supported by babel, but
488 // that does not matter since we don't have a language with an
489 // encoding supported by inputenc but without babel support.
490 set<string> encodings;
491 LanguageList::const_iterator it = UsedLanguages_.begin();
492 LanguageList::const_iterator end = UsedLanguages_.end();
493 for (; it != end; ++it)
494 if ((*it)->encoding()->latexName() != doc_encoding &&
495 ((*it)->encoding()->package() == Encoding::inputenc
496 || (*it)->encoding()->package() == Encoding::japanese))
497 encodings.insert((*it)->encoding()->latexName());
503 char const * simplefeatures[] = {
504 // note that the package order here will be the same in the LaTeX-output
511 // subfig is handled in BufferParams.cpp
514 /*For a successful cooperation of the `wrapfig' package with the
515 `float' package you should load the `wrapfig' package *after*
516 the `float' package. See the caption package documentation
545 // listings is handled in BufferParams.cpp
552 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
557 string const LaTeXFeatures::getColorOptions() const
559 ostringstream colors;
561 // Handling the color packages separately is needed to be able to load them
562 // before babel when hyperref is loaded with the colorlinks option
563 // for more info see Bufferparams.cpp
566 if (mustProvide("color") || mustProvide("xcolor")) {
567 string const package =
568 (mustProvide("xcolor") ? "xcolor" : "color");
569 if (params_.graphicsDriver == "default"
570 || params_.graphicsDriver == "none")
571 colors << "\\usepackage{" << package << "}\n";
573 colors << "\\usepackage["
574 << params_.graphicsDriver
575 << "]{" << package << "}\n";
578 // pdfcolmk must be loaded after color
579 if (mustProvide("pdfcolmk"))
580 colors << "\\usepackage{pdfcolmk}\n";
582 if (mustProvide("pagecolor")) {
583 // the \pagecolor command must be set after color is loaded and
584 // before pdfpages, therefore add the command here
585 // define the set color
586 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
587 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
588 // set the page color
589 colors << "\\pagecolor{page_backgroundcolor}\n";
596 string const LaTeXFeatures::getPackages() const
598 ostringstream packages;
599 DocumentClass const & tclass = params_.documentClass();
601 // FIXME: currently, we can only load packages and macros known
603 // However, with the Require tag of layouts/custom insets,
604 // also inknown packages can be requested. They are silently
605 // swallowed now. We should change this eventually.
608 // These are all the 'simple' includes. i.e
609 // packages which we just \usepackage{package}
611 for (int i = 0; i < nb_simplefeatures; ++i) {
612 if (mustProvide(simplefeatures[i]))
613 packages << "\\usepackage{"
614 << simplefeatures[i] << "}\n";
618 // The rest of these packages are somewhat more complicated
622 // esint is preferred for esintoramsmath
623 if ((mustProvide("amsmath")
624 && params_.use_amsmath != BufferParams::package_off)
625 || (mustProvide("esintoramsmath")
626 && params_.use_esint == BufferParams::package_off
627 && params_.use_amsmath != BufferParams::package_off)) {
628 packages << "\\usepackage{amsmath}\n";
630 // amsbsy and amstext are already provided by amsmath
631 if (mustProvide("amsbsy"))
632 packages << "\\usepackage{amsbsy}\n";
633 if (mustProvide("amstext"))
634 packages << "\\usepackage{amstext}\n";
637 // wasysym is a simple feature, but it must be after amsmath if both
639 // wasysym redefines some integrals (e.g. iint) from amsmath. That
640 // leads to inconsistent integrals. We only load this package if
641 // the document does not contain integrals (then isRequired("esint")
642 // is false) or if esint is used, since esint redefines all relevant
643 // integral symbols from wasysym and amsmath.
644 // See http://bugzilla.lyx.org/show_bug.cgi?id=1942
645 if (mustProvide("wasysym") &&
646 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
647 packages << "\\usepackage{wasysym}\n";
649 // accents must be loaded after amsmath
650 if (mustProvide("accents"))
651 packages << "\\usepackage{accents}\n";
653 // mathdots must be loaded after amsmath
654 if (mustProvide("mathdots"))
655 packages << "\\usepackage{mathdots}\n";
657 // yhmath must be loaded after amsmath
658 if (mustProvide("yhmath"))
659 packages << "\\usepackage{yhmath}\n";
661 // [x]color and pdfcolmk are handled in getColorOptions() above
664 if (isRequired("makeidx") || isRequired("splitidx")) {
665 if (!tclass.provides("makeidx") && !isRequired("splitidx"))
666 packages << "\\usepackage{makeidx}\n";
667 if (!tclass.provides("splitidx") && isRequired("splitidx"))
668 packages << "\\usepackage{splitidx}\n";
669 packages << "\\makeindex\n";
673 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
674 if (params_.graphicsDriver == "default")
675 packages << "\\usepackage{graphicx}\n";
677 packages << "\\usepackage["
678 << params_.graphicsDriver
681 // shadecolor for shaded
682 if (isRequired("framed") && mustProvide("color")) {
683 RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
684 //255.0 to force conversion to double
685 //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
686 //to use the xcolor package instead, and then we can do
687 // \define{shadcolor}{RGB}...
688 //and not do any conversion. We'd then need to require xcolor
689 //in InsetNote::validate().
690 int const stmSize = packages.precision(2);
691 packages << "\\definecolor{shadecolor}{rgb}{"
692 << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
693 packages.precision(stmSize);
696 // lyxskak.sty --- newer chess support based on skak.sty
697 if (mustProvide("chess"))
698 packages << "\\usepackage[ps,mover]{lyxskak}\n";
701 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
702 packages << "\\usepackage{setspace}\n";
705 if (mustProvide("amssymb")
706 || params_.use_amsmath == BufferParams::package_on)
707 packages << "\\usepackage{amssymb}\n";
709 // esint must be after amsmath and wasysym, since it will redeclare
710 // inconsistent integral symbols
711 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
712 params_.use_esint != BufferParams::package_off)
713 packages << "\\usepackage{esint}\n";
716 // Some classes load natbib themselves, but still allow (or even require)
717 // plain numeric citations (ReVTeX is such a case, see bug 5182).
718 // This special case is indicated by the "natbib-internal" key.
719 if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
720 packages << "\\usepackage[";
721 if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
722 packages << "numbers";
724 packages << "authoryear";
725 packages << "]{natbib}\n";
728 // jurabib -- we need version 0.6 at least.
729 if (mustProvide("jurabib"))
730 packages << "\\usepackage{jurabib}[2004/01/25]\n";
732 // xargs -- we need version 1.09 at least
733 if (mustProvide("xargs"))
734 packages << "\\usepackage{xargs}[2008/03/08]\n";
736 // bibtopic -- the dot provides the aux file naming which
738 if (mustProvide("bibtopic"))
739 packages << "\\usepackage[dot]{bibtopic}\n";
741 if (mustProvide("xy"))
742 packages << "\\usepackage[all]{xy}\n";
744 if (mustProvide("ulem"))
745 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
746 "\\usepackage{ulem}\n";
748 if (mustProvide("mhchem") &&
749 params_.use_mhchem != BufferParams::package_off)
750 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
751 "\\usepackage{mhchem}\n";
753 if (mustProvide("nomencl")) {
754 // Make it work with the new and old version of the package,
755 // but don't use the compatibility option since it is
756 // incompatible to other packages.
757 packages << "\\usepackage{nomencl}\n"
758 "% the following is useful when we have the old nomencl.sty package\n"
759 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
760 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
761 "\\makenomenclature\n";
764 return packages.str();
768 string LaTeXFeatures::getPreambleSnippets() const
771 SnippetList::const_iterator pit = preamble_snippets_.begin();
772 SnippetList::const_iterator pend = preamble_snippets_.end();
773 for (; pit != pend; ++pit) {
775 snip << *pit << '\n';
782 docstring const LaTeXFeatures::getMacros() const
784 odocstringstream macros;
786 if (!preamble_snippets_.empty()) {
788 macros << from_utf8(getPreambleSnippets());
791 if (mustProvide("papersize")) {
792 if (runparams_.flavor == OutputParams::LATEX)
793 macros << papersizedvi_def << '\n';
795 macros << papersizepdf_def << '\n';
798 if (mustProvide("LyX"))
799 macros << lyx_def << '\n';
801 if (mustProvide("lyxline"))
802 macros << lyxline_def << '\n';
804 if (mustProvide("noun"))
805 macros << noun_def << '\n';
807 if (mustProvide("lyxarrow"))
808 macros << lyxarrow_def << '\n';
810 if (mustProvide("textgreek"))
811 macros << textgreek_def << '\n';
813 if (mustProvide("textcyr"))
814 macros << textcyr_def << '\n';
816 if (mustProvide("lyxmathsym"))
817 macros << lyxmathsym_def << '\n';
819 if (mustProvide("cedilla"))
820 macros << cedilla_def << '\n';
822 if (mustProvide("subring"))
823 macros << subring_def << '\n';
825 if (mustProvide("subdot"))
826 macros << subdot_def << '\n';
828 if (mustProvide("subhat"))
829 macros << subhat_def << '\n';
831 if (mustProvide("subtilde"))
832 macros << subtilde_def << '\n';
834 if (mustProvide("dacute"))
835 macros << dacute_def << '\n';
837 if (mustProvide("tipasymb"))
838 macros << tipasymb_def << '\n';
840 if (mustProvide("dgrave"))
841 macros << dgrave_def << '\n';
843 if (mustProvide("rcap"))
844 macros << rcap_def << '\n';
846 if (mustProvide("ogonek"))
847 macros << ogonek_def << '\n';
850 if (mustProvide("quotesinglbase"))
851 macros << quotesinglbase_def << '\n';
852 if (mustProvide("quotedblbase"))
853 macros << quotedblbase_def << '\n';
854 if (mustProvide("guilsinglleft"))
855 macros << guilsinglleft_def << '\n';
856 if (mustProvide("guilsinglright"))
857 macros << guilsinglright_def << '\n';
858 if (mustProvide("guillemotleft"))
859 macros << guillemotleft_def << '\n';
860 if (mustProvide("guillemotright"))
861 macros << guillemotright_def << '\n';
864 if (mustProvide("binom") && !isRequired("amsmath"))
865 macros << binom_def << '\n';
866 if (mustProvide("mathcircumflex"))
867 macros << mathcircumflex_def << '\n';
870 if (mustProvide("ParagraphLeftIndent"))
871 macros << paragraphleftindent_def;
872 if (mustProvide("NeedLyXFootnoteCode"))
873 macros << floatingfootnote_def;
875 // some problems with tex->html converters
876 if (mustProvide("NeedTabularnewline"))
877 macros << tabularnewline_def;
879 // greyedout environment (note inset)
880 if (mustProvide("lyxgreyedout"))
881 macros << lyxgreyedout_def;
883 if (mustProvide("lyxdot"))
884 macros << lyxdot_def << '\n';
887 getFloatDefinitions(macros);
890 if (mustProvide("ct-dvipost"))
891 macros << changetracking_dvipost_def;
893 if (mustProvide("ct-xcolor-ulem")) {
894 int const prec = macros.precision(2);
896 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
897 macros << "\\providecolor{lyxadded}{rgb}{"
898 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
900 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
901 macros << "\\providecolor{lyxdeleted}{rgb}{"
902 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
904 macros.precision(prec);
906 if (isRequired("hyperref"))
907 macros << changetracking_xcolor_ulem_hyperref_def;
909 macros << changetracking_xcolor_ulem_def;
912 if (mustProvide("ct-none"))
913 macros << changetracking_none_def;
919 string const LaTeXFeatures::getBabelOptions() const
923 LanguageList::const_iterator it = UsedLanguages_.begin();
924 LanguageList::const_iterator end = UsedLanguages_.end();
925 for (; it != end; ++it)
926 if (!(*it)->latex_options().empty())
927 tmp << (*it)->latex_options() << '\n';
928 if (!params_.language->latex_options().empty())
929 tmp << params_.language->latex_options() << '\n';
935 docstring const LaTeXFeatures::getTClassPreamble() const
937 // the text class specific preamble
938 DocumentClass const & tclass = params_.documentClass();
939 odocstringstream tcpreamble;
941 tcpreamble << tclass.preamble();
943 list<docstring>::const_iterator cit = usedLayouts_.begin();
944 list<docstring>::const_iterator end = usedLayouts_.end();
945 for (; cit != end; ++cit)
946 tcpreamble << tclass[*cit].preamble();
948 cit = usedInsetLayouts_.begin();
949 end = usedInsetLayouts_.end();
950 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
951 for (; cit != end; ++cit) {
952 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
955 tcpreamble << it->second.preamble();
958 return tcpreamble.str();
962 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
964 DocumentClass const & tclass = params_.documentClass();
965 odocstringstream tcpreamble;
967 tcpreamble << tclass.htmlpreamble();
969 list<docstring>::const_iterator cit = usedLayouts_.begin();
970 list<docstring>::const_iterator end = usedLayouts_.end();
971 for (; cit != end; ++cit)
972 tcpreamble << tclass[*cit].htmlpreamble();
974 cit = usedInsetLayouts_.begin();
975 end = usedInsetLayouts_.end();
976 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
977 for (; cit != end; ++cit) {
978 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
981 tcpreamble << it->second.htmlpreamble();
984 return tcpreamble.str();
988 docstring const LaTeXFeatures::getTClassHTMLStyles() const {
989 DocumentClass const & tclass = params_.documentClass();
990 odocstringstream tcpreamble;
992 list<docstring>::const_iterator cit = usedLayouts_.begin();
993 list<docstring>::const_iterator end = usedLayouts_.end();
994 for (; cit != end; ++cit)
995 tcpreamble << tclass[*cit].htmlstyle();
997 cit = usedInsetLayouts_.begin();
998 end = usedInsetLayouts_.end();
999 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1000 for (; cit != end; ++cit) {
1001 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1002 if (it == ils.end())
1004 tcpreamble << it->second.htmlstyle();
1007 return tcpreamble.str();
1012 docstring const getFloatI18nPreamble(docstring const & type, docstring const & name, docstring const & lang)
1014 odocstringstream os;
1015 os << "\\addto\\captions" << lang
1016 << "{\\renewcommand{\\" << type << "name}{" << name << "}}\n";
1022 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
1024 DocumentClass const & tclass = params_.documentClass();
1025 // collect preamble snippets in a set to prevent multiple identical
1026 // commands (would happen if e.g. both theorem and theorem* are used)
1027 set<docstring> snippets;
1028 typedef LanguageList::const_iterator lang_it;
1029 lang_it const lbeg = UsedLanguages_.begin();
1030 lang_it const lend = UsedLanguages_.end();
1031 list<docstring>::const_iterator cit = usedLayouts_.begin();
1032 list<docstring>::const_iterator end = usedLayouts_.end();
1033 for (; cit != end; ++cit) {
1034 // language dependent commands (once per document)
1035 snippets.insert(tclass[*cit].langpreamble(buffer().language()));
1036 // commands for language changing (for multilanguage documents)
1037 if (use_babel && !UsedLanguages_.empty()) {
1038 snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
1039 for (lang_it lit = lbeg; lit != lend; ++lit)
1040 snippets.insert(tclass[*cit].babelpreamble(*lit));
1043 if (use_babel && !UsedLanguages_.empty()) {
1044 FloatList const & floats = params_.documentClass().floats();
1045 UsedFloats::const_iterator fit = usedFloats_.begin();
1046 UsedFloats::const_iterator fend = usedFloats_.end();
1047 for (; fit != fend; ++fit) {
1048 Floating const & fl = floats.getType(fit->first);
1049 docstring const type = from_ascii(fl.type());
1050 docstring const flname = from_utf8(fl.name());
1051 docstring name = translateIfPossible(flname,
1052 buffer().language()->code());
1053 snippets.insert(getFloatI18nPreamble(
1055 from_ascii(buffer().language()->babel())));
1056 for (lang_it lit = lbeg; lit != lend; ++lit) {
1057 name = translateIfPossible(flname,
1059 snippets.insert(getFloatI18nPreamble(
1061 from_ascii((*lit)->babel())));
1066 odocstringstream tcpreamble;
1067 set<docstring>::const_iterator const send = snippets.end();
1068 set<docstring>::const_iterator it = snippets.begin();
1069 for (; it != send; ++it)
1071 return tcpreamble.str();
1075 docstring const LaTeXFeatures::getLyXSGMLEntities() const
1077 // Definition of entities used in the document that are LyX related.
1078 odocstringstream entities;
1080 if (mustProvide("lyxarrow")) {
1081 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
1084 return entities.str();
1088 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1090 odocstringstream sgmlpreamble;
1092 docstring const basename(from_utf8(onlyPath(fname)));
1094 FileMap::const_iterator end = IncludedFiles_.end();
1095 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1098 sgmlpreamble << "\n<!ENTITY " << fi->first
1099 << (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"")
1100 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1102 return sgmlpreamble.str();
1106 void LaTeXFeatures::showStruct() const
1108 lyxerr << "LyX needs the following commands when LaTeXing:"
1109 << "\n***** Packages:" << getPackages()
1110 << "\n***** Macros:" << to_utf8(getMacros())
1111 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1112 << "\n***** done." << endl;
1116 Buffer const & LaTeXFeatures::buffer() const
1122 void LaTeXFeatures::setBuffer(Buffer const & buffer)
1128 BufferParams const & LaTeXFeatures::bufferParams() const
1134 void LaTeXFeatures::getFloatDefinitions(odocstream & os) const
1136 FloatList const & floats = params_.documentClass().floats();
1138 // Here we will output the code to create the needed float styles.
1139 // We will try to do this as minimal as possible.
1140 // \floatstyle{ruled}
1141 // \newfloat{algorithm}{htbp}{loa}
1142 // \providecommand{\algorithmname}{Algorithm}
1143 // \floatname{algorithm}{\protect\algorithmname}
1144 UsedFloats::const_iterator cit = usedFloats_.begin();
1145 UsedFloats::const_iterator end = usedFloats_.end();
1146 for (; cit != end; ++cit) {
1147 Floating const & fl = floats.getType(cit->first);
1149 // For builtin floats we do nothing.
1150 if (fl.builtin()) continue;
1152 // We have to special case "table" and "figure"
1153 if (fl.type() == "tabular" || fl.type() == "figure") {
1154 // Output code to modify "table" or "figure"
1155 // but only if builtin == false
1156 // and that have to be true at this point in the
1158 docstring const type = from_ascii(fl.type());
1159 docstring const placement = from_ascii(fl.placement());
1160 docstring const style = from_ascii(fl.style());
1161 if (!style.empty()) {
1162 os << "\\floatstyle{" << style << "}\n"
1163 << "\\restylefloat{" << type << "}\n";
1165 if (!placement.empty()) {
1166 os << "\\floatplacement{" << type << "}{"
1167 << placement << "}\n";
1170 // The other non builtin floats.
1172 docstring const type = from_ascii(fl.type());
1173 docstring const placement = from_ascii(fl.placement());
1174 docstring const ext = from_ascii(fl.ext());
1175 docstring const within = from_ascii(fl.within());
1176 docstring const style = from_ascii(fl.style());
1177 docstring const name = translateIfPossible(
1178 from_utf8(fl.name()),
1179 buffer().language()->code());
1180 os << "\\floatstyle{" << style << "}\n"
1181 << "\\newfloat{" << type << "}{" << placement
1182 << "}{" << ext << '}';
1183 if (!within.empty())
1184 os << '[' << within << ']';
1186 << "\\providecommand{\\" << type << "name}{"
1188 << "\\floatname{" << type << "}{\\protect\\"
1189 << type << "name}\n";
1191 // What missing here is to code to minimalize the code
1192 // output so that the same floatstyle will not be
1193 // used several times, when the same style is still in
1197 os << "\n\\newsubfloat{" << from_ascii(fl.type()) << "}\n";