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 "LaTeXFonts.h"
28 #include "LaTeXPackages.h"
32 #include "TextClass.h"
34 #include "texstream.h"
36 #include "insets/InsetLayout.h"
38 #include "support/debug.h"
39 #include "support/docstream.h"
40 #include "support/FileName.h"
41 #include "support/filetools.h"
42 #include "support/gettext.h"
43 #include "support/lstrings.h"
44 #include "support/regex.h"
50 using namespace lyx::support;
55 /////////////////////////////////////////////////////////////////////
59 /////////////////////////////////////////////////////////////////////
61 //\NeedsTeXFormat{LaTeX2e}
62 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
63 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
65 static docstring const lyx_def = from_ascii(
66 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
68 static docstring const lyx_rtl_def = from_ascii(
70 "\\def\\LyX{\\@ensure@LTR{\\@@LyX}}");
72 static docstring const lyx_hyperref_def = from_ascii(
73 "\\providecommand{\\LyX}{\\texorpdfstring%\n"
74 " {L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}\n"
77 static docstring const noun_def = from_ascii(
78 "\\newcommand{\\noun}[1]{\\textsc{#1}}");
80 static docstring const lyxarrow_def = from_ascii(
81 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
83 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
84 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
86 // ZERO WIDTH SPACE (ZWSP) is actually not a space character
87 // but marks a line break opportunity. Several commands provide a
88 // line break opportunity. They differ in side-effects:
89 // \allowbreak prevents hyphenation after hyphen or dash + ZWSP
90 // \linebreak[<n>] takes an optional argument denoting "urgency".
91 // The \LyXZeroWidthSpace wrapper allows customization in the preamble.
92 static docstring const lyxZWSP_def = from_ascii(
93 "\\newcommand*\\LyXZeroWidthSpace{\\hspace{0pt}}");
95 // for quotes without babel. This does not give perfect results, but
96 // anybody serious about non-english quotes should use babel (JMarc).
98 static docstring const quotedblbase_def = from_ascii(
99 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
100 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
101 " \\penalty10000\\hskip0em\\relax%\n"
104 static docstring const quotesinglbase_def = from_ascii(
105 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
106 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
107 " \\penalty10000\\hskip0em\\relax%\n"
110 static docstring const guillemotleft_def = from_ascii(
111 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
112 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
113 "\\penalty10000\\hskip0pt\\relax%\n"
116 static docstring const guillemotright_def = from_ascii(
117 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
118 " \\penalty10000\\hskip0pt%\n"
119 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
122 static docstring const guilsinglleft_def = from_ascii(
123 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
124 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
125 " \\penalty10000\\hskip0pt\\relax%\n"
128 static docstring const guilsinglright_def = from_ascii(
129 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
130 " \\penalty10000\\hskip0pt%\n"
131 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
134 static docstring const textquotedbl_def = from_ascii(
135 "\\DeclareTextSymbolDefault{\\textquotedbl}{T1}");
137 static docstring const textquotedblp_xetex_def = from_ascii(
138 "\\providecommand\\textquotedblplain{%\n"
139 " \\bgroup\\addfontfeatures{Mapping=}\\char34\\egroup}");
141 static docstring const textquotedblp_luatex_def = from_ascii(
142 "\\providecommand\\textquotedblplain{%\n"
143 " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\char34\\egroup}");
145 static docstring const textquotesinglep_xetex_def = from_ascii(
146 "\\providecommand\\textquotesingleplain{%\n"
147 " \\bgroup\\addfontfeatures{Mapping=}\\char39\\egroup}");
149 static docstring const textquotesinglep_luatex_def = from_ascii(
150 "\\providecommand\\textquotesingleplain{%\n"
151 " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\char39\\egroup}");
153 static docstring const paragraphleftindent_def = from_ascii(
154 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
156 " \\begin{list}{}{%\n"
157 " \\setlength{\\topsep}{0pt}%\n"
158 " \\addtolength{\\leftmargin}{#1}\n"
159 // ho hum, yet more things commented out with no hint as to why they
160 // weren't just removed
161 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
162 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
163 // "%% \\setlength\\listparindent\\parindent%\n"
164 // "%% \\setlength\\itemindent\\parindent%\n"
165 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
171 static docstring const floatingfootnote_def = from_ascii(
172 "%% Special footnote code from the package 'stblftnt.sty'\n"
173 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
174 "\\let\\SF@@footnote\\footnote\n"
175 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
176 " \\expandafter\\SF@@footnote\n"
178 " \\expandafter\\SF@gobble@opt\n"
181 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
182 " \\SF@gobble@twobracket\n"
185 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
186 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
187 "\\def\\SF@gobble@twobracket[#1]#2{}\n");
189 static docstring const binom_def = from_ascii(
190 "%% Binom macro for standard LaTeX users\n"
191 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
193 static docstring const mathcircumflex_def = from_ascii(
194 "%% For printing a cirumflex inside a formula\n"
195 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
197 static docstring const tabularnewline_def = from_ascii(
198 "%% Because html converters don't know tabularnewline\n"
199 "\\providecommand{\\tabularnewline}{\\\\}\n");
201 static docstring const lyxgreyedout_def = from_ascii(
202 "%% The greyedout annotation environment\n"
203 "\\newenvironment{lyxgreyedout}\n"
204 " {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n"
205 " {\\ignorespacesafterend\\egroup}\n");
207 // We want to omit the file extension for includegraphics, but this does not
208 // work when the filename contains other dots.
209 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
210 static docstring const lyxdot_def = from_ascii(
211 "%% A simple dot to overcome graphicx limitations\n"
212 "\\newcommand{\\lyxdot}{.}\n");
214 static docstring const changetracking_dvipost_def = from_ascii(
215 "%% Change tracking with dvipost\n"
217 "\\dvipost{osstart color push Red}\n"
218 "\\dvipost{osend color pop}\n"
219 "\\dvipost{cbstart color push Blue}\n"
220 "\\dvipost{cbend color pop}\n"
221 "\\DeclareRobustCommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
222 "\\DeclareRobustCommand{\\lyxdeleted}[3]{%\n"
223 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n");
225 static docstring const changetracking_xcolor_ulem_def = from_ascii(
226 "%% Change tracking with ulem\n"
227 "\\DeclareRobustCommand{\\lyxadded}[3]{{\\color{lyxadded}{}#3}}\n"
228 "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\lyxsout{#3}}}\n"
229 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
231 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
232 "%% Change tracking with ulem\n"
233 "\\DeclareRobustCommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}{}}{}#3}}\n"
234 "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\lyxsout{#3}}{}}}\n"
235 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
237 static docstring const changetracking_tikz_math_sout_def = from_ascii(
238 "%% Strike out display math with tikz\n"
239 "\\usepackage{tikz}\n"
240 "\\usetikzlibrary{calc}\n"
241 "\\newcommand{\\lyxmathsout}[1]{%\n"
242 " \\tikz[baseline=(math.base)]{\n"
243 " \\node[inner sep=0pt,outer sep=0pt](math){#1};\n"
244 " \\draw($(math.south west)+(2em,.5em)$)--($(math.north east)-(2em,.5em)$);\n"
248 static docstring const changetracking_none_def = from_ascii(
249 "\\newcommand{\\lyxadded}[3]{#3}\n"
250 "\\newcommand{\\lyxdeleted}[3]{}\n");
252 static docstring const textgreek_LGR_def = from_ascii(
253 "\\DeclareFontEncoding{LGR}{}{}\n");
254 static docstring const textgreek_def = from_ascii(
255 "\\DeclareRobustCommand{\\greektext}{%\n"
256 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
257 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n");
259 static docstring const textcyr_T2A_def = from_ascii(
260 "\\InputIfFileExists{t2aenc.def}{}{%\n"
261 " \\errmessage{File `t2aenc.def' not found: Cyrillic script not supported}}\n");
262 static docstring const textcyr_def = from_ascii(
263 "\\DeclareRobustCommand{\\cyrtext}{%\n"
264 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
265 "\\DeclareRobustCommand{\\textcyrillic}[1]{\\leavevmode{\\cyrtext #1}}\n");
267 static docstring const lyxmathsym_def = from_ascii(
268 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
269 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
271 static docstring const papersizedvi_def = from_ascii(
272 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
274 static docstring const papersizepdf_def = from_ascii(
275 "\\pdfpageheight\\paperheight\n"
276 "\\pdfpagewidth\\paperwidth\n");
278 static docstring const papersizepdflua_def = from_ascii(
279 "% Backwards compatibility for LuaTeX < 0.90\n"
280 "\\@ifundefined{pageheight}{\\let\\pageheight\\pdfpageheight}{}\n"
281 "\\@ifundefined{pagewidth}{\\let\\pagewidth\\pdfpagewidth}{}\n"
282 "\\pageheight\\paperheight\n"
283 "\\pagewidth\\paperwidth\n");
285 static docstring const cedilla_def = from_ascii(
286 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
287 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
289 static docstring const subring_def = from_ascii(
290 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
291 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
293 static docstring const subdot_def = from_ascii(
294 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
295 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
297 static docstring const subhat_def = from_ascii(
298 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
299 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
301 static docstring const subtilde_def = from_ascii(
302 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
303 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
305 static docstring const dacute_def = from_ascii(
306 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
308 static docstring const tipasymb_def = from_ascii(
309 "\\DeclareFontEncoding{T3}{}{}\n"
310 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
312 static docstring const dgrave_def = from_ascii(
313 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
315 static docstring const rcap_def = from_ascii(
316 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
318 static docstring const ogonek_def = from_ascii(
319 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
320 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
321 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
322 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
323 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
325 static docstring const lyxaccent_def = from_ascii(
326 "%% custom text accent \\LyxTextAccent[<rise value (length)>]{<accent>}{<base>}\n"
327 "\\newcommand*{\\LyxTextAccent}[3][0ex]{%\n"
328 " \\hmode@bgroup\\ooalign{\\null#3\\crcr\\hidewidth\n"
329 " \\raise#1\\hbox{#2}\\hidewidth}\\egroup}\n"
330 "%% select a font size smaller than the current font size:\n"
331 "\\newcommand{\\LyxAccentSize}[1][\\sf@size]{%\n"
332 " \\check@mathfonts\\fontsize#1\\z@\\math@fontsfalse\\selectfont\n"
335 static docstring const textcommabelow_def = from_ascii(
336 "\\ProvideTextCommandDefault{\\textcommabelow}[1]{%%\n"
337 " \\LyxTextAccent[-.31ex]{\\LyxAccentSize,}{#1}}\n");
339 static docstring const textcommaabove_def = from_ascii(
340 "\\ProvideTextCommandDefault{\\textcommaabove}[1]{%%\n"
341 " \\LyxTextAccent[.5ex]{\\LyxAccentSize`}{#1}}\n");
343 static docstring const textcommaaboveright_def = from_ascii(
344 "\\ProvideTextCommandDefault{\\textcommaaboveright}[1]{%%\n"
345 " \\LyxTextAccent[.5ex]{\\LyxAccentSize\\ '}{#1}}\n");
347 // Baltic languages use a comma-accent instead of a cedilla
348 static docstring const textbaltic_def = from_ascii(
349 "%% use comma accent instead of cedilla for these characters:\n"
350 "\\DeclareTextCompositeCommand{\\c}{T1}{g}{\\textcommaabove{g}}\n"
351 "\\DeclareTextCompositeCommand{\\c}{T1}{G}{\\textcommabelow{G}}\n"
352 "\\DeclareTextCompositeCommand{\\c}{T1}{k}{\\textcommabelow{k}}\n"
353 "\\DeclareTextCompositeCommand{\\c}{T1}{K}{\\textcommabelow{K}}\n"
354 "\\DeclareTextCompositeCommand{\\c}{T1}{l}{\\textcommabelow{l}}\n"
355 "\\DeclareTextCompositeCommand{\\c}{T1}{L}{\\textcommabelow{L}}\n"
356 "\\DeclareTextCompositeCommand{\\c}{T1}{n}{\\textcommabelow{n}}\n"
357 "\\DeclareTextCompositeCommand{\\c}{T1}{N}{\\textcommabelow{N}}\n"
358 "\\DeclareTextCompositeCommand{\\c}{T1}{r}{\\textcommabelow{r}}\n"
359 "\\DeclareTextCompositeCommand{\\c}{T1}{R}{\\textcommabelow{R}}\n");
361 // split-level fractions
362 static docstring const xfrac_def = from_ascii(
363 "\\usepackage{xfrac}\n");
364 static docstring const smallLetterFrac_def = from_ascii(
365 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{default}{text}\n"
366 " {phantom=c, scale-factor=1.0, slash-left-kern=-.05em}\n"
367 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{lmr}{text}\n"
368 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
369 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{lmss}{text}\n"
370 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
371 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{cmr}{text}\n"
372 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
373 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{cmss}{text}\n"
374 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
375 "\\newcommand{\\smallLetterFrac}[2]{%\n"
376 " {\\UseCollection{xfrac}{smallLetterFrac}\\sfrac{#1}{#2}}}\n");
378 static docstring const lyxref_def = from_ascii(
379 "\\RS@ifundefined{subsecref}\n"
380 " {\\newref{subsec}{name = \\RSsectxt}}\n"
382 "\\RS@ifundefined{thmref}\n"
383 " {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
385 "\\RS@ifundefined{lemref}\n"
386 " {\\def\\RSlemtxt{lemma~}\\newref{lem}{name = \\RSlemtxt}}\n"
389 // Make sure the columns are also outputed as rtl
390 static docstring const rtloutputdblcol_def = from_ascii(
391 "\\def\\@outputdblcol{%\n"
392 " \\if@firstcolumn\n"
393 " \\global \\@firstcolumnfalse\n"
394 " \\global \\setbox\\@leftcolumn \\box\\@outputbox\n"
396 " \\global \\@firstcolumntrue\n"
397 " \\setbox\\@outputbox \\vbox {%\n"
398 " \\hb@xt@\\textwidth {%\n"
399 " \\kern\\textwidth \\kern-\\columnwidth %**\n"
400 " \\hb@xt@\\columnwidth {%\n"
401 " \\box\\@leftcolumn \\hss}%\n"
402 " \\kern-\\textwidth %**\n"
404 " {\\normalcolor\\vrule \\@width\\columnseprule}%\n"
406 " \\kern-\\textwidth %**\n"
407 " \\hb@xt@\\columnwidth {%\n"
408 " \\box\\@outputbox \\hss}%\n"
409 " \\kern-\\columnwidth \\kern\\textwidth %**\n"
412 " \\@combinedblfloats\n"
415 " \\@dblfloatplacement\n"
416 " \\@startdblcolumn\n"
417 " \\@whilesw\\if@fcolmade \\fi\n"
419 " \\@startdblcolumn}%\n"
423 "\\@mparswitchtrue\n");
425 static docstring const lyxmintcaption_def = from_ascii(
426 "\\long\\def\\lyxmintcaption[#1]#2{%\n"
427 " \\ifx#1t\\vskip\\baselineskip\\fi%\n"
428 " \\refstepcounter{listing}\\noindent%\n"
429 " \\addcontentsline{lol}{listing}%\n"
430 " {\\protect\\numberline{\\thelisting}{\\ignorespaces #2}}%\n"
431 " \\setbox\\@tempboxa\\hbox{\\listingscaption~\\thelisting: #2}%\n"
432 " \\ifdim \\wd\\@tempboxa >\\linewidth%\n"
433 " \\parbox[t]{\\linewidth}{\\unhbox\\@tempboxa}\\else%\n"
434 " \\hbox to\\linewidth{\\hfil\\box\\@tempboxa\\hfil}\\fi%\n"
435 " \\ifx#1b\\vskip\\baselineskip\\fi\n"
439 /////////////////////////////////////////////////////////////////////
443 /////////////////////////////////////////////////////////////////////
445 static docstring const lyxnoun_style = from_ascii(
447 " font-variant: small-caps;\n"
451 // this is how it normally renders, but it might not always do so.
452 static docstring const lyxstrikeout_style = from_ascii(
454 " text-decoration: line-through;\n"
458 /////////////////////////////////////////////////////////////////////
462 /////////////////////////////////////////////////////////////////////
465 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
466 OutputParams const & r)
467 : buffer_(&b), params_(p), runparams_(r), in_float_(false),
468 in_deleted_inset_(false)
472 LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
474 string const local_lp = bufferParams().lang_package;
476 // Locally, custom is just stored as a string
477 // in bufferParams().lang_package.
478 if (local_lp != "auto"
479 && local_lp != "babel"
480 && local_lp != "default"
481 && local_lp != "none")
482 return LANG_PACK_CUSTOM;
484 if (local_lp == "none")
485 return LANG_PACK_NONE;
487 /* If "auto" is selected, we load polyglossia with non-TeX fonts,
488 * else we select babel.
489 * If babel is selected (either directly or via the "auto"
490 * mechanism), we really do only require it if we have
491 * a language that needs it.
493 bool const polyglossia_required =
494 params_.useNonTeXFonts
495 && isAvailable("polyglossia")
496 && !isProvided("babel")
497 && this->hasOnlyPolyglossiaLanguages();
498 bool const babel_required =
499 !bufferParams().language->babel().empty()
500 || !this->getBabelLanguages().empty();
502 if (local_lp == "auto") {
503 // polyglossia requirement has priority over babel
504 if (polyglossia_required)
505 return LANG_PACK_POLYGLOSSIA;
506 else if (babel_required)
507 return LANG_PACK_BABEL;
510 if (local_lp == "babel") {
512 return LANG_PACK_BABEL;
515 if (local_lp == "default") {
516 switch (lyxrc.language_package_selection) {
518 // polyglossia requirement has priority over babel
519 if (polyglossia_required)
520 return LANG_PACK_POLYGLOSSIA;
521 else if (babel_required)
522 return LANG_PACK_BABEL;
524 case LyXRC::LP_BABEL:
526 return LANG_PACK_BABEL;
528 case LyXRC::LP_CUSTOM:
529 return LANG_PACK_CUSTOM;
531 return LANG_PACK_NONE;
535 return LANG_PACK_NONE;
539 void LaTeXFeatures::require(string const & name)
541 features_.insert(name);
545 void LaTeXFeatures::require(set<string> const & names)
547 features_.insert(names.begin(), names.end());
551 void LaTeXFeatures::provide(string const & name)
553 provides_.insert(name);
557 void LaTeXFeatures::useLayout(docstring const & layoutname)
559 useLayout(layoutname, 0);
563 void LaTeXFeatures::useLayout(docstring const & layoutname, int level)
565 // Some code to avoid loops in dependency definition
566 const int maxlevel = 30;
567 if (level > maxlevel) {
568 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
569 << "recursion attained by layout "
570 << to_utf8(layoutname) << endl;
574 DocumentClass const & tclass = params_.documentClass();
575 if (tclass.hasLayout(layoutname)) {
576 // Is this layout already in usedLayouts?
577 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
578 != usedLayouts_.end())
581 Layout const & layout = tclass[layoutname];
582 require(layout.requires());
584 if (!layout.depends_on().empty()) {
585 useLayout(layout.depends_on(), level + 1);
587 usedLayouts_.push_back(layoutname);
589 lyxerr << "LaTeXFeatures::useLayout: layout `"
590 << to_utf8(layoutname) << "' does not exist in this class"
596 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
598 docstring const & lname = lay.name();
599 DocumentClass const & tclass = params_.documentClass();
601 // this is a default inset layout, nothing useful here
602 if (!tclass.hasInsetLayout(lname))
604 // Is this layout already in usedInsetLayouts?
605 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
606 != usedInsetLayouts_.end())
609 require(lay.requires());
610 usedInsetLayouts_.push_back(lname);
614 bool LaTeXFeatures::isRequired(string const & name) const
616 return features_.find(name) != features_.end();
620 bool LaTeXFeatures::isProvided(string const & name) const
622 // Currently, this is only features provided by babel languages
623 // (such as textgreek)
624 if (provides_.find(name) != provides_.end())
627 if (params_.useNonTeXFonts)
628 return params_.documentClass().provides(name);
630 bool const ot1 = (params_.main_font_encoding() == "default"
631 || params_.main_font_encoding() == "OT1");
632 bool const complete = (params_.fontsSans() == "default"
633 && params_.fontsTypewriter() == "default");
634 bool const nomath = (params_.fontsMath() == "default");
635 return params_.documentClass().provides(name)
636 || theLaTeXFonts().getLaTeXFont(
637 from_ascii(params_.fontsRoman())).provides(name, ot1,
640 || theLaTeXFonts().getLaTeXFont(
641 from_ascii(params_.fontsSans())).provides(name, ot1,
644 || theLaTeXFonts().getLaTeXFont(
645 from_ascii(params_.fontsTypewriter())).provides(name, ot1,
648 || theLaTeXFonts().getLaTeXFont(
649 from_ascii(params_.fontsMath())).provides(name, ot1,
655 bool LaTeXFeatures::mustProvide(string const & name) const
657 return isRequired(name) && !isProvided(name);
661 bool LaTeXFeatures::isAvailable(string const & name)
663 string::size_type const i = name.find("->");
664 if (i != string::npos) {
665 string const from = name.substr(0,i);
666 string const to = name.substr(i+2);
667 //LYXERR0("from=[" << from << "] to=[" << to << "]");
668 return theConverters().isReachable(from, to);
670 return LaTeXPackages::isAvailable(name);
676 void addSnippet(std::list<TexString> & list, TexString ts, bool allow_dupes)
679 // test the absense of duplicates, i.e. elements with same str
680 none_of(list.begin(), list.end(), [&](TexString const & ts2){
681 return ts.str == ts2.str;
684 list.push_back(move(ts));
688 TexString getSnippets(std::list<TexString> const & list)
690 otexstringstream snip;
691 for (TexString const & ts : list)
692 snip << TexString(ts) << '\n';
693 return snip.release();
699 void LaTeXFeatures::addPreambleSnippet(TexString ts, bool allow_dupes)
701 addSnippet(preamble_snippets_, move(ts), allow_dupes);
705 void LaTeXFeatures::addPreambleSnippet(docstring const & str, bool allow_dupes)
707 addSnippet(preamble_snippets_, TexString(str), allow_dupes);
711 void LaTeXFeatures::addCSSSnippet(std::string const & snippet)
713 addSnippet(css_snippets_, TexString(from_ascii(snippet)), false);
717 TexString LaTeXFeatures::getPreambleSnippets() const
719 return getSnippets(preamble_snippets_);
723 docstring LaTeXFeatures::getCSSSnippets() const
725 return getSnippets(css_snippets_).str;
730 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
732 if (!usedFloats_[name])
733 usedFloats_[name] = subfloat;
736 // We only need float.sty if we use non builtin floats, or if we
737 // use the "H" modifier. This includes modified table and
738 // figure floats. (Lgb)
739 Floating const & fl = params_.documentClass().floats().getType(name);
740 if (!fl.floattype().empty() && fl.usesFloatPkg()) {
746 void LaTeXFeatures::useLanguage(Language const * lang)
748 if (!lang->babel().empty() || !lang->polyglossia().empty())
749 UsedLanguages_.insert(lang);
750 if (!lang->requires().empty())
751 require(lang->requires());
752 // currently only supported for Babel
753 if (!lang->provides().empty() && useBabel())
754 provide(lang->provides());
755 // CJK languages do not have a babel name.
756 // They use the CJK package
757 if (lang->encoding()->package() == Encoding::CJK)
759 // japanese package is special
760 if (lang->encoding()->package() == Encoding::japanese)
765 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
767 IncludedFiles_[key] = name;
771 bool LaTeXFeatures::hasLanguages() const
773 return !UsedLanguages_.empty();
777 bool LaTeXFeatures::hasOnlyPolyglossiaLanguages() const
779 // first the main language
780 if (params_.language->polyglossia().empty())
782 // now the secondary languages
783 LanguageList::const_iterator const begin = UsedLanguages_.begin();
784 for (LanguageList::const_iterator cit = begin;
785 cit != UsedLanguages_.end();
787 if ((*cit)->polyglossia().empty())
794 bool LaTeXFeatures::hasPolyglossiaExclusiveLanguages() const
796 // first the main language
797 if (params_.language->isPolyglossiaExclusive())
799 // now the secondary languages
800 LanguageList::const_iterator const begin = UsedLanguages_.begin();
801 for (LanguageList::const_iterator cit = begin;
802 cit != UsedLanguages_.end();
804 if ((*cit)->isPolyglossiaExclusive())
811 vector<string> LaTeXFeatures::getPolyglossiaExclusiveLanguages() const
813 vector<string> result;
814 // first the main language
815 if (params_.language->isPolyglossiaExclusive())
816 result.push_back(params_.language->display());
817 // now the secondary languages
818 LanguageList::const_iterator const begin = UsedLanguages_.begin();
819 for (LanguageList::const_iterator cit = begin;
820 cit != UsedLanguages_.end();
822 if ((*cit)->isPolyglossiaExclusive())
823 result.push_back((*cit)->display());
829 vector<string> LaTeXFeatures::getBabelExclusiveLanguages() const
831 vector<string> result;
832 // first the main language
833 if (params_.language->isBabelExclusive())
834 result.push_back(params_.language->display());
835 // now the secondary languages
836 LanguageList::const_iterator const begin = UsedLanguages_.begin();
837 for (LanguageList::const_iterator cit = begin;
838 cit != UsedLanguages_.end();
840 if ((*cit)->isBabelExclusive())
841 result.push_back((*cit)->display());
847 string LaTeXFeatures::getBabelLanguages() const
852 LanguageList::const_iterator const begin = UsedLanguages_.begin();
853 for (LanguageList::const_iterator cit = begin;
854 cit != UsedLanguages_.end();
856 if ((*cit)->babel().empty())
862 langs << (*cit)->babel();
868 set<string> LaTeXFeatures::getPolyglossiaLanguages() const
872 LanguageList::const_iterator const begin = UsedLanguages_.begin();
873 for (LanguageList::const_iterator cit = begin;
874 cit != UsedLanguages_.end();
876 // We do not need the variants here
877 langs.insert((*cit)->polyglossia());
883 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
885 // This does only find encodings of languages supported by babel, but
886 // that does not matter since we don't have a language with an
887 // encoding supported by inputenc but without babel support.
889 for (auto const & lang : UsedLanguages_)
890 if (lang->encoding()->latexName() != doc_encoding &&
891 (lang->encoding()->package() == Encoding::inputenc
892 || lang->encoding()->package() == Encoding::japanese))
893 encs.insert(lang->encoding()->latexName());
898 void LaTeXFeatures::getFontEncodings(vector<string> & encs, bool const onlylangs) const
901 // these must be loaded if glyphs of this script are used
902 // unless a language providing them is used in the document
903 if (mustProvide("textgreek")
904 && find(encs.begin(), encs.end(), "LGR") == encs.end())
905 encs.insert(encs.begin(), "LGR");
906 if (mustProvide("textcyrillic")
907 && find(encs.begin(), encs.end(), "T2A") == encs.end())
908 encs.insert(encs.begin(), "T2A");
911 for (auto const & lang : UsedLanguages_) {
912 vector<string> extraencs =
913 getVectorFromString(lang->fontenc(buffer().masterParams()));
914 for (auto const & extra : extraencs) {
915 if (extra != "none" && find(encs.begin(), encs.end(), extra) == encs.end())
916 encs.insert(encs.begin(), extra);
922 bool LaTeXFeatures::hasRTLLanguage() const
924 if (params_.language->rightToLeft())
926 for (auto const & lang : UsedLanguages_)
927 if (lang->rightToLeft())
934 char const * simplefeatures[] = {
935 // note that the package order here will be the same in the LaTeX-output
943 // subfig is handled in BufferParams.cpp
947 /*For a successful cooperation of the `wrapfig' package with the
948 `float' package you should load the `wrapfig' package *after*
949 the `float' package. See the caption package documentation
980 // listings is handled in BufferParams.cpp
1005 char const * bibliofeatures[] = {
1006 // Known bibliography packages (will be loaded before natbib)
1022 int const nb_bibliofeatures = sizeof(bibliofeatures) / sizeof(char const *);
1024 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
1029 string const LaTeXFeatures::getColorOptions() const
1031 ostringstream colors;
1033 // Handling the color packages separately is needed to be able to load them
1034 // before babel when hyperref is loaded with the colorlinks option
1035 // for more info see Bufferparams.cpp
1038 if (mustProvide("color") || mustProvide("xcolor")) {
1039 string const package =
1040 (mustProvide("xcolor") ? "xcolor" : "color");
1041 if (params_.graphics_driver == "default"
1042 || params_.graphics_driver == "none")
1043 colors << "\\usepackage{" << package << "}\n";
1045 colors << "\\usepackage["
1046 << params_.graphics_driver
1047 << "]{" << package << "}\n";
1050 // pdfcolmk must be loaded after color
1051 if (mustProvide("pdfcolmk"))
1052 colors << "\\usepackage{pdfcolmk}\n";
1054 // the following 3 color commands must be set after color
1055 // is loaded and before pdfpages, therefore add the command
1056 // here define the set color
1057 if (mustProvide("pagecolor")) {
1058 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
1059 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
1060 // set the page color
1061 colors << "\\pagecolor{page_backgroundcolor}\n";
1064 if (mustProvide("fontcolor")) {
1065 colors << "\\definecolor{document_fontcolor}{rgb}{";
1066 colors << outputLaTeXColor(params_.fontcolor) << "}\n";
1068 colors << "\\color{document_fontcolor}\n";
1071 if (mustProvide("lyxgreyedout")) {
1072 colors << "\\definecolor{note_fontcolor}{rgb}{";
1073 colors << outputLaTeXColor(params_.notefontcolor) << "}\n";
1074 // the color will be set together with the definition of
1075 // the lyxgreyedout environment (see lyxgreyedout_def)
1078 // color for shaded boxes
1079 if (isRequired("framed") && mustProvide("color")) {
1080 colors << "\\definecolor{shadecolor}{rgb}{";
1081 colors << outputLaTeXColor(params_.boxbgcolor) << "}\n";
1082 // this color is automatically used by the LaTeX-package "framed"
1085 return colors.str();
1089 string const LaTeXFeatures::getPackageOptions() const
1091 ostringstream packageopts;
1092 // Output all the package option stuff we have been asked to do.
1093 map<string, string>::const_iterator it =
1094 params_.documentClass().packageOptions().begin();
1095 map<string, string>::const_iterator en =
1096 params_.documentClass().packageOptions().end();
1097 for (; it != en; ++it)
1098 if (mustProvide(it->first))
1099 packageopts << "\\PassOptionsToPackage{" << it->second << "}"
1100 << "{" << it->first << "}\n";
1101 return packageopts.str();
1105 string const LaTeXFeatures::getPackages() const
1107 ostringstream packages;
1109 // FIXME: currently, we can only load packages and macros known
1111 // However, with the Require tag of layouts/custom insets,
1112 // also unknown packages can be requested. They are silently
1113 // swallowed now. We should change this eventually.
1115 // These are all the 'simple' includes. i.e
1116 // packages which we just \usepackage{package}
1117 for (int i = 0; i < nb_simplefeatures; ++i) {
1118 if (mustProvide(simplefeatures[i]))
1119 packages << "\\usepackage{" << simplefeatures[i] << "}\n";
1122 // The rest of these packages are somewhat more complicated
1123 // than those above.
1125 if (mustProvide("footnote")) {
1126 if (isRequired("hyperref"))
1127 packages << "\\usepackage{footnotehyper}\n";
1129 packages << "\\usepackage{footnote}\n";
1132 // [pdf]lscape is used to rotate longtables
1133 if (mustProvide("lscape")) {
1134 if (runparams_.flavor == OutputParams::LATEX
1135 || runparams_.flavor == OutputParams::DVILUATEX)
1136 packages << "\\usepackage{lscape}\n";
1138 packages << "\\usepackage{pdflscape}\n";
1141 // The tipa package and its extensions (tipx, tone) must not
1142 // be loaded with non-TeX fonts, since fontspec includes the
1143 // respective macros
1144 if (mustProvide("tipa") && !params_.useNonTeXFonts)
1145 packages << "\\usepackage{tipa}\n";
1146 if (mustProvide("tipx") && !params_.useNonTeXFonts)
1147 packages << "\\usepackage{tipx}\n";
1148 if (mustProvide("extraipa") && !params_.useNonTeXFonts)
1149 packages << "\\usepackage{extraipa}\n";
1150 if (mustProvide("tone") && !params_.useNonTeXFonts)
1151 packages << "\\usepackage{tone}\n";
1153 // if fontspec or newtxmath is used, AMS packages have to be loaded
1154 // before fontspec (in BufferParams)
1155 string const amsPackages = loadAMSPackages();
1156 bool const ot1 = (params_.main_font_encoding() == "default"
1157 || params_.main_font_encoding() == "OT1");
1158 bool const use_newtxmath =
1159 theLaTeXFonts().getLaTeXFont(from_ascii(params_.fontsMath())).getUsedPackage(
1160 ot1, false, false) == "newtxmath";
1162 if (!params_.useNonTeXFonts && !use_newtxmath && !amsPackages.empty())
1163 packages << amsPackages;
1165 if (mustProvide("cancel") &&
1166 params_.use_package("cancel") != BufferParams::package_off)
1167 packages << "\\usepackage{cancel}\n";
1169 // marvosym and bbding both define the \Cross macro
1170 if (mustProvide("marvosym")) {
1171 if (mustProvide("bbding"))
1172 packages << "\\let\\Cross\\relax\n";
1173 packages << "\\usepackage{marvosym}\n";
1176 // accents must be loaded after amsmath
1177 if (mustProvide("accents") &&
1178 params_.use_package("accents") != BufferParams::package_off)
1179 packages << "\\usepackage{accents}\n";
1181 // mathdots must be loaded after amsmath
1182 if (mustProvide("mathdots") &&
1183 params_.use_package("mathdots") != BufferParams::package_off)
1184 packages << "\\usepackage{mathdots}\n";
1186 // yhmath must be loaded after amsmath
1187 if (mustProvide("yhmath") &&
1188 params_.use_package("yhmath") != BufferParams::package_off)
1189 packages << "\\usepackage{yhmath}\n";
1191 // stmaryrd must be loaded after amsmath
1192 if (mustProvide("stmaryrd") &&
1193 params_.use_package("stmaryrd") != BufferParams::package_off)
1194 packages << "\\usepackage{stmaryrd}\n";
1196 if (mustProvide("stackrel") &&
1197 params_.use_package("stackrel") != BufferParams::package_off)
1198 packages << "\\usepackage{stackrel}\n";
1200 if (mustProvide("undertilde") &&
1201 params_.use_package("undertilde") != BufferParams::package_off)
1202 packages << "\\usepackage{undertilde}\n";
1204 // [x]color and pdfcolmk are handled in getColorOptions() above
1207 if (isRequired("makeidx") || isRequired("splitidx")) {
1208 if (!isProvided("makeidx") && !isRequired("splitidx"))
1209 packages << "\\usepackage{makeidx}\n";
1210 if (mustProvide("splitidx"))
1211 packages << "\\usepackage{splitidx}\n";
1212 packages << "\\makeindex\n";
1216 if (mustProvide("graphicx") && params_.graphics_driver != "none") {
1217 if (params_.graphics_driver == "default")
1218 packages << "\\usepackage{graphicx}\n";
1220 packages << "\\usepackage["
1221 << params_.graphics_driver
1225 // lyxskak.sty --- newer chess support based on skak.sty
1226 if (mustProvide("chess"))
1227 packages << "\\usepackage[ps,mover]{lyxskak}\n";
1230 if (mustProvide("setspace") && !isProvided("SetSpace"))
1231 packages << "\\usepackage{setspace}\n";
1233 // we need to assure that mhchem is loaded before esint and every other
1234 // package that redefines command of amsmath because mhchem loads amlatex
1235 // (this info is from the author of mhchem from June 2013)
1236 if (mustProvide("mhchem") &&
1237 params_.use_package("mhchem") != BufferParams::package_off)
1238 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
1239 "\\usepackage{mhchem}\n";
1241 // wasysym is a simple feature, but it must be after amsmath if both
1243 // wasysym redefines some integrals (e.g. iint) from amsmath. That
1244 // leads to inconsistent integrals. We only load this package if
1245 // the document does not contain integrals (then isRequired("esint")
1246 // is false) or if esint is used, since esint redefines all relevant
1247 // integral symbols from wasysym and amsmath.
1248 // See http://www.lyx.org/trac/ticket/1942
1249 if (mustProvide("wasysym") &&
1250 params_.use_package("wasysym") != BufferParams::package_off &&
1251 (params_.use_package("esint") != BufferParams::package_off || !isRequired("esint")))
1252 packages << "\\usepackage{wasysym}\n";
1254 // esint must be after amsmath (and packages requiring amsmath, like mhchem)
1255 // and wasysym, since it will redeclare inconsistent integral symbols
1256 if (mustProvide("esint") &&
1257 params_.use_package("esint") != BufferParams::package_off)
1258 packages << "\\usepackage{esint}\n";
1260 // Known bibliography packages (simple \usepackage{package})
1261 for (int i = 0; i < nb_bibliofeatures; ++i) {
1262 if (mustProvide(bibliofeatures[i]))
1263 packages << "\\usepackage{"
1264 << bibliofeatures[i] << "}\n";
1267 // Compatibility between achicago and natbib
1268 if (mustProvide("achicago") && mustProvide("natbib"))
1269 packages << "\\let\\achicagobib\\thebibliography\n";
1272 // Some classes load natbib themselves, but still allow (or even require)
1273 // plain numeric citations (ReVTeX is such a case, see bug 5182).
1274 // This special case is indicated by the "natbib-internal" key.
1275 if (mustProvide("natbib")
1276 && !isProvided("natbib-internal")
1277 && !isProvided("biblatex")
1278 && !isProvided("biblatex-natbib")
1279 && !isProvided("jurabib")) {
1280 packages << "\\usepackage[";
1281 if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
1282 packages << "numbers";
1284 packages << "authoryear";
1285 if (!params_.biblio_opts.empty())
1286 packages << ',' << params_.biblio_opts;
1287 packages << "]{natbib}\n";
1290 // Compatibility between achicago and natbib
1291 if (mustProvide("achicago") && mustProvide("natbib")) {
1292 packages << "\\let\\thebibliography\\achicagobib\n";
1293 packages << "\\let\\SCcite\\astroncite\n";
1294 packages << "\\let\\UnexpandableProtect\\protect\n";
1297 // jurabib -- we need version 0.6 at least.
1298 if (mustProvide("jurabib")
1299 && !isProvided("natbib-internal")
1300 && !isProvided("natbib")
1301 && !isProvided("biblatex")
1302 && !isProvided("biblatex-natbib")) {
1303 packages << "\\usepackage";
1304 if (!params_.biblio_opts.empty())
1305 packages << '[' << params_.biblio_opts << ']';
1306 packages << "{jurabib}[2004/01/25]\n";
1309 // opcit -- we pass custombst as we output \bibliographystyle ourselves
1310 if (mustProvide("opcit")) {
1311 if (isRequired("hyperref"))
1312 packages << "\\usepackage[custombst,hyperref]{opcit}\n";
1314 packages << "\\usepackage[custombst]{opcit}\n";
1317 // xargs -- we need version 1.09 at least
1318 if (mustProvide("xargs"))
1319 packages << "\\usepackage{xargs}[2008/03/08]\n";
1321 if (mustProvide("xy"))
1322 packages << "\\usepackage[all]{xy}\n";
1324 if (mustProvide("feyn"))
1325 packages << "\\usepackage{feyn}\n"; //Diagram
1327 if (mustProvide("ulem"))
1328 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
1329 "\\usepackage{ulem}\n";
1331 if (mustProvide("nomencl")) {
1332 // Make it work with the new and old version of the package,
1333 // but don't use the compatibility option since it is
1334 // incompatible to other packages.
1335 packages << "\\usepackage{nomencl}\n"
1336 "% the following is useful when we have the old nomencl.sty package\n"
1337 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
1338 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
1339 "\\makenomenclature\n";
1342 // fixltx2e provides subscript
1343 if (mustProvide("subscript") && !isRequired("fixltx2e"))
1344 packages << "\\usepackage{subscript}\n";
1346 // footmisc must be loaded after setspace
1347 // Set options here, load the package after the user preamble to
1348 // avoid problems with manual loaded footmisc.
1349 if (mustProvide("footmisc"))
1350 packages << "\\PassOptionsToPackage{stable}{footmisc}\n";
1352 if (mustProvide("microtype")){
1353 packages << "\\usepackage{microtype}\n";
1356 return packages.str();
1360 TexString LaTeXFeatures::getMacros() const
1362 otexstringstream macros;
1364 if (!preamble_snippets_.empty()) {
1366 macros << getPreambleSnippets();
1369 if (mustProvide("xetexdashbreakstate"))
1370 macros << "\\XeTeXdashbreakstate 0" << '\n';
1372 if (mustProvide("papersize")) {
1373 if (runparams_.flavor == OutputParams::LATEX
1374 || runparams_.flavor == OutputParams::DVILUATEX)
1375 macros << papersizedvi_def << '\n';
1376 else if (runparams_.flavor == OutputParams::LUATEX)
1377 macros << papersizepdflua_def << '\n';
1379 macros << papersizepdf_def << '\n';
1382 if (mustProvide("LyX")) {
1383 if (isRequired("hyperref"))
1384 macros << lyx_hyperref_def << '\n';
1386 macros << lyx_def << '\n';
1387 if (runparams_.use_polyglossia && hasRTLLanguage())
1388 macros << lyx_rtl_def << '\n';
1391 if (mustProvide("noun"))
1392 macros << noun_def << '\n';
1394 if (mustProvide("lyxarrow"))
1395 macros << lyxarrow_def << '\n';
1397 if (mustProvide("lyxzerowidthspace"))
1398 macros << lyxZWSP_def << '\n';
1400 if (!usePolyglossia() && mustProvide("textgreek")) {
1401 // ensure LGR font encoding is defined also if fontenc is not loaded by LyX
1402 if (params_.main_font_encoding() == "default")
1403 macros << textgreek_LGR_def;
1404 macros << textgreek_def << '\n';
1407 if (!usePolyglossia() && mustProvide("textcyrillic")) {
1408 // ensure T2A font encoding is set up also if fontenc is not loaded by LyX
1409 if (params_.main_font_encoding() == "default")
1410 macros << textcyr_T2A_def;
1411 macros << textcyr_def << '\n';
1414 // non-standard text accents:
1415 if (mustProvide("textcommaabove") || mustProvide("textcommaaboveright") ||
1416 mustProvide("textcommabelow") || mustProvide("textbaltic"))
1417 macros << lyxaccent_def;
1419 if (mustProvide("textcommabelow") || mustProvide("textbaltic"))
1420 macros << textcommabelow_def << '\n';
1422 if (mustProvide("textcommaabove") || mustProvide("textbaltic"))
1423 macros << textcommaabove_def << '\n';
1425 if (mustProvide("textcommaaboveright"))
1426 macros << textcommaaboveright_def << '\n';
1428 if (mustProvide("textbaltic"))
1429 macros << textbaltic_def << '\n';
1431 // split-level fractions
1432 if (mustProvide("xfrac") || mustProvide("smallLetterFrac"))
1433 macros << xfrac_def << '\n';
1435 if (mustProvide("smallLetterFrac"))
1436 macros << smallLetterFrac_def << '\n';
1438 if (mustProvide("lyxmathsym"))
1439 macros << lyxmathsym_def << '\n';
1441 if (mustProvide("cedilla"))
1442 macros << cedilla_def << '\n';
1444 if (mustProvide("subring"))
1445 macros << subring_def << '\n';
1447 if (mustProvide("subdot"))
1448 macros << subdot_def << '\n';
1450 if (mustProvide("subhat"))
1451 macros << subhat_def << '\n';
1453 if (mustProvide("subtilde"))
1454 macros << subtilde_def << '\n';
1456 if (mustProvide("dacute"))
1457 macros << dacute_def << '\n';
1459 if (mustProvide("tipasymb"))
1460 macros << tipasymb_def << '\n';
1462 if (mustProvide("dgrave"))
1463 macros << dgrave_def << '\n';
1465 if (mustProvide("rcap"))
1466 macros << rcap_def << '\n';
1468 if (mustProvide("ogonek"))
1469 macros << ogonek_def << '\n';
1472 if (mustProvide("quotesinglbase"))
1473 macros << quotesinglbase_def << '\n';
1474 if (mustProvide("quotedblbase"))
1475 macros << quotedblbase_def << '\n';
1476 if (mustProvide("guilsinglleft"))
1477 macros << guilsinglleft_def << '\n';
1478 if (mustProvide("guilsinglright"))
1479 macros << guilsinglright_def << '\n';
1480 if (mustProvide("guillemotleft"))
1481 macros << guillemotleft_def << '\n';
1482 if (mustProvide("guillemotright"))
1483 macros << guillemotright_def << '\n';
1484 if (mustProvide("textquotedbl"))
1485 macros << textquotedbl_def << '\n';
1486 if (mustProvide("textquotesinglep")) {
1487 if (runparams_.flavor == OutputParams::XETEX)
1488 macros << textquotesinglep_xetex_def << '\n';
1490 macros << textquotesinglep_luatex_def << '\n';
1492 if (mustProvide("textquotedblp")) {
1493 if (runparams_.flavor == OutputParams::XETEX)
1494 macros << textquotedblp_xetex_def << '\n';
1496 macros << textquotedblp_luatex_def << '\n';
1500 if (mustProvide("binom") && !isRequired("amsmath"))
1501 macros << binom_def << '\n';
1502 if (mustProvide("mathcircumflex"))
1503 macros << mathcircumflex_def << '\n';
1506 if (mustProvide("ParagraphLeftIndent"))
1507 macros << paragraphleftindent_def;
1508 if (mustProvide("NeedLyXFootnoteCode"))
1509 macros << floatingfootnote_def;
1511 // some problems with tex->html converters
1512 if (mustProvide("NeedTabularnewline"))
1513 macros << tabularnewline_def;
1515 // greyed-out environment (note inset)
1516 // the color is specified in the routine
1517 // getColorOptions() to avoid LaTeX-package clashes
1518 if (mustProvide("lyxgreyedout"))
1519 macros << lyxgreyedout_def;
1521 if (mustProvide("lyxdot"))
1522 macros << lyxdot_def << '\n';
1525 getFloatDefinitions(macros);
1527 if (mustProvide("refstyle"))
1528 macros << lyxref_def << '\n';
1531 if (mustProvide("ct-dvipost"))
1532 macros << changetracking_dvipost_def;
1534 if (mustProvide("ct-xcolor-ulem")) {
1535 streamsize const prec = macros.os().precision(2);
1537 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
1538 macros << "\\providecolor{lyxadded}{rgb}{"
1539 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
1541 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
1542 macros << "\\providecolor{lyxdeleted}{rgb}{"
1543 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
1545 macros.os().precision(prec);
1547 if (isRequired("hyperref"))
1548 macros << changetracking_xcolor_ulem_hyperref_def;
1550 macros << changetracking_xcolor_ulem_def;
1553 if (mustProvide("ct-tikz-math-sout"))
1554 macros << changetracking_tikz_math_sout_def;
1556 if (mustProvide("ct-none"))
1557 macros << changetracking_none_def;
1559 if (mustProvide("rtloutputdblcol"))
1560 macros << rtloutputdblcol_def;
1562 if (mustProvide("lyxmintcaption"))
1563 macros << lyxmintcaption_def;
1565 return macros.release();
1569 docstring const LaTeXFeatures::getBabelPresettings() const
1571 odocstringstream tmp;
1573 for (Language const * lang : UsedLanguages_)
1574 if (!lang->babel_presettings().empty())
1575 tmp << lang->babel_presettings() << '\n';
1576 if (!params_.language->babel_presettings().empty())
1577 tmp << params_.language->babel_presettings() << '\n';
1579 if (!contains(tmp.str(), '@'))
1582 return "\\makeatletter\n" + tmp.str() + "\\makeatother\n";
1586 docstring const LaTeXFeatures::getBabelPostsettings() const
1588 odocstringstream tmp;
1590 for (Language const * lang : UsedLanguages_)
1591 if (!lang->babel_postsettings().empty())
1592 tmp << lang->babel_postsettings() << '\n';
1593 if (!params_.language->babel_postsettings().empty())
1594 tmp << params_.language->babel_postsettings() << '\n';
1596 if (!contains(tmp.str(), '@'))
1599 return "\\makeatletter\n" + tmp.str() + "\\makeatother\n";
1603 bool LaTeXFeatures::needBabelLangOptions() const
1605 if (!lyxrc.language_global_options || params_.language->asBabelOptions())
1608 LanguageList::const_iterator it = UsedLanguages_.begin();
1609 LanguageList::const_iterator end = UsedLanguages_.end();
1610 for (; it != end; ++it)
1611 if ((*it)->asBabelOptions())
1618 string const LaTeXFeatures::loadAMSPackages() const
1622 if (mustProvide("amsmath")
1623 && params_.use_package("amsmath") != BufferParams::package_off) {
1624 tmp << "\\usepackage{amsmath}\n";
1626 // amsbsy and amstext are already provided by amsmath
1627 if (mustProvide("amsbsy"))
1628 tmp << "\\usepackage{amsbsy}\n";
1629 if (mustProvide("amstext"))
1630 tmp << "\\usepackage{amstext}\n";
1633 if (mustProvide("amsthm"))
1634 tmp << "\\usepackage{amsthm}\n";
1636 if (mustProvide("amssymb")
1637 && params_.use_package("amssymb") != BufferParams::package_off)
1638 tmp << "\\usepackage{amssymb}\n";
1644 docstring const LaTeXFeatures::getTClassPreamble() const
1646 // the text class specific preamble
1647 DocumentClass const & tclass = params_.documentClass();
1648 odocstringstream tcpreamble;
1650 tcpreamble << tclass.preamble();
1652 list<docstring>::const_iterator cit = usedLayouts_.begin();
1653 list<docstring>::const_iterator end = usedLayouts_.end();
1654 for (; cit != end; ++cit)
1655 // For InPreamble layouts, we output the preamble stuff earlier
1656 // (before the layouts). See Paragraph::Private::validate.
1657 if (!tclass[*cit].inpreamble)
1658 tcpreamble << tclass[*cit].preamble();
1660 cit = usedInsetLayouts_.begin();
1661 end = usedInsetLayouts_.end();
1662 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1663 for (; cit != end; ++cit) {
1664 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1665 if (it == ils.end())
1667 tcpreamble << it->second.preamble();
1670 return tcpreamble.str();
1674 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
1676 DocumentClass const & tclass = params_.documentClass();
1677 odocstringstream tcpreamble;
1679 tcpreamble << tclass.htmlpreamble();
1681 list<docstring>::const_iterator cit = usedLayouts_.begin();
1682 list<docstring>::const_iterator end = usedLayouts_.end();
1683 for (; cit != end; ++cit)
1684 tcpreamble << tclass[*cit].htmlpreamble();
1686 cit = usedInsetLayouts_.begin();
1687 end = usedInsetLayouts_.end();
1688 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1689 for (; cit != end; ++cit) {
1690 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1691 if (it == ils.end())
1693 tcpreamble << it->second.htmlpreamble();
1696 return tcpreamble.str();
1700 docstring const LaTeXFeatures::getTClassHTMLStyles() const
1702 DocumentClass const & tclass = params_.documentClass();
1703 odocstringstream tcpreamble;
1705 if (mustProvide("noun"))
1706 tcpreamble << lyxnoun_style;
1707 // this isn't exact, but it won't hurt that much if it
1709 if (mustProvide("ulem"))
1710 tcpreamble << lyxstrikeout_style;
1712 tcpreamble << tclass.htmlstyles();
1714 list<docstring>::const_iterator cit = usedLayouts_.begin();
1715 list<docstring>::const_iterator end = usedLayouts_.end();
1716 for (; cit != end; ++cit)
1717 tcpreamble << tclass[*cit].htmlstyle();
1719 cit = usedInsetLayouts_.begin();
1720 end = usedInsetLayouts_.end();
1721 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1722 for (; cit != end; ++cit) {
1723 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1724 if (it == ils.end())
1726 tcpreamble << it->second.htmlstyle();
1729 return tcpreamble.str();
1735 docstring const getFloatI18nPreamble(docstring const & type,
1736 docstring const & name, Language const * lang,
1737 Encoding const & enc, bool const polyglossia)
1739 // Check whether name can be encoded in the buffer encoding
1740 bool encodable = true;
1741 for (size_t i = 0; i < name.size(); ++i) {
1742 if (!enc.encodable(name[i])) {
1748 docstring const language = polyglossia ? from_ascii(lang->polyglossia())
1749 : from_ascii(lang->babel());
1750 docstring const langenc = from_ascii(lang->encoding()->iconvName());
1751 docstring const texenc = from_ascii(lang->encoding()->latexName());
1752 docstring const bufenc = from_ascii(enc.iconvName());
1753 docstring const s1 = docstring(1, 0xF0000);
1754 docstring const s2 = docstring(1, 0xF0001);
1755 docstring const translated = encodable ? name
1756 : from_ascii("\\inputencoding{") + texenc + from_ascii("}")
1757 + s1 + langenc + s2 + name + s1 + bufenc + s2;
1759 odocstringstream os;
1760 os << "\\addto\\captions" << language
1761 << "{\\renewcommand{\\" << type << "name}{" << translated << "}}\n";
1766 docstring const i18npreamble(docstring const & templ, Language const * lang,
1767 Encoding const & enc, bool const polyglossia,
1768 bool const need_fixedwidth)
1773 string preamble = polyglossia ?
1774 subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
1775 subst(to_utf8(templ), "$$lang", lang->babel());
1777 string const langenc = lang->encoding()->iconvName();
1778 string const texenc = lang->encoding()->latexName();
1779 string const bufenc = enc.iconvName();
1780 Encoding const * testenc(&enc);
1781 bool lang_fallback = false;
1782 bool ascii_fallback = false;
1783 if (need_fixedwidth && !enc.hasFixedWidth()) {
1784 if (lang->encoding()->hasFixedWidth()) {
1785 testenc = lang->encoding();
1786 lang_fallback = true;
1788 // We need a fixed width encoding, but both the buffer
1789 // encoding and the language encoding are variable
1790 // width. As a last fallback, try to convert to pure
1791 // ASCII using the LaTeX commands defined in unicodesymbols.
1792 testenc = encodings.fromLyXName("ascii");
1795 ascii_fallback = true;
1798 // First and second character of plane 15 (Private Use Area)
1799 string const s1 = "\xf3\xb0\x80\x80"; // U+F0000
1800 string const s2 = "\xf3\xb0\x80\x81"; // U+F0001
1802 // lyx::regex is not unicode-safe.
1803 // Should use QRegExp or (boost::u32regex, but that requires ICU)
1804 static regex const reg("_\\(([^\\)]+)\\)");
1806 while (regex_search(preamble, sub, reg)) {
1807 string const key = sub.str(1);
1808 docstring const name = lang->translateLayout(key);
1809 // Check whether name can be encoded in the buffer encoding
1810 bool encodable = true;
1811 for (size_t i = 0; i < name.size() && encodable; ++i)
1812 if (!testenc->encodable(name[i]))
1815 if (encodable && !lang_fallback)
1816 translated = to_utf8(name);
1817 else if (ascii_fallback)
1818 translated = to_ascii(testenc->latexString(name).first);
1820 translated = "\\inputencoding{" + texenc + "}"
1821 + s1 + langenc + s2 + to_utf8(name)
1823 preamble = subst(preamble, sub.str(), translated);
1825 return from_utf8(preamble);
1831 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel,
1832 bool use_polyglossia, bool use_minted) const
1834 DocumentClass const & tclass = params_.documentClass();
1835 // collect preamble snippets in a set to prevent multiple identical
1836 // commands (would happen if e.g. both theorem and theorem* are used)
1837 set<docstring> snippets;
1838 typedef LanguageList::const_iterator lang_it;
1839 lang_it const lbeg = UsedLanguages_.begin();
1840 lang_it const lend = UsedLanguages_.end();
1841 list<docstring>::const_iterator cit = usedLayouts_.begin();
1842 list<docstring>::const_iterator end = usedLayouts_.end();
1843 for (; cit != end; ++cit) {
1844 // language dependent commands (once per document)
1845 snippets.insert(i18npreamble(tclass[*cit].langpreamble(),
1846 buffer().language(),
1847 buffer().params().encoding(),
1848 use_polyglossia, false));
1849 // commands for language changing (for multilanguage documents)
1850 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1851 snippets.insert(i18npreamble(
1852 tclass[*cit].babelpreamble(),
1853 buffer().language(),
1854 buffer().params().encoding(),
1855 use_polyglossia, false));
1856 for (lang_it lit = lbeg; lit != lend; ++lit)
1857 snippets.insert(i18npreamble(
1858 tclass[*cit].babelpreamble(),
1860 buffer().params().encoding(),
1861 use_polyglossia, false));
1864 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1865 FloatList const & floats = params_.documentClass().floats();
1866 UsedFloats::const_iterator fit = usedFloats_.begin();
1867 UsedFloats::const_iterator fend = usedFloats_.end();
1868 for (; fit != fend; ++fit) {
1869 Floating const & fl = floats.getType(fit->first);
1870 // we assume builtin floats are translated
1871 if (fl.isPredefined())
1873 docstring const type = from_ascii(fl.floattype());
1874 docstring const flname = from_utf8(fl.name());
1875 docstring name = buffer().language()->translateLayout(fl.name());
1876 // only request translation if we have a real translation
1877 // (that differs from the source)
1879 snippets.insert(getFloatI18nPreamble(
1880 type, name, buffer().language(),
1881 buffer().params().encoding(),
1883 for (lang_it lit = lbeg; lit != lend; ++lit) {
1884 string const code = (*lit)->code();
1885 name = (*lit)->translateLayout(fl.name());
1886 // we assume we have a suitable translation if
1887 // either the language is English (we need to
1888 // translate into English if English is a secondary
1889 // language) or if translateIfPossible returns
1890 // something different to the English source.
1891 bool const have_translation =
1892 (flname != name || contains(code, "en"));
1893 if (have_translation)
1894 snippets.insert(getFloatI18nPreamble(
1896 buffer().params().encoding(),
1902 cit = usedInsetLayouts_.begin();
1903 end = usedInsetLayouts_.end();
1904 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1905 for (; cit != end; ++cit) {
1906 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1907 if (it == ils.end())
1909 // The listings package does not work with variable width
1910 // encodings, only with fixed width encodings. Therefore we
1911 // need to force a fixed width encoding for
1912 // \lstlistlistingname and \lstlistingname (bug 9382).
1913 // This needs to be consistent with InsetListings::latex().
1914 bool const need_fixedwidth = !use_minted &&
1915 !runparams_.isFullUnicode() &&
1916 it->second.fixedwidthpreambleencoding();
1917 // language dependent commands (once per document)
1918 snippets.insert(i18npreamble(it->second.langpreamble(),
1919 buffer().language(),
1920 buffer().params().encoding(),
1921 use_polyglossia, need_fixedwidth));
1922 // commands for language changing (for multilanguage documents)
1923 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1924 snippets.insert(i18npreamble(
1925 it->second.babelpreamble(),
1926 buffer().language(),
1927 buffer().params().encoding(),
1928 use_polyglossia, need_fixedwidth));
1929 for (lang_it lit = lbeg; lit != lend; ++lit)
1930 snippets.insert(i18npreamble(
1931 it->second.babelpreamble(),
1933 buffer().params().encoding(),
1934 use_polyglossia, need_fixedwidth));
1938 odocstringstream tcpreamble;
1939 set<docstring>::const_iterator const send = snippets.end();
1940 set<docstring>::const_iterator it = snippets.begin();
1941 for (; it != send; ++it)
1943 return tcpreamble.str();
1947 docstring const LaTeXFeatures::getLyXSGMLEntities() const
1949 // Definition of entities used in the document that are LyX related.
1950 odocstringstream entities;
1952 if (mustProvide("lyxarrow")) {
1953 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
1956 return entities.str();
1960 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1962 odocstringstream sgmlpreamble;
1964 docstring const basename(from_utf8(onlyPath(fname)));
1966 FileMap::const_iterator end = IncludedFiles_.end();
1967 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1970 sgmlpreamble << "\n<!ENTITY " << fi->first
1971 << (isSGMLFileName(fi->second) ? " SYSTEM \"" : " \"")
1972 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1974 return sgmlpreamble.str();
1978 void LaTeXFeatures::showStruct() const
1980 lyxerr << "LyX needs the following commands when LaTeXing:"
1981 << "\n***** Packages:" << getPackages()
1982 << "\n***** Macros:" << to_utf8(getMacros().str)
1983 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1984 << "\n***** done." << endl;
1988 Buffer const & LaTeXFeatures::buffer() const
1994 void LaTeXFeatures::setBuffer(Buffer const & buffer)
2000 BufferParams const & LaTeXFeatures::bufferParams() const
2006 void LaTeXFeatures::getFloatDefinitions(otexstream & os) const
2008 FloatList const & floats = params_.documentClass().floats();
2010 // Here we will output the code to create the needed float styles.
2011 // We will try to do this as minimal as possible.
2012 // \floatstyle{ruled}
2013 // \newfloat{algorithm}{htbp}{loa}
2014 // \providecommand{\algorithmname}{Algorithm}
2015 // \floatname{algorithm}{\protect\algorithmname}
2016 UsedFloats::const_iterator cit = usedFloats_.begin();
2017 UsedFloats::const_iterator end = usedFloats_.end();
2018 for (; cit != end; ++cit) {
2019 Floating const & fl = floats.getType(cit->first);
2021 // For builtin floats we do nothing.
2022 if (fl.isPredefined())
2025 // We have to special case "table" and "figure"
2026 if (fl.floattype() == "tabular" || fl.floattype() == "figure") {
2027 // Output code to modify "table" or "figure"
2028 // but only if builtin == false
2029 // and that have to be true at this point in the
2031 docstring const type = from_ascii(fl.floattype());
2032 docstring const placement = from_ascii(fl.placement());
2033 docstring const style = from_ascii(fl.style());
2034 if (!style.empty()) {
2035 os << "\\floatstyle{" << style << "}\n"
2036 << "\\restylefloat{" << type << "}\n";
2038 if (!placement.empty()) {
2039 os << "\\floatplacement{" << type << "}{"
2040 << placement << "}\n";
2043 // The other non builtin floats.
2045 docstring const type = from_ascii(fl.floattype());
2046 docstring const placement = from_ascii(fl.placement());
2047 docstring const ext = from_ascii(fl.ext());
2048 docstring const within = from_ascii(fl.within());
2049 docstring const style = from_ascii(fl.style());
2050 docstring const name =
2051 buffer().language()->translateLayout(fl.name());
2052 os << "\\floatstyle{" << style << "}\n"
2053 << "\\newfloat{" << type << "}{" << placement
2054 << "}{" << ext << '}';
2055 if (!within.empty())
2056 os << '[' << within << ']';
2058 << "\\providecommand{\\" << type << "name}{"
2060 << "\\floatname{" << type << "}{\\protect\\"
2061 << type << "name}\n";
2063 // What missing here is to code to minimalize the code
2064 // output so that the same floatstyle will not be
2065 // used several times, when the same style is still in
2069 // The subfig package is loaded later
2070 os << "\n\\AtBeginDocument{\\newsubfloat{" << from_ascii(fl.floattype()) << "}}\n";
2075 void LaTeXFeatures::resolveAlternatives()
2077 for (Features::iterator it = features_.begin(); it != features_.end();) {
2078 if (contains(*it, '|')) {
2079 vector<string> const alternatives = getVectorFromString(*it, "|");
2080 vector<string>::const_iterator const end = alternatives.end();
2081 vector<string>::const_iterator ita = alternatives.begin();
2082 // Is any alternative already required? => use that
2083 for (; ita != end; ++ita) {
2084 if (isRequired(*ita))
2087 // Is any alternative available? => use the first one
2090 for (ita = alternatives.begin(); ita != end; ++ita) {
2091 if (isAvailable(*ita)) {
2097 // This will not work, but not requiring something
2098 // would be more confusing
2100 require(alternatives.front());
2101 features_.erase(it);
2102 it = features_.begin();
2109 void LaTeXFeatures::expandMultiples()
2111 for (Features::iterator it = features_.begin(); it != features_.end();) {
2112 if (contains(*it, ',')) {
2113 vector<string> const multiples = getVectorFromString(*it, ",");
2114 vector<string>::const_iterator const end = multiples.end();
2115 vector<string>::const_iterator itm = multiples.begin();
2116 // Do nothing if any multiple is already required
2117 for (; itm != end; ++itm) {
2118 if (!isRequired(*itm))
2121 features_.erase(it);
2122 it = features_.begin();