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 "\\DeclareRobustCommand{\\greektext}{%\n"
199 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
200 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
201 "\\DeclareFontEncoding{LGR}{}{}\n");
203 static docstring const textcyr_def = from_ascii(
204 "\\DeclareRobustCommand{\\cyrtext}{%\n"
205 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
206 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
207 "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n");
209 static docstring const lyxmathsym_def = from_ascii(
210 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
211 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
213 static docstring const papersizedvi_def = from_ascii(
214 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
216 static docstring const papersizepdf_def = from_ascii(
217 "\\pdfpageheight\\paperheight\n"
218 "\\pdfpagewidth\\paperwidth\n");
220 static docstring const cedilla_def = from_ascii(
221 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
222 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
224 static docstring const subring_def = from_ascii(
225 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
226 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
228 static docstring const subdot_def = from_ascii(
229 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
230 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
232 static docstring const subhat_def = from_ascii(
233 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
234 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
236 static docstring const subtilde_def = from_ascii(
237 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
238 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
240 static docstring const dacute_def = from_ascii(
241 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
243 static docstring const tipasymb_def = from_ascii(
244 "\\DeclareFontEncoding{T3}{}{}\n"
245 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
247 static docstring const dgrave_def = from_ascii(
248 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
250 static docstring const rcap_def = from_ascii(
251 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
253 static docstring const ogonek_def = from_ascii(
254 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
255 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
256 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
257 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
258 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
260 /////////////////////////////////////////////////////////////////////
264 /////////////////////////////////////////////////////////////////////
266 LaTeXFeatures::Packages LaTeXFeatures::packages_;
269 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
270 OutputParams const & r)
271 : buffer_(&b), params_(p), runparams_(r), in_float_(false)
275 bool LaTeXFeatures::useBabel() const
277 return lyxrc.language_use_babel ||
278 (bufferParams().language->lang() != lyxrc.default_language &&
279 !bufferParams().language->babel().empty()) ||
280 this->hasLanguages();
284 void LaTeXFeatures::require(string const & name)
286 features_.insert(name);
290 void LaTeXFeatures::require(set<string> const & names)
292 features_.insert(names.begin(), names.end());
296 void LaTeXFeatures::getAvailable()
299 support::FileName const real_file = libFileSearch("", "packages.lst");
301 if (real_file.empty())
304 lex.setFile(real_file);
309 // Make sure that we are clean
312 bool finished = false;
314 while (lex.isOK() && !finished) {
316 case Lexer::LEX_FEOF:
320 packages_.insert(lex.getString());
326 void LaTeXFeatures::useLayout(docstring const & layoutname)
328 // Some code to avoid loops in dependency definition
329 static int level = 0;
330 const int maxlevel = 30;
331 if (level > maxlevel) {
332 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
333 << "recursion attained by layout "
334 << to_utf8(layoutname) << endl;
338 DocumentClass const & tclass = params_.documentClass();
339 if (tclass.hasLayout(layoutname)) {
340 // Is this layout already in usedLayouts?
341 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
342 != usedLayouts_.end())
345 Layout const & layout = tclass[layoutname];
346 require(layout.requires());
348 if (!layout.depends_on().empty()) {
350 useLayout(layout.depends_on());
353 usedLayouts_.push_back(layoutname);
355 lyxerr << "LaTeXFeatures::useLayout: layout `"
356 << to_utf8(layoutname) << "' does not exist in this class"
364 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
366 docstring const & lname = lay.name();
367 DocumentClass const & tclass = params_.documentClass();
369 // this is a default inset layout, nothing useful here
370 if (!tclass.hasInsetLayout(lname))
372 // Is this layout already in usedInsetLayouts?
373 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
374 != usedInsetLayouts_.end())
377 require(lay.requires());
378 usedInsetLayouts_.push_back(lname);
382 bool LaTeXFeatures::isRequired(string const & name) const
384 return features_.find(name) != features_.end();
388 bool LaTeXFeatures::mustProvide(string const & name) const
390 return isRequired(name) && !params_.documentClass().provides(name);
394 bool LaTeXFeatures::isAvailable(string const & name)
396 string::size_type const i = name.find("->");
397 if (i != string::npos) {
398 string const from = name.substr(0,i);
399 string const to = name.substr(i+2);
400 //LYXERR0("from=[" << from << "] to=[" << to << "]");
401 return theConverters().isReachable(from, to);
404 if (packages_.empty())
407 if (suffixIs(n, ".sty"))
408 n.erase(name.length() - 4);
409 return packages_.find(n) != packages_.end();
413 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
415 SnippetList::const_iterator begin = preamble_snippets_.begin();
416 SnippetList::const_iterator end = preamble_snippets_.end();
417 if (find(begin, end, preamble) == end)
418 preamble_snippets_.push_back(preamble);
422 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
424 if (!usedFloats_[name])
425 usedFloats_[name] = subfloat;
428 // We only need float.sty if we use non builtin floats, or if we
429 // use the "H" modifier. This includes modified table and
430 // figure floats. (Lgb)
431 Floating const & fl = params_.documentClass().floats().getType(name);
432 if (!fl.type().empty() && !fl.builtin()) {
438 void LaTeXFeatures::useLanguage(Language const * lang)
440 if (!lang->babel().empty())
441 UsedLanguages_.insert(lang);
442 if (lang->lang() == "vietnamese")
443 require("vietnamese");
444 // CJK languages do not have a babel name.
445 // They use the CJK package
446 if (lang->encoding()->package() == Encoding::CJK)
448 // japanese package is special
449 if (lang->encoding()->package() == Encoding::japanese)
454 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
456 IncludedFiles_[key] = name;
460 bool LaTeXFeatures::hasLanguages() const
462 return !UsedLanguages_.empty();
466 string LaTeXFeatures::getLanguages() const
468 ostringstream languages;
470 LanguageList::const_iterator const begin = UsedLanguages_.begin();
471 for (LanguageList::const_iterator cit = begin;
472 cit != UsedLanguages_.end();
476 languages << (*cit)->babel();
478 return languages.str();
482 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
484 // This does only find encodings of languages supported by babel, but
485 // that does not matter since we don't have a language with an
486 // encoding supported by inputenc but without babel support.
487 set<string> encodings;
488 LanguageList::const_iterator it = UsedLanguages_.begin();
489 LanguageList::const_iterator end = UsedLanguages_.end();
490 for (; it != end; ++it)
491 if ((*it)->encoding()->latexName() != doc_encoding &&
492 ((*it)->encoding()->package() == Encoding::inputenc
493 || (*it)->encoding()->package() == Encoding::japanese))
494 encodings.insert((*it)->encoding()->latexName());
500 char const * simplefeatures[] = {
501 // note that the package order here will be the same in the LaTeX-output
508 // subfig is handled in BufferParams.cpp
511 /*For a successful cooperation of the `wrapfig' package with the
512 `float' package you should load the `wrapfig' package *after*
513 the `float' package. See the caption package documentation
542 // listings is handled in BufferParams.cpp
549 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
554 string const LaTeXFeatures::getColorOptions() const
556 ostringstream colors;
558 // Handling the color packages separately is needed to be able to load them
559 // before babel when hyperref is loaded with the colorlinks option
560 // for more info see Bufferparams.cpp
563 if (mustProvide("color") || mustProvide("xcolor")) {
564 string const package =
565 (mustProvide("xcolor") ? "xcolor" : "color");
566 if (params_.graphicsDriver == "default"
567 || params_.graphicsDriver == "none")
568 colors << "\\usepackage{" << package << "}\n";
570 colors << "\\usepackage["
571 << params_.graphicsDriver
572 << "]{" << package << "}\n";
575 // pdfcolmk must be loaded after color
576 if (mustProvide("pdfcolmk"))
577 colors << "\\usepackage{pdfcolmk}\n";
579 if (mustProvide("pagecolor")) {
580 // the \pagecolor command must be set after color is loaded and
581 // before pdfpages, therefore add the command here
582 // define the set color
583 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
584 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
585 // set the page color
586 colors << "\\pagecolor{page_backgroundcolor}\n";
593 string const LaTeXFeatures::getPackages() const
595 ostringstream packages;
596 DocumentClass const & tclass = params_.documentClass();
598 // FIXME: currently, we can only load packages and macros known
600 // However, with the Require tag of layouts/custom insets,
601 // also inknown packages can be requested. They are silently
602 // swallowed now. We should change this eventually.
605 // These are all the 'simple' includes. i.e
606 // packages which we just \usepackage{package}
608 for (int i = 0; i < nb_simplefeatures; ++i) {
609 if (mustProvide(simplefeatures[i]))
610 packages << "\\usepackage{"
611 << simplefeatures[i] << "}\n";
615 // The rest of these packages are somewhat more complicated
619 // esint is preferred for esintoramsmath
620 if ((mustProvide("amsmath")
621 && params_.use_amsmath != BufferParams::package_off)
622 || (mustProvide("esintoramsmath")
623 && params_.use_esint == BufferParams::package_off
624 && params_.use_amsmath != BufferParams::package_off)) {
625 packages << "\\usepackage{amsmath}\n";
627 // amsbsy and amstext are already provided by amsmath
628 if (mustProvide("amsbsy"))
629 packages << "\\usepackage{amsbsy}\n";
630 if (mustProvide("amstext"))
631 packages << "\\usepackage{amstext}\n";
634 // wasysym is a simple feature, but it must be after amsmath if both
636 // wasysym redefines some integrals (e.g. iint) from amsmath. That
637 // leads to inconsistent integrals. We only load this package if
638 // the document does not contain integrals (then isRequired("esint")
639 // is false) or if esint is used, since esint redefines all relevant
640 // integral symbols from wasysym and amsmath.
641 // See http://bugzilla.lyx.org/show_bug.cgi?id=1942
642 if (mustProvide("wasysym") &&
643 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
644 packages << "\\usepackage{wasysym}\n";
646 // accents must be loaded after amsmath
647 if (mustProvide("accents"))
648 packages << "\\usepackage{accents}\n";
650 // mathdots must be loaded after amsmath
651 if (mustProvide("mathdots"))
652 packages << "\\usepackage{mathdots}\n";
654 // yhmath must be loaded after amsmath
655 if (mustProvide("yhmath"))
656 packages << "\\usepackage{yhmath}\n";
658 // [x]color and pdfcolmk are handled in getColorOptions() above
661 if (isRequired("makeidx") || isRequired("splitidx")) {
662 if (!tclass.provides("makeidx") && !isRequired("splitidx"))
663 packages << "\\usepackage{makeidx}\n";
664 if (!tclass.provides("splitidx") && isRequired("splitidx"))
665 packages << "\\usepackage{splitidx}\n";
666 packages << "\\makeindex\n";
670 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
671 if (params_.graphicsDriver == "default")
672 packages << "\\usepackage{graphicx}\n";
674 packages << "\\usepackage["
675 << params_.graphicsDriver
678 // shadecolor for shaded
679 if (isRequired("framed") && mustProvide("color")) {
680 RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
681 //255.0 to force conversion to double
682 //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
683 //to use the xcolor package instead, and then we can do
684 // \define{shadcolor}{RGB}...
685 //and not do any conversion. We'd then need to require xcolor
686 //in InsetNote::validate().
687 int const stmSize = packages.precision(2);
688 packages << "\\definecolor{shadecolor}{rgb}{"
689 << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
690 packages.precision(stmSize);
693 // lyxskak.sty --- newer chess support based on skak.sty
694 if (mustProvide("chess"))
695 packages << "\\usepackage[ps,mover]{lyxskak}\n";
698 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
699 packages << "\\usepackage{setspace}\n";
702 if (mustProvide("amssymb")
703 || params_.use_amsmath == BufferParams::package_on)
704 packages << "\\usepackage{amssymb}\n";
706 // esint must be after amsmath and wasysym, since it will redeclare
707 // inconsistent integral symbols
708 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
709 params_.use_esint != BufferParams::package_off)
710 packages << "\\usepackage{esint}\n";
713 // Some classes load natbib themselves, but still allow (or even require)
714 // plain numeric citations (ReVTeX is such a case, see bug 5182).
715 // This special case is indicated by the "natbib-internal" key.
716 if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
717 packages << "\\usepackage[";
718 if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
719 packages << "numbers";
721 packages << "authoryear";
722 packages << "]{natbib}\n";
725 // jurabib -- we need version 0.6 at least.
726 if (mustProvide("jurabib"))
727 packages << "\\usepackage{jurabib}[2004/01/25]\n";
729 // xargs -- we need version 1.09 at least
730 if (mustProvide("xargs"))
731 packages << "\\usepackage{xargs}[2008/03/08]\n";
733 // bibtopic -- the dot provides the aux file naming which
735 if (mustProvide("bibtopic"))
736 packages << "\\usepackage[dot]{bibtopic}\n";
738 if (mustProvide("xy"))
739 packages << "\\usepackage[all]{xy}\n";
741 if (mustProvide("ulem"))
742 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
743 "\\usepackage{ulem}\n";
745 if (mustProvide("mhchem"))
746 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
747 "\\usepackage{mhchem}\n";
749 if (mustProvide("nomencl")) {
750 // Make it work with the new and old version of the package,
751 // but don't use the compatibility option since it is
752 // incompatible to other packages.
753 packages << "\\usepackage{nomencl}\n"
754 "% the following is useful when we have the old nomencl.sty package\n"
755 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
756 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
757 "\\makenomenclature\n";
760 return packages.str();
764 docstring const LaTeXFeatures::getMacros() const
766 odocstringstream macros;
768 if (!preamble_snippets_.empty())
770 SnippetList::const_iterator pit = preamble_snippets_.begin();
771 SnippetList::const_iterator pend = preamble_snippets_.end();
772 for (; pit != pend; ++pit)
773 macros << *pit << '\n';
775 if (mustProvide("papersize")) {
776 if (runparams_.flavor == OutputParams::LATEX)
777 macros << papersizedvi_def << '\n';
779 macros << papersizepdf_def << '\n';
782 if (mustProvide("LyX"))
783 macros << lyx_def << '\n';
785 if (mustProvide("lyxline"))
786 macros << lyxline_def << '\n';
788 if (mustProvide("noun"))
789 macros << noun_def << '\n';
791 if (mustProvide("lyxarrow"))
792 macros << lyxarrow_def << '\n';
794 if (mustProvide("textgreek"))
795 macros << textgreek_def << '\n';
797 if (mustProvide("textcyr"))
798 macros << textcyr_def << '\n';
800 if (mustProvide("lyxmathsym"))
801 macros << lyxmathsym_def << '\n';
803 if (mustProvide("cedilla"))
804 macros << cedilla_def << '\n';
806 if (mustProvide("subring"))
807 macros << subring_def << '\n';
809 if (mustProvide("subdot"))
810 macros << subdot_def << '\n';
812 if (mustProvide("subhat"))
813 macros << subhat_def << '\n';
815 if (mustProvide("subtilde"))
816 macros << subtilde_def << '\n';
818 if (mustProvide("dacute"))
819 macros << dacute_def << '\n';
821 if (mustProvide("tipasymb"))
822 macros << tipasymb_def << '\n';
824 if (mustProvide("dgrave"))
825 macros << dgrave_def << '\n';
827 if (mustProvide("rcap"))
828 macros << rcap_def << '\n';
830 if (mustProvide("ogonek"))
831 macros << ogonek_def << '\n';
834 if (mustProvide("quotesinglbase"))
835 macros << quotesinglbase_def << '\n';
836 if (mustProvide("quotedblbase"))
837 macros << quotedblbase_def << '\n';
838 if (mustProvide("guilsinglleft"))
839 macros << guilsinglleft_def << '\n';
840 if (mustProvide("guilsinglright"))
841 macros << guilsinglright_def << '\n';
842 if (mustProvide("guillemotleft"))
843 macros << guillemotleft_def << '\n';
844 if (mustProvide("guillemotright"))
845 macros << guillemotright_def << '\n';
848 if (mustProvide("binom") && !isRequired("amsmath"))
849 macros << binom_def << '\n';
850 if (mustProvide("mathcircumflex"))
851 macros << mathcircumflex_def << '\n';
854 if (mustProvide("ParagraphLeftIndent"))
855 macros << paragraphleftindent_def;
856 if (mustProvide("NeedLyXFootnoteCode"))
857 macros << floatingfootnote_def;
859 // some problems with tex->html converters
860 if (mustProvide("NeedTabularnewline"))
861 macros << tabularnewline_def;
863 // greyedout environment (note inset)
864 if (mustProvide("lyxgreyedout"))
865 macros << lyxgreyedout_def;
867 if (mustProvide("lyxdot"))
868 macros << lyxdot_def << '\n';
871 getFloatDefinitions(macros);
874 if (mustProvide("ct-dvipost"))
875 macros << changetracking_dvipost_def;
877 if (mustProvide("ct-xcolor-ulem")) {
878 int const prec = macros.precision(2);
880 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
881 macros << "\\providecolor{lyxadded}{rgb}{"
882 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
884 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
885 macros << "\\providecolor{lyxdeleted}{rgb}{"
886 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
888 macros.precision(prec);
890 if (isRequired("hyperref"))
891 macros << changetracking_xcolor_ulem_hyperref_def;
893 macros << changetracking_xcolor_ulem_def;
896 if (mustProvide("ct-none"))
897 macros << changetracking_none_def;
903 string const LaTeXFeatures::getBabelOptions() const
907 LanguageList::const_iterator it = UsedLanguages_.begin();
908 LanguageList::const_iterator end = UsedLanguages_.end();
909 for (; it != end; ++it)
910 if (!(*it)->latex_options().empty())
911 tmp << (*it)->latex_options() << '\n';
912 if (!params_.language->latex_options().empty())
913 tmp << params_.language->latex_options() << '\n';
919 docstring const LaTeXFeatures::getTClassPreamble() const
921 // the text class specific preamble
922 DocumentClass const & tclass = params_.documentClass();
923 odocstringstream tcpreamble;
925 tcpreamble << tclass.preamble();
927 list<docstring>::const_iterator cit = usedLayouts_.begin();
928 list<docstring>::const_iterator end = usedLayouts_.end();
929 for (; cit != end; ++cit)
930 tcpreamble << tclass[*cit].preamble();
932 cit = usedInsetLayouts_.begin();
933 end = usedInsetLayouts_.end();
934 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
935 for (; cit != end; ++cit) {
936 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
939 tcpreamble << it->second.preamble();
942 return tcpreamble.str();
946 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
948 DocumentClass const & tclass = params_.documentClass();
949 odocstringstream tcpreamble;
951 tcpreamble << tclass.htmlpreamble();
953 list<docstring>::const_iterator cit = usedLayouts_.begin();
954 list<docstring>::const_iterator end = usedLayouts_.end();
955 for (; cit != end; ++cit)
956 tcpreamble << tclass[*cit].htmlpreamble();
958 cit = usedInsetLayouts_.begin();
959 end = usedInsetLayouts_.end();
960 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
961 for (; cit != end; ++cit) {
962 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
965 tcpreamble << it->second.htmlpreamble();
968 return tcpreamble.str();
972 docstring const LaTeXFeatures::getTClassHTMLStyles() const {
973 DocumentClass const & tclass = params_.documentClass();
974 odocstringstream tcpreamble;
976 list<docstring>::const_iterator cit = usedLayouts_.begin();
977 list<docstring>::const_iterator end = usedLayouts_.end();
978 for (; cit != end; ++cit)
979 tcpreamble << tclass[*cit].htmlstyle();
981 cit = usedInsetLayouts_.begin();
982 end = usedInsetLayouts_.end();
983 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
984 for (; cit != end; ++cit) {
985 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
988 tcpreamble << it->second.htmlstyle();
991 return tcpreamble.str();
996 docstring const getFloatI18nPreamble(docstring const & type, docstring const & name, docstring const & lang)
999 os << "\\addto\\captions" << lang
1000 << "{\\renewcommand{\\" << type << "name}{" << name << "}}\n";
1006 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
1008 DocumentClass const & tclass = params_.documentClass();
1009 // collect preamble snippets in a set to prevent multiple identical
1010 // commands (would happen if e.g. both theorem and theorem* are used)
1011 set<docstring> snippets;
1012 typedef LanguageList::const_iterator lang_it;
1013 lang_it const lbeg = UsedLanguages_.begin();
1014 lang_it const lend = UsedLanguages_.end();
1015 list<docstring>::const_iterator cit = usedLayouts_.begin();
1016 list<docstring>::const_iterator end = usedLayouts_.end();
1017 for (; cit != end; ++cit) {
1018 // language dependent commands (once per document)
1019 snippets.insert(tclass[*cit].langpreamble(buffer().language()));
1020 // commands for language changing (for multilanguage documents)
1021 if (use_babel && !UsedLanguages_.empty()) {
1022 snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
1023 for (lang_it lit = lbeg; lit != lend; ++lit)
1024 snippets.insert(tclass[*cit].babelpreamble(*lit));
1027 if (use_babel && !UsedLanguages_.empty()) {
1028 FloatList const & floats = params_.documentClass().floats();
1029 UsedFloats::const_iterator fit = usedFloats_.begin();
1030 UsedFloats::const_iterator fend = usedFloats_.end();
1031 for (; fit != fend; ++fit) {
1032 Floating const & fl = floats.getType(fit->first);
1033 docstring const type = from_ascii(fl.type());
1034 docstring const flname = from_utf8(fl.name());
1035 docstring name = translateIfPossible(flname,
1036 buffer().language()->code());
1037 snippets.insert(getFloatI18nPreamble(
1039 from_ascii(buffer().language()->babel())));
1040 for (lang_it lit = lbeg; lit != lend; ++lit) {
1041 name = translateIfPossible(flname,
1043 snippets.insert(getFloatI18nPreamble(
1045 from_ascii((*lit)->babel())));
1050 odocstringstream tcpreamble;
1051 set<docstring>::const_iterator const send = snippets.end();
1052 set<docstring>::const_iterator it = snippets.begin();
1053 for (; it != send; ++it)
1055 return tcpreamble.str();
1059 docstring const LaTeXFeatures::getLyXSGMLEntities() const
1061 // Definition of entities used in the document that are LyX related.
1062 odocstringstream entities;
1064 if (mustProvide("lyxarrow")) {
1065 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
1068 return entities.str();
1072 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1074 odocstringstream sgmlpreamble;
1076 docstring const basename(from_utf8(onlyPath(fname)));
1078 FileMap::const_iterator end = IncludedFiles_.end();
1079 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1082 sgmlpreamble << "\n<!ENTITY " << fi->first
1083 << (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"")
1084 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1086 return sgmlpreamble.str();
1090 void LaTeXFeatures::showStruct() const
1092 lyxerr << "LyX needs the following commands when LaTeXing:"
1093 << "\n***** Packages:" << getPackages()
1094 << "\n***** Macros:" << to_utf8(getMacros())
1095 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1096 << "\n***** done." << endl;
1100 Buffer const & LaTeXFeatures::buffer() const
1106 void LaTeXFeatures::setBuffer(Buffer const & buffer)
1112 BufferParams const & LaTeXFeatures::bufferParams() const
1118 void LaTeXFeatures::getFloatDefinitions(odocstream & os) const
1120 FloatList const & floats = params_.documentClass().floats();
1122 // Here we will output the code to create the needed float styles.
1123 // We will try to do this as minimal as possible.
1124 // \floatstyle{ruled}
1125 // \newfloat{algorithm}{htbp}{loa}
1126 // \providecommand{\algorithmname}{Algorithm}
1127 // \floatname{algorithm}{\protect\algorithmname}
1128 UsedFloats::const_iterator cit = usedFloats_.begin();
1129 UsedFloats::const_iterator end = usedFloats_.end();
1130 for (; cit != end; ++cit) {
1131 Floating const & fl = floats.getType(cit->first);
1133 // For builtin floats we do nothing.
1134 if (fl.builtin()) continue;
1136 // We have to special case "table" and "figure"
1137 if (fl.type() == "tabular" || fl.type() == "figure") {
1138 // Output code to modify "table" or "figure"
1139 // but only if builtin == false
1140 // and that have to be true at this point in the
1142 docstring const type = from_ascii(fl.type());
1143 docstring const placement = from_ascii(fl.placement());
1144 docstring const style = from_ascii(fl.style());
1145 if (!style.empty()) {
1146 os << "\\floatstyle{" << style << "}\n"
1147 << "\\restylefloat{" << type << "}\n";
1149 if (!placement.empty()) {
1150 os << "\\floatplacement{" << type << "}{"
1151 << placement << "}\n";
1154 // The other non builtin floats.
1156 docstring const type = from_ascii(fl.type());
1157 docstring const placement = from_ascii(fl.placement());
1158 docstring const ext = from_ascii(fl.ext());
1159 docstring const within = from_ascii(fl.within());
1160 docstring const style = from_ascii(fl.style());
1161 docstring const name = translateIfPossible(
1162 from_utf8(fl.name()),
1163 buffer().language()->code());
1164 os << "\\floatstyle{" << style << "}\n"
1165 << "\\newfloat{" << type << "}{" << placement
1166 << "}{" << ext << '}';
1167 if (!within.empty())
1168 os << '[' << within << ']';
1170 << "\\providecommand{\\" << type << "name}{"
1172 << "\\floatname{" << type << "}{\\protect\\"
1173 << type << "name}\n";
1175 // What missing here is to code to minimalize the code
1176 // output so that the same floatstyle will not be
1177 // used several times, when the same style is still in
1181 os << "\n\\newsubfloat{" << from_ascii(fl.type()) << "}\n";