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"
27 #include "LaTeXPackages.h"
31 #include "TextClass.h"
33 #include "insets/InsetLayout.h"
35 #include "support/debug.h"
36 #include "support/docstream.h"
37 #include "support/FileName.h"
38 #include "support/filetools.h"
39 #include "support/gettext.h"
40 #include "support/lstrings.h"
41 #include "support/regex.h"
47 using namespace lyx::support;
52 /////////////////////////////////////////////////////////////////////
56 /////////////////////////////////////////////////////////////////////
58 //\NeedsTeXFormat{LaTeX2e}
59 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
60 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
62 static docstring const lyx_def = from_ascii(
63 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
65 static docstring const lyx_hyperref_def = from_ascii(
66 "\\providecommand{\\LyX}{\\texorpdfstring%\n"
67 " {L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}\n"
70 static docstring const noun_def = from_ascii(
71 "\\newcommand{\\noun}[1]{\\textsc{#1}}");
73 static docstring const lyxarrow_def = from_ascii(
74 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
76 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
77 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
79 // for quotes without babel. This does not give perfect results, but
80 // anybody serious about non-english quotes should use babel (JMarc).
82 static docstring const quotedblbase_def = from_ascii(
83 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
84 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
85 " \\penalty10000\\hskip0em\\relax%\n"
88 static docstring const quotesinglbase_def = from_ascii(
89 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
90 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
91 " \\penalty10000\\hskip0em\\relax%\n"
94 static docstring const guillemotleft_def = from_ascii(
95 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
96 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
97 "\\penalty10000\\hskip0pt\\relax%\n"
100 static docstring const guillemotright_def = from_ascii(
101 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
102 " \\penalty10000\\hskip0pt%\n"
103 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
106 static docstring const guilsinglleft_def = from_ascii(
107 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
108 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
109 " \\penalty10000\\hskip0pt\\relax%\n"
112 static docstring const guilsinglright_def = from_ascii(
113 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
114 " \\penalty10000\\hskip0pt%\n"
115 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
118 static docstring const paragraphleftindent_def = from_ascii(
119 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
121 " \\begin{list}{}{%\n"
122 " \\setlength{\\topsep}{0pt}%\n"
123 " \\addtolength{\\leftmargin}{#1}\n"
124 // ho hum, yet more things commented out with no hint as to why they
125 // weren't just removed
126 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
127 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
128 // "%% \\setlength\\listparindent\\parindent%\n"
129 // "%% \\setlength\\itemindent\\parindent%\n"
130 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
136 static docstring const floatingfootnote_def = from_ascii(
137 "%% Special footnote code from the package 'stblftnt.sty'\n"
138 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
139 "\\let\\SF@@footnote\\footnote\n"
140 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
141 " \\expandafter\\SF@@footnote\n"
143 " \\expandafter\\SF@gobble@opt\n"
146 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
147 " \\SF@gobble@twobracket\n"
150 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
151 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
152 "\\def\\SF@gobble@twobracket[#1]#2{}\n");
154 static docstring const binom_def = from_ascii(
155 "%% Binom macro for standard LaTeX users\n"
156 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
158 static docstring const mathcircumflex_def = from_ascii(
159 "%% For printing a cirumflex inside a formula\n"
160 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
162 static docstring const tabularnewline_def = from_ascii(
163 "%% Because html converters don't know tabularnewline\n"
164 "\\providecommand{\\tabularnewline}{\\\\}\n");
166 static docstring const lyxgreyedout_def = from_ascii(
167 "%% The greyedout annotation environment\n"
168 "\\newenvironment{lyxgreyedout}\n"
169 " {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n"
170 " {\\ignorespacesafterend\\egroup}\n");
172 // We want to omit the file extension for includegraphics, but this does not
173 // work when the filename contains other dots.
174 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
175 static docstring const lyxdot_def = from_ascii(
176 "%% A simple dot to overcome graphicx limitations\n"
177 "\\newcommand{\\lyxdot}{.}\n");
179 static docstring const changetracking_dvipost_def = from_ascii(
180 "%% Change tracking with dvipost\n"
182 "\\dvipost{osstart color push Red}\n"
183 "\\dvipost{osend color pop}\n"
184 "\\dvipost{cbstart color push Blue}\n"
185 "\\dvipost{cbend color pop}\n"
186 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
187 "\\newcommand{\\lyxdeleted}[3]{%\n"
188 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n");
190 static docstring const changetracking_xcolor_ulem_def = from_ascii(
191 "%% Change tracking with ulem\n"
192 "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}{}#3}}\n"
193 "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
195 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
196 "%% Change tracking with ulem\n"
197 "\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}{}}{}#3}}\n"
198 "\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
200 static docstring const changetracking_none_def = from_ascii(
201 "\\newcommand{\\lyxadded}[3]{#3}\n"
202 "\\newcommand{\\lyxdeleted}[3]{}\n");
204 static docstring const textgreek_def = from_ascii(
205 "\\DeclareRobustCommand{\\greektext}{%\n"
206 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
207 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
208 "\\DeclareFontEncoding{LGR}{}{}\n"
209 "\\DeclareTextSymbol{\\~}{LGR}{126}");
211 static docstring const textcyr_def = from_ascii(
212 "\\DeclareRobustCommand{\\cyrtext}{%\n"
213 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
214 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
215 "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n");
217 static docstring const lyxmathsym_def = from_ascii(
218 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
219 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
221 static docstring const papersizedvi_def = from_ascii(
222 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
224 static docstring const papersizepdf_def = from_ascii(
225 "\\pdfpageheight\\paperheight\n"
226 "\\pdfpagewidth\\paperwidth\n");
228 static docstring const cedilla_def = from_ascii(
229 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
230 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
232 static docstring const subring_def = from_ascii(
233 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
234 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
236 static docstring const subdot_def = from_ascii(
237 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
238 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
240 static docstring const subhat_def = from_ascii(
241 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
242 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
244 static docstring const subtilde_def = from_ascii(
245 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
246 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
248 static docstring const dacute_def = from_ascii(
249 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
251 static docstring const tipasymb_def = from_ascii(
252 "\\DeclareFontEncoding{T3}{}{}\n"
253 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
255 static docstring const dgrave_def = from_ascii(
256 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
258 static docstring const rcap_def = from_ascii(
259 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
261 static docstring const ogonek_def = from_ascii(
262 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
263 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
264 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
265 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
266 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
268 static docstring const lyxref_def = from_ascii(
269 "\\RS@ifundefined{subref}\n"
270 " {\\def\\RSsubtxt{section~}\\newref{sub}{name = \\RSsubtxt}}\n"
272 "\\RS@ifundefined{thmref}\n"
273 " {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
275 "\\RS@ifundefined{lemref}\n"
276 " {\\def\\RSlemtxt{lemma~}\\newref{lem}{name = \\RSlemtxt}}\n"
280 /////////////////////////////////////////////////////////////////////
284 /////////////////////////////////////////////////////////////////////
287 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
288 OutputParams const & r)
289 : buffer_(&b), params_(p), runparams_(r), in_float_(false)
293 bool LaTeXFeatures::useBabel() const
295 if (usePolyglossia())
297 if (bufferParams().lang_package == "default")
298 return (lyxrc.language_package_selection != LyXRC::LP_NONE)
299 || (bufferParams().language->lang() != lyxrc.default_language
300 && !bufferParams().language->babel().empty())
301 || this->hasLanguages();
302 return (bufferParams().lang_package != "none")
303 || (bufferParams().language->lang() != lyxrc.default_language
304 && !bufferParams().language->babel().empty())
305 || this->hasLanguages();
309 bool LaTeXFeatures::usePolyglossia() const
311 if (bufferParams().lang_package == "default")
312 return (lyxrc.language_package_selection == LyXRC::LP_AUTO)
313 && isRequired("polyglossia")
314 && isAvailable("polyglossia")
315 && !params_.documentClass().provides("babel")
316 && this->hasOnlyPolyglossiaLanguages();
317 return (bufferParams().lang_package == "auto")
318 && isRequired("polyglossia")
319 && isAvailable("polyglossia")
320 && !params_.documentClass().provides("babel")
321 && this->hasOnlyPolyglossiaLanguages();
325 void LaTeXFeatures::require(string const & name)
327 features_.insert(name);
331 void LaTeXFeatures::require(set<string> const & names)
333 features_.insert(names.begin(), names.end());
337 void LaTeXFeatures::useLayout(docstring const & layoutname)
339 // Some code to avoid loops in dependency definition
340 static int level = 0;
341 const int maxlevel = 30;
342 if (level > maxlevel) {
343 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
344 << "recursion attained by layout "
345 << to_utf8(layoutname) << endl;
349 DocumentClass const & tclass = params_.documentClass();
350 if (tclass.hasLayout(layoutname)) {
351 // Is this layout already in usedLayouts?
352 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
353 != usedLayouts_.end())
356 Layout const & layout = tclass[layoutname];
357 require(layout.requires());
359 if (!layout.depends_on().empty()) {
361 useLayout(layout.depends_on());
364 usedLayouts_.push_back(layoutname);
366 lyxerr << "LaTeXFeatures::useLayout: layout `"
367 << to_utf8(layoutname) << "' does not exist in this class"
375 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
377 docstring const & lname = lay.name();
378 DocumentClass const & tclass = params_.documentClass();
380 // this is a default inset layout, nothing useful here
381 if (!tclass.hasInsetLayout(lname))
383 // Is this layout already in usedInsetLayouts?
384 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
385 != usedInsetLayouts_.end())
388 require(lay.requires());
389 usedInsetLayouts_.push_back(lname);
393 bool LaTeXFeatures::isRequired(string const & name) const
395 return features_.find(name) != features_.end();
399 bool LaTeXFeatures::mustProvide(string const & name) const
401 return isRequired(name) && !params_.documentClass().provides(name);
405 bool LaTeXFeatures::isAvailable(string const & name)
407 string::size_type const i = name.find("->");
408 if (i != string::npos) {
409 string const from = name.substr(0,i);
410 string const to = name.substr(i+2);
411 //LYXERR0("from=[" << from << "] to=[" << to << "]");
412 return theConverters().isReachable(from, to);
414 return LaTeXPackages::isAvailable(name);
418 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
420 SnippetList::const_iterator begin = preamble_snippets_.begin();
421 SnippetList::const_iterator end = preamble_snippets_.end();
422 if (find(begin, end, preamble) == end)
423 preamble_snippets_.push_back(preamble);
427 void LaTeXFeatures::addCSSSnippet(std::string const & snippet)
429 SnippetList::const_iterator begin = css_snippets_.begin();
430 SnippetList::const_iterator end = css_snippets_.end();
431 if (find(begin, end, snippet) == end)
432 css_snippets_.push_back(snippet);
436 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
438 if (!usedFloats_[name])
439 usedFloats_[name] = subfloat;
442 // We only need float.sty if we use non builtin floats, or if we
443 // use the "H" modifier. This includes modified table and
444 // figure floats. (Lgb)
445 Floating const & fl = params_.documentClass().floats().getType(name);
446 if (!fl.floattype().empty() && fl.usesFloatPkg()) {
452 void LaTeXFeatures::useLanguage(Language const * lang)
454 if (!lang->babel().empty() || !lang->polyglossia().empty())
455 UsedLanguages_.insert(lang);
456 if (!lang->requires().empty())
457 require(lang->requires());
458 // CJK languages do not have a babel name.
459 // They use the CJK package
460 if (lang->encoding()->package() == Encoding::CJK)
462 // japanese package is special
463 if (lang->encoding()->package() == Encoding::japanese)
468 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
470 IncludedFiles_[key] = name;
474 bool LaTeXFeatures::hasLanguages() const
476 return !UsedLanguages_.empty();
480 bool LaTeXFeatures::hasOnlyPolyglossiaLanguages() const
482 LanguageList::const_iterator const begin = UsedLanguages_.begin();
483 for (LanguageList::const_iterator cit = begin;
484 cit != UsedLanguages_.end();
486 if ((*cit)->polyglossia().empty())
493 bool LaTeXFeatures::hasPolyglossiaExclusiveLanguages() const
495 LanguageList::const_iterator const begin = UsedLanguages_.begin();
496 for (LanguageList::const_iterator cit = begin;
497 cit != UsedLanguages_.end();
499 if ((*cit)->babel().empty() && !(*cit)->polyglossia().empty() && (*cit)->requires().empty())
506 string LaTeXFeatures::getBabelLanguages() const
508 ostringstream languages;
511 LanguageList::const_iterator const begin = UsedLanguages_.begin();
512 for (LanguageList::const_iterator cit = begin;
513 cit != UsedLanguages_.end();
515 if ((*cit)->babel().empty())
521 languages << (*cit)->babel();
523 return languages.str();
527 std::map<std::string, std::string> LaTeXFeatures::getPolyglossiaLanguages() const
529 std::map<std::string, std::string> languages;
531 LanguageList::const_iterator const begin = UsedLanguages_.begin();
532 for (LanguageList::const_iterator cit = begin;
533 cit != UsedLanguages_.end();
535 languages[(*cit)->polyglossia()] = (*cit)->polyglossiaOpts();
541 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
543 // This does only find encodings of languages supported by babel, but
544 // that does not matter since we don't have a language with an
545 // encoding supported by inputenc but without babel support.
546 set<string> encodings;
547 LanguageList::const_iterator it = UsedLanguages_.begin();
548 LanguageList::const_iterator end = UsedLanguages_.end();
549 for (; it != end; ++it)
550 if ((*it)->encoding()->latexName() != doc_encoding &&
551 ((*it)->encoding()->package() == Encoding::inputenc
552 || (*it)->encoding()->package() == Encoding::japanese))
553 encodings.insert((*it)->encoding()->latexName());
559 char const * simplefeatures[] = {
560 // note that the package order here will be the same in the LaTeX-output
567 // subfig is handled in BufferParams.cpp
571 /*For a successful cooperation of the `wrapfig' package with the
572 `float' package you should load the `wrapfig' package *after*
573 the `float' package. See the caption package documentation
607 // listings is handled in BufferParams.cpp
616 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
621 string const LaTeXFeatures::getColorOptions() const
623 ostringstream colors;
625 // Handling the color packages separately is needed to be able to load them
626 // before babel when hyperref is loaded with the colorlinks option
627 // for more info see Bufferparams.cpp
630 if (mustProvide("color") || mustProvide("xcolor")) {
631 string const package =
632 (mustProvide("xcolor") ? "xcolor" : "color");
633 if (params_.graphics_driver == "default"
634 || params_.graphics_driver == "none")
635 colors << "\\usepackage{" << package << "}\n";
637 colors << "\\usepackage["
638 << params_.graphics_driver
639 << "]{" << package << "}\n";
642 // pdfcolmk must be loaded after color
643 if (mustProvide("pdfcolmk"))
644 colors << "\\usepackage{pdfcolmk}\n";
646 // the following 3 color commands must be set after color
647 // is loaded and before pdfpages, therefore add the command
648 // here define the set color
649 if (mustProvide("pagecolor")) {
650 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
651 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
652 // set the page color
653 colors << "\\pagecolor{page_backgroundcolor}\n";
656 if (mustProvide("fontcolor")) {
657 colors << "\\definecolor{document_fontcolor}{rgb}{";
658 colors << outputLaTeXColor(params_.fontcolor) << "}\n";
660 colors << "\\color{document_fontcolor}\n";
663 if (mustProvide("lyxgreyedout")) {
664 colors << "\\definecolor{note_fontcolor}{rgb}{";
665 colors << outputLaTeXColor(params_.notefontcolor) << "}\n";
666 // the color will be set together with the definition of
667 // the lyxgreyedout environment (see lyxgreyedout_def)
670 // color for shaded boxes
671 if (isRequired("framed") && mustProvide("color")) {
672 colors << "\\definecolor{shadecolor}{rgb}{";
673 colors << outputLaTeXColor(params_.boxbgcolor) << "}\n";
674 // this color is automatically used by the LaTeX-package "framed"
681 string const LaTeXFeatures::getPackages() const
683 ostringstream packages;
684 DocumentClass const & tclass = params_.documentClass();
686 // FIXME: currently, we can only load packages and macros known
688 // However, with the Require tag of layouts/custom insets,
689 // also unknown packages can be requested. They are silently
690 // swallowed now. We should change this eventually.
693 // These are all the 'simple' includes. i.e
694 // packages which we just \usepackage{package}
696 for (int i = 0; i < nb_simplefeatures; ++i) {
697 if (mustProvide(simplefeatures[i]))
698 packages << "\\usepackage{"
699 << simplefeatures[i] << "}\n";
703 // The rest of these packages are somewhat more complicated
707 // if fontspec is used, AMS packages have to be loaded before
708 // fontspec (in BufferParams)
709 string const amsPackages = loadAMSPackages();
710 if (!params_.useNonTeXFonts && !amsPackages.empty())
711 packages << amsPackages;
713 // fixltx2e must be loaded after amsthm, since amsthm produces an error with
714 // the redefined \[ command (bug 7233). Load it as early as possible, since
715 // other packages might profit from it.
716 if (mustProvide("fixltx2e"))
717 packages << "\\usepackage{fixltx2e}\n";
719 // wasysym is a simple feature, but it must be after amsmath if both
721 // wasysym redefines some integrals (e.g. iint) from amsmath. That
722 // leads to inconsistent integrals. We only load this package if
723 // the document does not contain integrals (then isRequired("esint")
724 // is false) or if esint is used, since esint redefines all relevant
725 // integral symbols from wasysym and amsmath.
726 // See http://www.lyx.org/trac/ticket/1942
727 if (mustProvide("wasysym") &&
728 params_.use_package("wasysym") != BufferParams::package_off &&
729 (params_.use_package("esint") != BufferParams::package_off || !isRequired("esint")))
730 packages << "\\usepackage{wasysym}\n";
732 // accents must be loaded after amsmath
733 if (mustProvide("accents") &&
734 params_.use_package("accents") != BufferParams::package_off)
735 packages << "\\usepackage{accents}\n";
737 // mathdots must be loaded after amsmath
738 if (mustProvide("mathdots") &&
739 params_.use_package("mathdots") != BufferParams::package_off)
740 packages << "\\usepackage{mathdots}\n";
742 // yhmath must be loaded after amsmath
743 if (mustProvide("yhmath") &&
744 params_.use_package("yhmath") != BufferParams::package_off)
745 packages << "\\usepackage{yhmath}\n";
747 if (mustProvide("undertilde") &&
748 params_.use_package("undertilde") != BufferParams::package_off)
749 packages << "\\usepackage{undertilde}\n";
751 // [x]color and pdfcolmk are handled in getColorOptions() above
754 if (isRequired("makeidx") || isRequired("splitidx")) {
755 if (!tclass.provides("makeidx") && !isRequired("splitidx"))
756 packages << "\\usepackage{makeidx}\n";
757 if (!tclass.provides("splitidx") && isRequired("splitidx"))
758 packages << "\\usepackage{splitidx}\n";
759 packages << "\\makeindex\n";
763 if (mustProvide("graphicx") && params_.graphics_driver != "none") {
764 if (params_.graphics_driver == "default")
765 packages << "\\usepackage{graphicx}\n";
767 packages << "\\usepackage["
768 << params_.graphics_driver
772 // lyxskak.sty --- newer chess support based on skak.sty
773 if (mustProvide("chess"))
774 packages << "\\usepackage[ps,mover]{lyxskak}\n";
777 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
778 packages << "\\usepackage{setspace}\n";
780 // esint must be after amsmath and wasysym, since it will redeclare
781 // inconsistent integral symbols
782 if (mustProvide("esint") &&
783 params_.use_package("esint") != BufferParams::package_off)
784 packages << "\\usepackage{esint}\n";
787 // Some classes load natbib themselves, but still allow (or even require)
788 // plain numeric citations (ReVTeX is such a case, see bug 5182).
789 // This special case is indicated by the "natbib-internal" key.
790 if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
791 packages << "\\usepackage[";
792 if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
793 packages << "numbers";
795 packages << "authoryear";
796 packages << "]{natbib}\n";
799 // jurabib -- we need version 0.6 at least.
800 if (mustProvide("jurabib"))
801 packages << "\\usepackage{jurabib}[2004/01/25]\n";
803 // xargs -- we need version 1.09 at least
804 if (mustProvide("xargs"))
805 packages << "\\usepackage{xargs}[2008/03/08]\n";
807 if (mustProvide("xy"))
808 packages << "\\usepackage[all]{xy}\n";
810 if (mustProvide("feyn"))
811 packages << "\\usepackage{feyn}\n"; //Diagram
813 if (mustProvide("ulem"))
814 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
815 "\\usepackage{ulem}\n";
817 if (mustProvide("mhchem") &&
818 params_.use_package("mhchem") != BufferParams::package_off)
819 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
820 "\\usepackage{mhchem}\n";
822 if (mustProvide("nomencl")) {
823 // Make it work with the new and old version of the package,
824 // but don't use the compatibility option since it is
825 // incompatible to other packages.
826 packages << "\\usepackage{nomencl}\n"
827 "% the following is useful when we have the old nomencl.sty package\n"
828 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
829 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
830 "\\makenomenclature\n";
833 // fixltx2e provides subscript
834 if (mustProvide("subscript") && !isRequired("fixltx2e"))
835 packages << "\\usepackage{subscript}\n";
837 return packages.str();
841 string LaTeXFeatures::getPreambleSnippets() const
844 SnippetList::const_iterator pit = preamble_snippets_.begin();
845 SnippetList::const_iterator pend = preamble_snippets_.end();
846 for (; pit != pend; ++pit)
847 snip << *pit << '\n';
852 std::string LaTeXFeatures::getCSSSnippets() const
855 SnippetList::const_iterator pit = css_snippets_.begin();
856 SnippetList::const_iterator pend = css_snippets_.end();
857 for (; pit != pend; ++pit)
858 snip << *pit << '\n';
863 docstring const LaTeXFeatures::getMacros() const
865 odocstringstream macros;
867 if (!preamble_snippets_.empty()) {
869 macros << from_utf8(getPreambleSnippets());
872 if (mustProvide("papersize")) {
873 if (runparams_.flavor == OutputParams::LATEX)
874 macros << papersizedvi_def << '\n';
876 macros << papersizepdf_def << '\n';
879 if (mustProvide("LyX")) {
880 if (isRequired("hyperref"))
881 macros << lyx_hyperref_def << '\n';
883 macros << lyx_def << '\n';
886 if (mustProvide("noun"))
887 macros << noun_def << '\n';
889 if (mustProvide("lyxarrow"))
890 macros << lyxarrow_def << '\n';
892 if (!usePolyglossia() && mustProvide("textgreek")) {
893 // Avoid a LaTeX error if times fonts are used and the grtimes
894 // package is installed but actual fonts are not (bug 6469).
895 if (params_.fonts_roman == "times")
896 macros << subst(textgreek_def,
897 from_ascii("\\greektext #1"),
898 from_ascii("%\n \\IfFileExists"
899 "{grtm10.tfm}{}{\\fontfamily"
900 "{cmr}}\\greektext #1"))
903 macros << textgreek_def << '\n';
906 if (!usePolyglossia() && mustProvide("textcyr"))
907 macros << textcyr_def << '\n';
909 if (mustProvide("lyxmathsym"))
910 macros << lyxmathsym_def << '\n';
912 if (mustProvide("cedilla"))
913 macros << cedilla_def << '\n';
915 if (mustProvide("subring"))
916 macros << subring_def << '\n';
918 if (mustProvide("subdot"))
919 macros << subdot_def << '\n';
921 if (mustProvide("subhat"))
922 macros << subhat_def << '\n';
924 if (mustProvide("subtilde"))
925 macros << subtilde_def << '\n';
927 if (mustProvide("dacute"))
928 macros << dacute_def << '\n';
930 if (mustProvide("tipasymb"))
931 macros << tipasymb_def << '\n';
933 if (mustProvide("dgrave"))
934 macros << dgrave_def << '\n';
936 if (mustProvide("rcap"))
937 macros << rcap_def << '\n';
939 if (mustProvide("ogonek"))
940 macros << ogonek_def << '\n';
943 if (mustProvide("quotesinglbase"))
944 macros << quotesinglbase_def << '\n';
945 if (mustProvide("quotedblbase"))
946 macros << quotedblbase_def << '\n';
947 if (mustProvide("guilsinglleft"))
948 macros << guilsinglleft_def << '\n';
949 if (mustProvide("guilsinglright"))
950 macros << guilsinglright_def << '\n';
951 if (mustProvide("guillemotleft"))
952 macros << guillemotleft_def << '\n';
953 if (mustProvide("guillemotright"))
954 macros << guillemotright_def << '\n';
957 if (mustProvide("binom") && !isRequired("amsmath"))
958 macros << binom_def << '\n';
959 if (mustProvide("mathcircumflex"))
960 macros << mathcircumflex_def << '\n';
963 if (mustProvide("ParagraphLeftIndent"))
964 macros << paragraphleftindent_def;
965 if (mustProvide("NeedLyXFootnoteCode"))
966 macros << floatingfootnote_def;
968 // some problems with tex->html converters
969 if (mustProvide("NeedTabularnewline"))
970 macros << tabularnewline_def;
972 // greyed-out environment (note inset)
973 // the color is specified in the routine
974 // getColorOptions() to avoid LaTeX-package clashes
975 if (mustProvide("lyxgreyedout"))
976 macros << lyxgreyedout_def;
978 if (mustProvide("lyxdot"))
979 macros << lyxdot_def << '\n';
982 getFloatDefinitions(macros);
984 if (mustProvide("refstyle"))
985 macros << lyxref_def << '\n';
988 if (mustProvide("ct-dvipost"))
989 macros << changetracking_dvipost_def;
991 if (mustProvide("ct-xcolor-ulem")) {
992 streamsize const prec = macros.precision(2);
994 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
995 macros << "\\providecolor{lyxadded}{rgb}{"
996 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
998 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
999 macros << "\\providecolor{lyxdeleted}{rgb}{"
1000 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
1002 macros.precision(prec);
1004 if (isRequired("hyperref"))
1005 macros << changetracking_xcolor_ulem_hyperref_def;
1007 macros << changetracking_xcolor_ulem_def;
1010 if (mustProvide("ct-none"))
1011 macros << changetracking_none_def;
1013 return macros.str();
1017 string const LaTeXFeatures::getBabelPresettings() const
1021 LanguageList::const_iterator it = UsedLanguages_.begin();
1022 LanguageList::const_iterator end = UsedLanguages_.end();
1023 for (; it != end; ++it)
1024 if (!(*it)->babel_presettings().empty())
1025 tmp << (*it)->babel_presettings() << '\n';
1026 if (!params_.language->babel_presettings().empty())
1027 tmp << params_.language->babel_presettings() << '\n';
1033 string const LaTeXFeatures::getBabelPostsettings() const
1037 LanguageList::const_iterator it = UsedLanguages_.begin();
1038 LanguageList::const_iterator end = UsedLanguages_.end();
1039 for (; it != end; ++it)
1040 if (!(*it)->babel_postsettings().empty())
1041 tmp << (*it)->babel_postsettings() << '\n';
1042 if (!params_.language->babel_postsettings().empty())
1043 tmp << params_.language->babel_postsettings() << '\n';
1049 bool LaTeXFeatures::needBabelLangOptions() const
1051 if (!lyxrc.language_global_options || params_.language->asBabelOptions())
1054 LanguageList::const_iterator it = UsedLanguages_.begin();
1055 LanguageList::const_iterator end = UsedLanguages_.end();
1056 for (; it != end; ++it)
1057 if ((*it)->asBabelOptions())
1064 string const LaTeXFeatures::loadAMSPackages() const
1067 if (mustProvide("amsthm"))
1068 tmp << "\\usepackage{amsthm}\n";
1070 if (mustProvide("amsmath")
1071 && params_.use_package("amsmath") != BufferParams::package_off) {
1072 tmp << "\\usepackage{amsmath}\n";
1074 // amsbsy and amstext are already provided by amsmath
1075 if (mustProvide("amsbsy"))
1076 tmp << "\\usepackage{amsbsy}\n";
1077 if (mustProvide("amstext"))
1078 tmp << "\\usepackage{amstext}\n";
1081 if (mustProvide("amssymb")
1082 && params_.use_package("amssymb") != BufferParams::package_off)
1083 tmp << "\\usepackage{amssymb}\n";
1089 docstring const LaTeXFeatures::getTClassPreamble() const
1091 // the text class specific preamble
1092 DocumentClass const & tclass = params_.documentClass();
1093 odocstringstream tcpreamble;
1095 tcpreamble << tclass.preamble();
1097 list<docstring>::const_iterator cit = usedLayouts_.begin();
1098 list<docstring>::const_iterator end = usedLayouts_.end();
1099 for (; cit != end; ++cit)
1100 tcpreamble << tclass[*cit].preamble();
1102 cit = usedInsetLayouts_.begin();
1103 end = usedInsetLayouts_.end();
1104 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1105 for (; cit != end; ++cit) {
1106 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1107 if (it == ils.end())
1109 tcpreamble << it->second.preamble();
1112 return tcpreamble.str();
1116 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
1118 DocumentClass const & tclass = params_.documentClass();
1119 odocstringstream tcpreamble;
1121 tcpreamble << tclass.htmlpreamble();
1123 list<docstring>::const_iterator cit = usedLayouts_.begin();
1124 list<docstring>::const_iterator end = usedLayouts_.end();
1125 for (; cit != end; ++cit)
1126 tcpreamble << tclass[*cit].htmlpreamble();
1128 cit = usedInsetLayouts_.begin();
1129 end = usedInsetLayouts_.end();
1130 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1131 for (; cit != end; ++cit) {
1132 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1133 if (it == ils.end())
1135 tcpreamble << it->second.htmlpreamble();
1138 return tcpreamble.str();
1142 docstring const LaTeXFeatures::getTClassHTMLStyles() const
1144 DocumentClass const & tclass = params_.documentClass();
1145 odocstringstream tcpreamble;
1147 tcpreamble << tclass.htmlstyles();
1149 list<docstring>::const_iterator cit = usedLayouts_.begin();
1150 list<docstring>::const_iterator end = usedLayouts_.end();
1151 for (; cit != end; ++cit)
1152 tcpreamble << tclass[*cit].htmlstyle();
1154 cit = usedInsetLayouts_.begin();
1155 end = usedInsetLayouts_.end();
1156 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1157 for (; cit != end; ++cit) {
1158 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1159 if (it == ils.end())
1161 tcpreamble << it->second.htmlstyle();
1164 return tcpreamble.str();
1169 docstring const getFloatI18nPreamble(docstring const & type,
1170 docstring const & name, Language const * lang,
1171 Encoding const & enc, bool const polyglossia)
1173 // Check whether name can be encoded in the buffer encoding
1174 bool encodable = true;
1175 for (size_t i = 0; i < name.size(); ++i) {
1176 if (!enc.encodable(name[i])) {
1182 docstring const language = polyglossia ? from_ascii(lang->polyglossia())
1183 : from_ascii(lang->babel());
1184 docstring const langenc = from_ascii(lang->encoding()->iconvName());
1185 docstring const texenc = from_ascii(lang->encoding()->latexName());
1186 docstring const bufenc = from_ascii(enc.iconvName());
1187 docstring const s1 = docstring(1, 0xF0000);
1188 docstring const s2 = docstring(1, 0xF0001);
1189 docstring const translated = encodable ? name
1190 : from_ascii("\\inputencoding{") + texenc + from_ascii("}")
1191 + s1 + langenc + s2 + name + s1 + bufenc + s2;
1193 odocstringstream os;
1194 os << "\\addto\\captions" << language
1195 << "{\\renewcommand{\\" << type << "name}{" << translated << "}}\n";
1200 docstring const i18npreamble(docstring const & templ, Language const * lang,
1201 Encoding const & enc, bool const polyglossia)
1206 string preamble = polyglossia ?
1207 subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
1208 subst(to_utf8(templ), "$$lang", lang->babel());
1210 string const langenc = lang->encoding()->iconvName();
1211 string const texenc = lang->encoding()->latexName();
1212 string const bufenc = enc.iconvName();
1213 // First and second character of plane 15 (Private Use Area)
1214 string const s1 = "\xf3\xb0\x80\x80"; // U+F0000
1215 string const s2 = "\xf3\xb0\x80\x81"; // U+F0001
1217 // lyx::regex is not unicode-safe.
1218 // Should use QRegExp or (boost::u32regex, but that requires ICU)
1219 static regex const reg("_\\(([^\\)]+)\\)");
1221 while (regex_search(preamble, sub, reg)) {
1222 string const key = sub.str(1);
1223 docstring const name = lang->translateLayout(key);
1224 // Check whether name can be encoded in the buffer encoding
1225 bool encodable = true;
1226 for (size_t i = 0; i < name.size(); ++i) {
1227 if (!enc.encodable(name[i])) {
1232 string const translated = encodable ? to_utf8(name)
1233 : "\\inputencoding{" + texenc + "}"
1234 + s1 + langenc + s2 + to_utf8(name)
1236 preamble = subst(preamble, sub.str(), translated);
1238 return from_utf8(preamble);
1244 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const
1246 DocumentClass const & tclass = params_.documentClass();
1247 // collect preamble snippets in a set to prevent multiple identical
1248 // commands (would happen if e.g. both theorem and theorem* are used)
1249 set<docstring> snippets;
1250 typedef LanguageList::const_iterator lang_it;
1251 lang_it const lbeg = UsedLanguages_.begin();
1252 lang_it const lend = UsedLanguages_.end();
1253 list<docstring>::const_iterator cit = usedLayouts_.begin();
1254 list<docstring>::const_iterator end = usedLayouts_.end();
1255 for (; cit != end; ++cit) {
1256 // language dependent commands (once per document)
1257 snippets.insert(i18npreamble(tclass[*cit].langpreamble(),
1258 buffer().language(),
1259 buffer().params().encoding(),
1261 // commands for language changing (for multilanguage documents)
1262 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1263 snippets.insert(i18npreamble(
1264 tclass[*cit].babelpreamble(),
1265 buffer().language(),
1266 buffer().params().encoding(),
1268 for (lang_it lit = lbeg; lit != lend; ++lit)
1269 snippets.insert(i18npreamble(
1270 tclass[*cit].babelpreamble(),
1272 buffer().params().encoding(),
1276 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1277 FloatList const & floats = params_.documentClass().floats();
1278 UsedFloats::const_iterator fit = usedFloats_.begin();
1279 UsedFloats::const_iterator fend = usedFloats_.end();
1280 for (; fit != fend; ++fit) {
1281 Floating const & fl = floats.getType(fit->first);
1282 // we assume builtin floats are translated
1283 if (fl.isPredefined())
1285 docstring const type = from_ascii(fl.floattype());
1286 docstring const flname = from_utf8(fl.name());
1287 docstring name = buffer().language()->translateLayout(fl.name());
1288 // only request translation if we have a real translation
1289 // (that differs from the source)
1291 snippets.insert(getFloatI18nPreamble(
1292 type, name, buffer().language(),
1293 buffer().params().encoding(),
1295 for (lang_it lit = lbeg; lit != lend; ++lit) {
1296 string const code = (*lit)->code();
1297 name = (*lit)->translateLayout(fl.name());
1298 // we assume we have a suitable translation if
1299 // either the language is English (we need to
1300 // translate into English if English is a secondary
1301 // language) or if translateIfPossible returns
1302 // something different to the English source.
1303 bool const have_translation =
1304 (flname != name || contains(code, "en"));
1305 if (have_translation)
1306 snippets.insert(getFloatI18nPreamble(
1308 buffer().params().encoding(),
1314 cit = usedInsetLayouts_.begin();
1315 end = usedInsetLayouts_.end();
1316 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1317 for (; cit != end; ++cit) {
1318 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1319 if (it == ils.end())
1321 // language dependent commands (once per document)
1322 snippets.insert(i18npreamble(it->second.langpreamble(),
1323 buffer().language(),
1324 buffer().params().encoding(),
1326 // commands for language changing (for multilanguage documents)
1327 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1328 snippets.insert(i18npreamble(
1329 it->second.babelpreamble(),
1330 buffer().language(),
1331 buffer().params().encoding(),
1333 for (lang_it lit = lbeg; lit != lend; ++lit)
1334 snippets.insert(i18npreamble(
1335 it->second.babelpreamble(),
1337 buffer().params().encoding(),
1342 odocstringstream tcpreamble;
1343 set<docstring>::const_iterator const send = snippets.end();
1344 set<docstring>::const_iterator it = snippets.begin();
1345 for (; it != send; ++it)
1347 return tcpreamble.str();
1351 docstring const LaTeXFeatures::getLyXSGMLEntities() const
1353 // Definition of entities used in the document that are LyX related.
1354 odocstringstream entities;
1356 if (mustProvide("lyxarrow")) {
1357 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
1360 return entities.str();
1364 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1366 odocstringstream sgmlpreamble;
1368 docstring const basename(from_utf8(onlyPath(fname)));
1370 FileMap::const_iterator end = IncludedFiles_.end();
1371 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1374 sgmlpreamble << "\n<!ENTITY " << fi->first
1375 << (isSGMLFileName(fi->second) ? " SYSTEM \"" : " \"")
1376 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1378 return sgmlpreamble.str();
1382 void LaTeXFeatures::showStruct() const
1384 lyxerr << "LyX needs the following commands when LaTeXing:"
1385 << "\n***** Packages:" << getPackages()
1386 << "\n***** Macros:" << to_utf8(getMacros())
1387 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1388 << "\n***** done." << endl;
1392 Buffer const & LaTeXFeatures::buffer() const
1398 void LaTeXFeatures::setBuffer(Buffer const & buffer)
1404 BufferParams const & LaTeXFeatures::bufferParams() const
1410 void LaTeXFeatures::getFloatDefinitions(odocstream & os) const
1412 FloatList const & floats = params_.documentClass().floats();
1414 // Here we will output the code to create the needed float styles.
1415 // We will try to do this as minimal as possible.
1416 // \floatstyle{ruled}
1417 // \newfloat{algorithm}{htbp}{loa}
1418 // \providecommand{\algorithmname}{Algorithm}
1419 // \floatname{algorithm}{\protect\algorithmname}
1420 UsedFloats::const_iterator cit = usedFloats_.begin();
1421 UsedFloats::const_iterator end = usedFloats_.end();
1422 for (; cit != end; ++cit) {
1423 Floating const & fl = floats.getType(cit->first);
1425 // For builtin floats we do nothing.
1426 if (fl.isPredefined())
1429 // We have to special case "table" and "figure"
1430 if (fl.floattype() == "tabular" || fl.floattype() == "figure") {
1431 // Output code to modify "table" or "figure"
1432 // but only if builtin == false
1433 // and that have to be true at this point in the
1435 docstring const type = from_ascii(fl.floattype());
1436 docstring const placement = from_ascii(fl.placement());
1437 docstring const style = from_ascii(fl.style());
1438 if (!style.empty()) {
1439 os << "\\floatstyle{" << style << "}\n"
1440 << "\\restylefloat{" << type << "}\n";
1442 if (!placement.empty()) {
1443 os << "\\floatplacement{" << type << "}{"
1444 << placement << "}\n";
1447 // The other non builtin floats.
1449 docstring const type = from_ascii(fl.floattype());
1450 docstring const placement = from_ascii(fl.placement());
1451 docstring const ext = from_ascii(fl.ext());
1452 docstring const within = from_ascii(fl.within());
1453 docstring const style = from_ascii(fl.style());
1454 docstring const name =
1455 buffer().language()->translateLayout(fl.name());
1456 os << "\\floatstyle{" << style << "}\n"
1457 << "\\newfloat{" << type << "}{" << placement
1458 << "}{" << ext << '}';
1459 if (!within.empty())
1460 os << '[' << within << ']';
1462 << "\\providecommand{\\" << type << "name}{"
1464 << "\\floatname{" << type << "}{\\protect\\"
1465 << type << "name}\n";
1467 // What missing here is to code to minimalize the code
1468 // output so that the same floatstyle will not be
1469 // used several times, when the same style is still in
1473 os << "\n\\newsubfloat{" << from_ascii(fl.floattype()) << "}\n";
1478 void LaTeXFeatures::resolveAlternatives()
1480 for (Features::iterator it = features_.begin(); it != features_.end();) {
1481 if (contains(*it, '|')) {
1482 vector<string> const alternatives = getVectorFromString(*it, "|");
1483 vector<string>::const_iterator const end = alternatives.end();
1484 vector<string>::const_iterator ita = alternatives.begin();
1485 for (; ita != end; ++ita) {
1486 if (isRequired(*ita))
1490 require(alternatives.front());
1491 features_.erase(it);
1492 it = features_.begin();