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"
45 using namespace lyx::support;
50 /////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
56 //\NeedsTeXFormat{LaTeX2e}
57 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
58 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
60 static docstring const lyx_def = from_ascii(
61 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
63 static docstring const lyxline_def = from_ascii(
64 "\\newcommand{\\lyxline}[1][1pt]{%\n"
66 " \\rule[.5ex]{\\linewidth}{#1}\\par}");
68 static docstring const noun_def = from_ascii(
69 "\\newcommand{\\noun}[1]{\\textsc{#1}}");
71 static docstring const lyxarrow_def = from_ascii(
72 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
74 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
75 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
77 // for quotes without babel. This does not give perfect results, but
78 // anybody serious about non-english quotes should use babel (JMarc).
80 static docstring const quotedblbase_def = from_ascii(
81 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
82 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
83 " \\penalty10000\\hskip0em\\relax%\n"
86 static docstring const quotesinglbase_def = from_ascii(
87 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
88 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
89 " \\penalty10000\\hskip0em\\relax%\n"
92 static docstring const guillemotleft_def = from_ascii(
93 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
94 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
95 "\\penalty10000\\hskip0pt\\relax%\n"
98 static docstring const guillemotright_def = from_ascii(
99 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
100 " \\penalty10000\\hskip0pt%\n"
101 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
104 static docstring const guilsinglleft_def = from_ascii(
105 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
106 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
107 " \\penalty10000\\hskip0pt\\relax%\n"
110 static docstring const guilsinglright_def = from_ascii(
111 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
112 " \\penalty10000\\hskip0pt%\n"
113 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
116 static docstring const paragraphleftindent_def = from_ascii(
117 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
119 " \\begin{list}{}{%\n"
120 " \\setlength{\\topsep}{0pt}%\n"
121 " \\addtolength{\\leftmargin}{#1}\n"
122 // ho hum, yet more things commented out with no hint as to why they
123 // weren't just removed
124 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
125 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
126 // "%% \\setlength\\listparindent\\parindent%\n"
127 // "%% \\setlength\\itemindent\\parindent%\n"
128 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
134 static docstring const floatingfootnote_def = from_ascii(
135 "%% Special footnote code from the package 'stblftnt.sty'\n"
136 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
137 "\\let\\SF@@footnote\\footnote\n"
138 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
139 " \\expandafter\\SF@@footnote\n"
141 " \\expandafter\\SF@gobble@opt\n"
144 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
145 " \\SF@gobble@twobracket\n"
148 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
149 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
150 "\\def\\SF@gobble@twobracket[#1]#2{}\n");
152 static docstring const binom_def = from_ascii(
153 "%% Binom macro for standard LaTeX users\n"
154 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
156 static docstring const mathcircumflex_def = from_ascii(
157 "%% For printing a cirumflex inside a formula\n"
158 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
160 static docstring const tabularnewline_def = from_ascii(
161 "%% Because html converters don't know tabularnewline\n"
162 "\\providecommand{\\tabularnewline}{\\\\}\n");
164 static docstring const lyxgreyedout_def = from_ascii(
165 "%% The greyedout annotation environment\n"
166 "\\newenvironment{lyxgreyedout}{\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n");
168 // We want to omit the file extension for includegraphics, but this does not
169 // work when the filename contains other dots.
170 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
171 static docstring const lyxdot_def = from_ascii(
172 "%% A simple dot to overcome graphicx limitations\n"
173 "\\newcommand{\\lyxdot}{.}\n");
175 static docstring const changetracking_dvipost_def = from_ascii(
176 "%% Change tracking with dvipost\n"
178 "\\dvipost{osstart color push Red}\n"
179 "\\dvipost{osend color pop}\n"
180 "\\dvipost{cbstart color push Blue}\n"
181 "\\dvipost{cbend color pop}\n"
182 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
183 "\\newcommand{\\lyxdeleted}[3]{%\n"
184 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n");
186 static docstring const changetracking_xcolor_ulem_def = from_ascii(
187 "%% Change tracking with ulem\n"
188 "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}{}#3}}\n"
189 "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
191 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
192 "%% Change tracking with ulem\n"
193 "\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}{}}{}#3}}\n"
194 "\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
196 static docstring const changetracking_none_def = from_ascii(
197 "\\newcommand{\\lyxadded}[3]{#3}\n"
198 "\\newcommand{\\lyxdeleted}[3]{}\n");
200 static docstring const textgreek_def = from_ascii(
201 "\\DeclareRobustCommand{\\greektext}{%\n"
202 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
203 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
204 "\\DeclareFontEncoding{LGR}{}{}\n"
205 "\\DeclareTextSymbol{\\~}{LGR}{126}");
207 static docstring const textcyr_def = from_ascii(
208 "\\DeclareRobustCommand{\\cyrtext}{%\n"
209 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
210 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
211 "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n");
213 static docstring const lyxmathsym_def = from_ascii(
214 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
215 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
217 static docstring const papersizedvi_def = from_ascii(
218 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
220 static docstring const papersizepdf_def = from_ascii(
221 "\\pdfpageheight\\paperheight\n"
222 "\\pdfpagewidth\\paperwidth\n");
224 static docstring const cedilla_def = from_ascii(
225 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
226 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
228 static docstring const subring_def = from_ascii(
229 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
230 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
232 static docstring const subdot_def = from_ascii(
233 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
234 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
236 static docstring const subhat_def = from_ascii(
237 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
238 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
240 static docstring const subtilde_def = from_ascii(
241 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
242 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
244 static docstring const dacute_def = from_ascii(
245 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
247 static docstring const tipasymb_def = from_ascii(
248 "\\DeclareFontEncoding{T3}{}{}\n"
249 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
251 static docstring const dgrave_def = from_ascii(
252 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
254 static docstring const rcap_def = from_ascii(
255 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
257 static docstring const ogonek_def = from_ascii(
258 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
259 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
260 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
261 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
262 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
264 /////////////////////////////////////////////////////////////////////
268 /////////////////////////////////////////////////////////////////////
270 LaTeXFeatures::Packages LaTeXFeatures::packages_;
273 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
274 OutputParams const & r)
275 : buffer_(&b), params_(p), runparams_(r), in_float_(false)
279 bool LaTeXFeatures::useBabel() const
281 return lyxrc.language_use_babel ||
282 (bufferParams().language->lang() != lyxrc.default_language &&
283 !bufferParams().language->babel().empty()) ||
284 this->hasLanguages();
288 void LaTeXFeatures::require(string const & name)
290 features_.insert(name);
294 void LaTeXFeatures::require(set<string> const & names)
296 features_.insert(names.begin(), names.end());
300 void LaTeXFeatures::getAvailable()
303 support::FileName const real_file = libFileSearch("", "packages.lst");
305 if (real_file.empty())
308 lex.setFile(real_file);
313 // Make sure that we are clean
316 bool finished = false;
318 while (lex.isOK() && !finished) {
320 case Lexer::LEX_FEOF:
324 packages_.insert(lex.getString());
330 void LaTeXFeatures::useLayout(docstring const & layoutname)
332 // Some code to avoid loops in dependency definition
333 static int level = 0;
334 const int maxlevel = 30;
335 if (level > maxlevel) {
336 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
337 << "recursion attained by layout "
338 << to_utf8(layoutname) << endl;
342 DocumentClass const & tclass = params_.documentClass();
343 if (tclass.hasLayout(layoutname)) {
344 // Is this layout already in usedLayouts?
345 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
346 != usedLayouts_.end())
349 Layout const & layout = tclass[layoutname];
350 require(layout.requires());
352 if (!layout.depends_on().empty()) {
354 useLayout(layout.depends_on());
357 usedLayouts_.push_back(layoutname);
359 lyxerr << "LaTeXFeatures::useLayout: layout `"
360 << to_utf8(layoutname) << "' does not exist in this class"
368 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
370 docstring const & lname = lay.name();
371 DocumentClass const & tclass = params_.documentClass();
373 // this is a default inset layout, nothing useful here
374 if (!tclass.hasInsetLayout(lname))
376 // Is this layout already in usedInsetLayouts?
377 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
378 != usedInsetLayouts_.end())
381 require(lay.requires());
382 usedInsetLayouts_.push_back(lname);
386 bool LaTeXFeatures::isRequired(string const & name) const
388 return features_.find(name) != features_.end();
392 bool LaTeXFeatures::mustProvide(string const & name) const
394 return isRequired(name) && !params_.documentClass().provides(name);
398 bool LaTeXFeatures::isAvailable(string const & name)
400 string::size_type const i = name.find("->");
401 if (i != string::npos) {
402 string const from = name.substr(0,i);
403 string const to = name.substr(i+2);
404 //LYXERR0("from=[" << from << "] to=[" << to << "]");
405 return theConverters().isReachable(from, to);
408 if (packages_.empty())
411 if (suffixIs(n, ".sty"))
412 n.erase(name.length() - 4);
413 return packages_.find(n) != packages_.end();
417 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
419 SnippetList::const_iterator begin = preamble_snippets_.begin();
420 SnippetList::const_iterator end = preamble_snippets_.end();
421 if (find(begin, end, preamble) == end)
422 preamble_snippets_.push_back(preamble);
426 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
428 if (!usedFloats_[name])
429 usedFloats_[name] = subfloat;
432 // We only need float.sty if we use non builtin floats, or if we
433 // use the "H" modifier. This includes modified table and
434 // figure floats. (Lgb)
435 Floating const & fl = params_.documentClass().floats().getType(name);
436 if (!fl.floattype().empty() && fl.needsFloatPkg()) {
442 void LaTeXFeatures::useLanguage(Language const * lang)
444 if (!lang->babel().empty())
445 UsedLanguages_.insert(lang);
446 if (lang->lang() == "vietnamese")
447 require("vietnamese");
448 // CJK languages do not have a babel name.
449 // They use the CJK package
450 if (lang->encoding()->package() == Encoding::CJK)
452 // japanese package is special
453 if (lang->encoding()->package() == Encoding::japanese)
458 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
460 IncludedFiles_[key] = name;
464 bool LaTeXFeatures::hasLanguages() const
466 return !UsedLanguages_.empty();
470 string LaTeXFeatures::getLanguages() const
472 ostringstream languages;
474 LanguageList::const_iterator const begin = UsedLanguages_.begin();
475 for (LanguageList::const_iterator cit = begin;
476 cit != UsedLanguages_.end();
480 languages << (*cit)->babel();
482 return languages.str();
486 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
488 // This does only find encodings of languages supported by babel, but
489 // that does not matter since we don't have a language with an
490 // encoding supported by inputenc but without babel support.
491 set<string> encodings;
492 LanguageList::const_iterator it = UsedLanguages_.begin();
493 LanguageList::const_iterator end = UsedLanguages_.end();
494 for (; it != end; ++it)
495 if ((*it)->encoding()->latexName() != doc_encoding &&
496 ((*it)->encoding()->package() == Encoding::inputenc
497 || (*it)->encoding()->package() == Encoding::japanese))
498 encodings.insert((*it)->encoding()->latexName());
504 char const * simplefeatures[] = {
505 // note that the package order here will be the same in the LaTeX-output
512 // subfig is handled in BufferParams.cpp
515 /*For a successful cooperation of the `wrapfig' package with the
516 `float' package you should load the `wrapfig' package *after*
517 the `float' package. See the caption package documentation
546 // listings is handled in BufferParams.cpp
554 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
559 string const LaTeXFeatures::getColorOptions() const
561 ostringstream colors;
563 // Handling the color packages separately is needed to be able to load them
564 // before babel when hyperref is loaded with the colorlinks option
565 // for more info see Bufferparams.cpp
568 if (mustProvide("color") || mustProvide("xcolor")) {
569 string const package =
570 (mustProvide("xcolor") ? "xcolor" : "color");
571 if (params_.graphicsDriver == "default"
572 || params_.graphicsDriver == "none")
573 colors << "\\usepackage{" << package << "}\n";
575 colors << "\\usepackage["
576 << params_.graphicsDriver
577 << "]{" << package << "}\n";
580 // pdfcolmk must be loaded after color
581 if (mustProvide("pdfcolmk"))
582 colors << "\\usepackage{pdfcolmk}\n";
584 // the following 3 color commands must be set after color
585 // is loaded and before pdfpages, therefore add the command
586 // here define the set color
587 if (mustProvide("pagecolor")) {
588 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
589 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
590 // set the page color
591 colors << "\\pagecolor{page_backgroundcolor}\n";
594 if (mustProvide("fontcolor")) {
595 colors << "\\definecolor{document_fontcolor}{rgb}{";
596 colors << outputLaTeXColor(params_.fontcolor) << "}\n";
598 colors << "\\color{document_fontcolor}\n";
601 if (mustProvide("lyxgreyedout")) {
602 colors << "\\definecolor{note_fontcolor}{rgb}{";
603 colors << outputLaTeXColor(params_.notefontcolor) << "}\n";
604 // the color will be set together with the definition of
605 // the lyxgreyedout environment (see lyxgreyedout_def)
608 // color for shaded boxes
609 if (isRequired("framed") && mustProvide("color")) {
610 colors << "\\definecolor{shadecolor}{rgb}{";
611 colors << outputLaTeXColor(params_.boxbgcolor) << "}\n";
612 // this color is automatically used by the LaTeX-package "framed"
619 string const LaTeXFeatures::getPackages() const
621 ostringstream packages;
622 DocumentClass const & tclass = params_.documentClass();
624 // FIXME: currently, we can only load packages and macros known
626 // However, with the Require tag of layouts/custom insets,
627 // also inknown packages can be requested. They are silently
628 // swallowed now. We should change this eventually.
631 // These are all the 'simple' includes. i.e
632 // packages which we just \usepackage{package}
634 for (int i = 0; i < nb_simplefeatures; ++i) {
635 if (mustProvide(simplefeatures[i]))
636 packages << "\\usepackage{"
637 << simplefeatures[i] << "}\n";
641 // The rest of these packages are somewhat more complicated
645 // esint is preferred for esintoramsmath
646 if ((mustProvide("amsmath")
647 && params_.use_amsmath != BufferParams::package_off)
648 || (mustProvide("esintoramsmath")
649 && params_.use_esint == BufferParams::package_off
650 && params_.use_amsmath != BufferParams::package_off)) {
651 packages << "\\usepackage{amsmath}\n";
653 // amsbsy and amstext are already provided by amsmath
654 if (mustProvide("amsbsy"))
655 packages << "\\usepackage{amsbsy}\n";
656 if (mustProvide("amstext"))
657 packages << "\\usepackage{amstext}\n";
660 // wasysym is a simple feature, but it must be after amsmath if both
662 // wasysym redefines some integrals (e.g. iint) from amsmath. That
663 // leads to inconsistent integrals. We only load this package if
664 // the document does not contain integrals (then isRequired("esint")
665 // is false) or if esint is used, since esint redefines all relevant
666 // integral symbols from wasysym and amsmath.
667 // See http://www.lyx.org/trac/ticket/1942
668 if (mustProvide("wasysym") &&
669 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
670 packages << "\\usepackage{wasysym}\n";
672 // accents must be loaded after amsmath
673 if (mustProvide("accents"))
674 packages << "\\usepackage{accents}\n";
676 // mathdots must be loaded after amsmath
677 if (mustProvide("mathdots") &&
678 params_.use_mathdots != BufferParams::package_off)
679 packages << "\\usepackage{mathdots}\n";
681 // yhmath must be loaded after amsmath
682 if (mustProvide("yhmath"))
683 packages << "\\usepackage{yhmath}\n";
685 // [x]color and pdfcolmk are handled in getColorOptions() above
688 if (isRequired("makeidx") || isRequired("splitidx")) {
689 if (!tclass.provides("makeidx") && !isRequired("splitidx"))
690 packages << "\\usepackage{makeidx}\n";
691 if (!tclass.provides("splitidx") && isRequired("splitidx"))
692 packages << "\\usepackage{splitidx}\n";
693 packages << "\\makeindex\n";
697 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
698 if (params_.graphicsDriver == "default")
699 packages << "\\usepackage{graphicx}\n";
701 packages << "\\usepackage["
702 << params_.graphicsDriver
706 // lyxskak.sty --- newer chess support based on skak.sty
707 if (mustProvide("chess"))
708 packages << "\\usepackage[ps,mover]{lyxskak}\n";
711 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
712 packages << "\\usepackage{setspace}\n";
715 if (mustProvide("amssymb")
716 || params_.use_amsmath == BufferParams::package_on)
717 packages << "\\usepackage{amssymb}\n";
719 // esint must be after amsmath and wasysym, since it will redeclare
720 // inconsistent integral symbols
721 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
722 params_.use_esint != BufferParams::package_off)
723 packages << "\\usepackage{esint}\n";
726 // Some classes load natbib themselves, but still allow (or even require)
727 // plain numeric citations (ReVTeX is such a case, see bug 5182).
728 // This special case is indicated by the "natbib-internal" key.
729 if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
730 packages << "\\usepackage[";
731 if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
732 packages << "numbers";
734 packages << "authoryear";
735 packages << "]{natbib}\n";
738 // jurabib -- we need version 0.6 at least.
739 if (mustProvide("jurabib"))
740 packages << "\\usepackage{jurabib}[2004/01/25]\n";
742 // xargs -- we need version 1.09 at least
743 if (mustProvide("xargs"))
744 packages << "\\usepackage{xargs}[2008/03/08]\n";
746 // bibtopic -- the dot provides the aux file naming which
748 if (mustProvide("bibtopic"))
749 packages << "\\usepackage[dot]{bibtopic}\n";
751 if (mustProvide("xy"))
752 packages << "\\usepackage[all]{xy}\n";
754 if (mustProvide("ulem"))
755 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
756 "\\usepackage{ulem}\n";
758 if (mustProvide("mhchem") &&
759 params_.use_mhchem != BufferParams::package_off)
760 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
761 "\\usepackage{mhchem}\n";
763 if (mustProvide("nomencl")) {
764 // Make it work with the new and old version of the package,
765 // but don't use the compatibility option since it is
766 // incompatible to other packages.
767 packages << "\\usepackage{nomencl}\n"
768 "% the following is useful when we have the old nomencl.sty package\n"
769 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
770 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
771 "\\makenomenclature\n";
774 return packages.str();
778 string LaTeXFeatures::getPreambleSnippets() const
781 SnippetList::const_iterator pit = preamble_snippets_.begin();
782 SnippetList::const_iterator pend = preamble_snippets_.end();
783 for (; pit != pend; ++pit)
784 snip << *pit << '\n';
789 docstring const LaTeXFeatures::getMacros() const
791 odocstringstream macros;
793 if (!preamble_snippets_.empty()) {
795 macros << from_utf8(getPreambleSnippets());
798 if (mustProvide("papersize")) {
799 if (runparams_.flavor == OutputParams::LATEX)
800 macros << papersizedvi_def << '\n';
802 macros << papersizepdf_def << '\n';
805 if (mustProvide("LyX"))
806 macros << lyx_def << '\n';
808 if (mustProvide("lyxline"))
809 macros << lyxline_def << '\n';
811 if (mustProvide("noun"))
812 macros << noun_def << '\n';
814 if (mustProvide("lyxarrow"))
815 macros << lyxarrow_def << '\n';
817 if (mustProvide("textgreek")) {
818 // Avoid a LaTeX error if times fonts are used and the grtimes
819 // package is installed but actual fonts are not (bug 6469).
820 if (params_.fontsRoman == "times")
821 macros << subst(textgreek_def,
822 from_ascii("\\greektext #1"),
823 from_ascii("%\n \\IfFileExists"
824 "{grtm10.tfm}{}{\\fontfamily"
825 "{cmr}}\\greektext #1"))
828 macros << textgreek_def << '\n';
831 if (mustProvide("textcyr"))
832 macros << textcyr_def << '\n';
834 if (mustProvide("lyxmathsym"))
835 macros << lyxmathsym_def << '\n';
837 if (mustProvide("cedilla"))
838 macros << cedilla_def << '\n';
840 if (mustProvide("subring"))
841 macros << subring_def << '\n';
843 if (mustProvide("subdot"))
844 macros << subdot_def << '\n';
846 if (mustProvide("subhat"))
847 macros << subhat_def << '\n';
849 if (mustProvide("subtilde"))
850 macros << subtilde_def << '\n';
852 if (mustProvide("dacute"))
853 macros << dacute_def << '\n';
855 if (mustProvide("tipasymb"))
856 macros << tipasymb_def << '\n';
858 if (mustProvide("dgrave"))
859 macros << dgrave_def << '\n';
861 if (mustProvide("rcap"))
862 macros << rcap_def << '\n';
864 if (mustProvide("ogonek"))
865 macros << ogonek_def << '\n';
868 if (mustProvide("quotesinglbase"))
869 macros << quotesinglbase_def << '\n';
870 if (mustProvide("quotedblbase"))
871 macros << quotedblbase_def << '\n';
872 if (mustProvide("guilsinglleft"))
873 macros << guilsinglleft_def << '\n';
874 if (mustProvide("guilsinglright"))
875 macros << guilsinglright_def << '\n';
876 if (mustProvide("guillemotleft"))
877 macros << guillemotleft_def << '\n';
878 if (mustProvide("guillemotright"))
879 macros << guillemotright_def << '\n';
882 if (mustProvide("binom") && !isRequired("amsmath"))
883 macros << binom_def << '\n';
884 if (mustProvide("mathcircumflex"))
885 macros << mathcircumflex_def << '\n';
888 if (mustProvide("ParagraphLeftIndent"))
889 macros << paragraphleftindent_def;
890 if (mustProvide("NeedLyXFootnoteCode"))
891 macros << floatingfootnote_def;
893 // some problems with tex->html converters
894 if (mustProvide("NeedTabularnewline"))
895 macros << tabularnewline_def;
897 // greyed-out environment (note inset)
898 // the color is specified in the routine
899 // getColorOptions() to avoid LaTeX-package clashes
900 if (mustProvide("lyxgreyedout"))
901 macros << lyxgreyedout_def;
903 if (mustProvide("lyxdot"))
904 macros << lyxdot_def << '\n';
907 getFloatDefinitions(macros);
910 if (mustProvide("ct-dvipost"))
911 macros << changetracking_dvipost_def;
913 if (mustProvide("ct-xcolor-ulem")) {
914 int const prec = macros.precision(2);
916 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
917 macros << "\\providecolor{lyxadded}{rgb}{"
918 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
920 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
921 macros << "\\providecolor{lyxdeleted}{rgb}{"
922 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
924 macros.precision(prec);
926 if (isRequired("hyperref"))
927 macros << changetracking_xcolor_ulem_hyperref_def;
929 macros << changetracking_xcolor_ulem_def;
932 if (mustProvide("ct-none"))
933 macros << changetracking_none_def;
939 string const LaTeXFeatures::getBabelOptions() const
943 LanguageList::const_iterator it = UsedLanguages_.begin();
944 LanguageList::const_iterator end = UsedLanguages_.end();
945 for (; it != end; ++it)
946 if (!(*it)->latex_options().empty())
947 tmp << (*it)->latex_options() << '\n';
948 if (!params_.language->latex_options().empty())
949 tmp << params_.language->latex_options() << '\n';
955 docstring const LaTeXFeatures::getTClassPreamble() const
957 // the text class specific preamble
958 DocumentClass const & tclass = params_.documentClass();
959 odocstringstream tcpreamble;
961 tcpreamble << tclass.preamble();
963 list<docstring>::const_iterator cit = usedLayouts_.begin();
964 list<docstring>::const_iterator end = usedLayouts_.end();
965 for (; cit != end; ++cit)
966 tcpreamble << tclass[*cit].preamble();
968 cit = usedInsetLayouts_.begin();
969 end = usedInsetLayouts_.end();
970 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
971 for (; cit != end; ++cit) {
972 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
975 tcpreamble << it->second.preamble();
978 return tcpreamble.str();
982 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
984 DocumentClass const & tclass = params_.documentClass();
985 odocstringstream tcpreamble;
987 tcpreamble << tclass.htmlpreamble();
989 list<docstring>::const_iterator cit = usedLayouts_.begin();
990 list<docstring>::const_iterator end = usedLayouts_.end();
991 for (; cit != end; ++cit)
992 tcpreamble << tclass[*cit].htmlpreamble();
994 cit = usedInsetLayouts_.begin();
995 end = usedInsetLayouts_.end();
996 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
997 for (; cit != end; ++cit) {
998 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1001 tcpreamble << it->second.htmlpreamble();
1004 return tcpreamble.str();
1008 docstring const LaTeXFeatures::getTClassHTMLStyles() const {
1009 DocumentClass const & tclass = params_.documentClass();
1010 odocstringstream tcpreamble;
1012 list<docstring>::const_iterator cit = usedLayouts_.begin();
1013 list<docstring>::const_iterator end = usedLayouts_.end();
1014 for (; cit != end; ++cit)
1015 tcpreamble << tclass[*cit].htmlstyle();
1017 cit = usedInsetLayouts_.begin();
1018 end = usedInsetLayouts_.end();
1019 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1020 for (; cit != end; ++cit) {
1021 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1022 if (it == ils.end())
1024 tcpreamble << it->second.htmlstyle();
1027 return tcpreamble.str();
1032 docstring const getFloatI18nPreamble(docstring const & type, docstring const & name, docstring const & lang)
1034 odocstringstream os;
1035 os << "\\addto\\captions" << lang
1036 << "{\\renewcommand{\\" << type << "name}{" << name << "}}\n";
1042 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
1044 DocumentClass const & tclass = params_.documentClass();
1045 // collect preamble snippets in a set to prevent multiple identical
1046 // commands (would happen if e.g. both theorem and theorem* are used)
1047 set<docstring> snippets;
1048 typedef LanguageList::const_iterator lang_it;
1049 lang_it const lbeg = UsedLanguages_.begin();
1050 lang_it const lend = UsedLanguages_.end();
1051 list<docstring>::const_iterator cit = usedLayouts_.begin();
1052 list<docstring>::const_iterator end = usedLayouts_.end();
1053 for (; cit != end; ++cit) {
1054 // language dependent commands (once per document)
1055 snippets.insert(tclass[*cit].langpreamble(buffer().language()));
1056 // commands for language changing (for multilanguage documents)
1057 if (use_babel && !UsedLanguages_.empty()) {
1058 snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
1059 for (lang_it lit = lbeg; lit != lend; ++lit)
1060 snippets.insert(tclass[*cit].babelpreamble(*lit));
1063 if (use_babel && !UsedLanguages_.empty()) {
1064 FloatList const & floats = params_.documentClass().floats();
1065 UsedFloats::const_iterator fit = usedFloats_.begin();
1066 UsedFloats::const_iterator fend = usedFloats_.end();
1067 for (; fit != fend; ++fit) {
1068 Floating const & fl = floats.getType(fit->first);
1069 docstring const type = from_ascii(fl.floattype());
1070 docstring const flname = from_utf8(fl.name());
1071 docstring name = translateIfPossible(flname,
1072 buffer().language()->code());
1073 snippets.insert(getFloatI18nPreamble(
1075 from_ascii(buffer().language()->babel())));
1076 for (lang_it lit = lbeg; lit != lend; ++lit) {
1077 name = translateIfPossible(flname,
1079 snippets.insert(getFloatI18nPreamble(
1081 from_ascii((*lit)->babel())));
1086 odocstringstream tcpreamble;
1087 set<docstring>::const_iterator const send = snippets.end();
1088 set<docstring>::const_iterator it = snippets.begin();
1089 for (; it != send; ++it)
1091 return tcpreamble.str();
1095 docstring const LaTeXFeatures::getLyXSGMLEntities() const
1097 // Definition of entities used in the document that are LyX related.
1098 odocstringstream entities;
1100 if (mustProvide("lyxarrow")) {
1101 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
1104 return entities.str();
1108 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1110 odocstringstream sgmlpreamble;
1112 docstring const basename(from_utf8(onlyPath(fname)));
1114 FileMap::const_iterator end = IncludedFiles_.end();
1115 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1118 sgmlpreamble << "\n<!ENTITY " << fi->first
1119 << (isSGMLFileName(fi->second) ? " SYSTEM \"" : " \"")
1120 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1122 return sgmlpreamble.str();
1126 void LaTeXFeatures::showStruct() const
1128 lyxerr << "LyX needs the following commands when LaTeXing:"
1129 << "\n***** Packages:" << getPackages()
1130 << "\n***** Macros:" << to_utf8(getMacros())
1131 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1132 << "\n***** done." << endl;
1136 Buffer const & LaTeXFeatures::buffer() const
1142 void LaTeXFeatures::setBuffer(Buffer const & buffer)
1148 BufferParams const & LaTeXFeatures::bufferParams() const
1154 void LaTeXFeatures::getFloatDefinitions(odocstream & os) const
1156 FloatList const & floats = params_.documentClass().floats();
1158 // Here we will output the code to create the needed float styles.
1159 // We will try to do this as minimal as possible.
1160 // \floatstyle{ruled}
1161 // \newfloat{algorithm}{htbp}{loa}
1162 // \providecommand{\algorithmname}{Algorithm}
1163 // \floatname{algorithm}{\protect\algorithmname}
1164 UsedFloats::const_iterator cit = usedFloats_.begin();
1165 UsedFloats::const_iterator end = usedFloats_.end();
1166 for (; cit != end; ++cit) {
1167 Floating const & fl = floats.getType(cit->first);
1169 // For builtin floats we do nothing.
1170 if (!fl.needsFloatPkg())
1173 // We have to special case "table" and "figure"
1174 if (fl.floattype() == "tabular" || fl.floattype() == "figure") {
1175 // Output code to modify "table" or "figure"
1176 // but only if builtin == false
1177 // and that have to be true at this point in the
1179 docstring const type = from_ascii(fl.floattype());
1180 docstring const placement = from_ascii(fl.placement());
1181 docstring const style = from_ascii(fl.style());
1182 if (!style.empty()) {
1183 os << "\\floatstyle{" << style << "}\n"
1184 << "\\restylefloat{" << type << "}\n";
1186 if (!placement.empty()) {
1187 os << "\\floatplacement{" << type << "}{"
1188 << placement << "}\n";
1191 // The other non builtin floats.
1193 docstring const type = from_ascii(fl.floattype());
1194 docstring const placement = from_ascii(fl.placement());
1195 docstring const ext = from_ascii(fl.ext());
1196 docstring const within = from_ascii(fl.within());
1197 docstring const style = from_ascii(fl.style());
1198 docstring const name = translateIfPossible(
1199 from_utf8(fl.name()),
1200 buffer().language()->code());
1201 os << "\\floatstyle{" << style << "}\n"
1202 << "\\newfloat{" << type << "}{" << placement
1203 << "}{" << ext << '}';
1204 if (!within.empty())
1205 os << '[' << within << ']';
1207 << "\\providecommand{\\" << type << "name}{"
1209 << "\\floatname{" << type << "}{\\protect\\"
1210 << type << "name}\n";
1212 // What missing here is to code to minimalize the code
1213 // output so that the same floatstyle will not be
1214 // used several times, when the same style is still in
1218 os << "\n\\newsubfloat{" << from_ascii(fl.floattype()) << "}\n";