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 "{%\n L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
68 static docstring const noun_def = from_ascii(
69 "\\newcommand{\\noun}[1]{\\textsc{#1}}");
71 static docstring const lyxarrow_def = from_ascii(
72 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
74 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
75 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}");
77 // ZERO WIDTH SPACE (ZWSP) is actually not a space character
78 // but marks a line break opportunity. Several commands provide a
79 // line break opportunity. They differ in side-effects:
80 // \allowbreak prevents hyphenation after hyphen or dash + ZWSP
81 // \linebreak[<n>] takes an optional argument denoting "urgency".
82 // The \LyXZeroWidthSpace wrapper allows customization in the preamble.
83 static docstring const lyxZWSP_def = from_ascii(
84 "\\newcommand*\\LyXZeroWidthSpace{\\hspace{0pt}}");
86 // for quotes without babel. This does not give perfect results, but
87 // anybody serious about non-english quotes should use babel (JMarc).
89 static docstring const quotedblbase_def = from_ascii(
90 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
91 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
92 " \\penalty10000\\hskip0em\\relax%\n"
95 static docstring const quotesinglbase_def = from_ascii(
96 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
97 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
98 " \\penalty10000\\hskip0em\\relax%\n"
101 static docstring const guillemotleft_def = from_ascii(
102 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
103 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
104 "\\penalty10000\\hskip0pt\\relax%\n"
107 static docstring const guillemotright_def = from_ascii(
108 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
109 " \\penalty10000\\hskip0pt%\n"
110 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
113 static docstring const guilsinglleft_def = from_ascii(
114 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
115 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
116 " \\penalty10000\\hskip0pt\\relax%\n"
119 static docstring const guilsinglright_def = from_ascii(
120 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
121 " \\penalty10000\\hskip0pt%\n"
122 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
125 static docstring const textquotedbl_def = from_ascii(
126 "\\DeclareTextSymbolDefault{\\textquotedbl}{T1}");
128 static docstring const textquotedblp_xetex_def = from_ascii(
129 "\\providecommand\\textquotedblplain{%\n"
130 " \\bgroup\\addfontfeatures{Mapping=}\\char34\\egroup}");
132 static docstring const textquotedblp_luatex_def = from_ascii(
133 "\\providecommand\\textquotedblplain{%\n"
134 " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\char34\\egroup}");
136 static docstring const textquotesinglep_xetex_def = from_ascii(
137 "\\providecommand\\textquotesingleplain{%\n"
138 " \\bgroup\\addfontfeatures{Mapping=}\\char39\\egroup}");
140 static docstring const textquotesinglep_luatex_def = from_ascii(
141 "\\providecommand\\textquotesingleplain{%\n"
142 " \\bgroup\\addfontfeatures{RawFeature=-tlig}\\char39\\egroup}");
144 static docstring const paragraphleftindent_def = from_ascii(
145 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
147 " \\begin{list}{}{%\n"
148 " \\setlength{\\topsep}{0pt}%\n"
149 " \\addtolength{\\leftmargin}{#1}\n"
150 // ho hum, yet more things commented out with no hint as to why they
151 // weren't just removed
152 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
153 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
154 // "%% \\setlength\\listparindent\\parindent%\n"
155 // "%% \\setlength\\itemindent\\parindent%\n"
156 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
162 static docstring const floatingfootnote_def = from_ascii(
163 "%% Special footnote code from the package 'stblftnt.sty'\n"
164 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
165 "\\let\\SF@@footnote\\footnote\n"
166 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
167 " \\expandafter\\SF@@footnote\n"
169 " \\expandafter\\SF@gobble@opt\n"
172 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
173 " \\SF@gobble@twobracket\n"
176 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
177 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
178 "\\def\\SF@gobble@twobracket[#1]#2{}\n");
180 static docstring const binom_def = from_ascii(
181 "%% Binom macro for standard LaTeX users\n"
182 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
184 static docstring const mathcircumflex_def = from_ascii(
185 "%% For printing a cirumflex inside a formula\n"
186 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
188 static docstring const tabularnewline_def = from_ascii(
189 "%% Because html converters don't know tabularnewline\n"
190 "\\providecommand{\\tabularnewline}{\\\\}\n");
192 static docstring const lyxgreyedout_def = from_ascii(
193 "%% The greyedout annotation environment\n"
194 "\\newenvironment{lyxgreyedout}\n"
195 " {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n"
196 " {\\ignorespacesafterend\\egroup}\n");
198 static docstring const lyxgreyedout_rtl_def = from_ascii(
199 "%% The greyedout annotation environment (with RTL support)\n"
200 "\\NewEnviron{lyxgreyedout}{%\n"
202 "\\everypar{\\textcolor{note_fontcolor}\\beginL\\ignorespaces}%\n"
203 "\\BODY\\everypar{\\ignorespacesafterend\\endL}\n"
205 "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
206 "\\BODY\\ignorespacesafterend\\egroup\n"
209 static docstring const lyxgreyedout_luartl_def = from_ascii(
210 "%% The greyedout annotation environment (with RTL support)\n"
211 "\\NewEnviron{lyxgreyedout}{%\n"
213 "\\everypar{\\color{note_fontcolor}\\pardir TRT \\textdir TRT\\ignorespaces}%\n"
214 "\\BODY\\everypar{\\ignorespacesafterend}\n"
216 "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
217 "\\BODY\\ignorespacesafterend\\egroup\n"
220 static docstring const lyxgreyedout_luartl_babel_def = from_ascii(
221 "%% The greyedout annotation environment (with RTL support)\n"
222 "\\NewEnviron{lyxgreyedout}{%\n"
224 "\\everypar{\\color{note_fontcolor}\\pardir TRT \\textdir TRT\\ignorespaces}%\n"
225 "\\BODY\\everypar{\\ignorespacesafterend}\n"
227 "\\textcolor{note_fontcolor}\\bgroup\\ignorespaces%\n"
228 "\\BODY\\ignorespacesafterend\\egroup\n"
231 // We want to omit the file extension for includegraphics, but this does not
232 // work when the filename contains other dots.
233 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
234 static docstring const lyxdot_def = from_ascii(
235 "%% A simple dot to overcome graphicx limitations\n"
236 "\\newcommand{\\lyxdot}{.}\n");
238 static docstring const changetracking_dvipost_def = from_ascii(
239 "%% Change tracking with dvipost\n"
241 "\\dvipost{osstart color push Red}\n"
242 "\\dvipost{osend color pop}\n"
243 "\\dvipost{cbstart color push Blue}\n"
244 "\\dvipost{cbrule 0pt}\n"
245 "\\dvipost{cbend color pop}\n"
246 "\\DeclareRobustCommand{\\lyxadded}[4][]{\\changestart#4\\changeend}\n"
247 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{%\n"
248 "\\changestart\\overstrikeon#4\\overstrikeoff\\changeend}\n");
250 static docstring const changetracking_dvipost_cb_def = from_ascii(
251 "%% Change tracking with dvipost\n"
253 "\\dvipost{osstart color push Red}\n"
254 "\\dvipost{osend color pop}\n"
255 "\\dvipost{cbstart color push Blue}\n"
256 "\\dvipost{cbend color pop}\n"
257 "\\DeclareRobustCommand{\\lyxadded}[4][]{\\changestart#4\\changeend}\n"
258 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{%\n"
259 "\\changestart\\overstrikeon#4\\overstrikeoff\\changeend}\n");
261 static docstring const changetracking_xcolor_ulem_def = from_ascii(
262 "%% Change tracking with ulem\n"
263 "\\DeclareRobustCommand{\\lyxadded}[4][]{{\\color{lyxadded}{}#4}}\n"
264 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{{\\color{lyxdeleted}\\lyxsout{#4}}}\n"
265 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
267 static docstring const changetracking_xcolor_ulem_cb_def = from_ascii(
268 "%% Change tracking with ulem and changebars\n"
269 "\\DeclareRobustCommand{\\lyxadded}[4][]{{%\n"
270 " \\protect\\cbstart\\color{lyxadded}{}#4%\n"
271 " \\protect\\cbend%\n"
273 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{{%\n"
274 " \\protect\\cbstart\\color{lyxdeleted}\\lyxsout{#4}%\n"
275 " \\protect\\cbend%\n"
277 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
279 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
280 "%% Change tracking with ulem and hyperref\n"
281 "\\DeclareRobustCommand{\\lyxadded}[4][]{{\\texorpdfstring{\\color{lyxadded}{}}{}#4}}\n"
282 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{{\\texorpdfstring{\\color{lyxdeleted}\\lyxsout{#4}}{}}}\n"
283 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
285 static docstring const changetracking_xcolor_ulem_hyperref_cb_def = from_ascii(
286 "%% Change tracking with ulem, hyperref and changebars\n"
287 "\\DeclareRobustCommand{\\lyxadded}[4][]{{%\n"
288 " \\texorpdfstring{\\protect\\cbstart\\color{lyxadded}{}}{}#4%\n"
289 " \\texorpdfstring{\\protect\\cbend}{}%\n"
291 "\\DeclareRobustCommand{\\lyxdeleted}[4][]{{%\n"
292 " \\texorpdfstring{\\protect\\cbstart\\color{lyxdeleted}\\lyxsout{#4}%\n"
293 " \\protect\\cbend}{}%\n"
295 "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
297 static docstring const changetracking_tikz_math_sout_def = from_ascii(
298 "%% Strike out display math with tikz\n"
299 "\\usepackage{tikz}\n"
300 "\\usetikzlibrary{calc}\n"
301 "\\newcommand{\\lyxmathsout}[1]{%\n"
302 " \\tikz[baseline=(math.base)]{\n"
303 " \\node[inner sep=0pt,outer sep=0pt](math){#1};\n"
304 " \\draw($(math.south west)+(2em,.5em)$)--($(math.north east)-(2em,.5em)$);\n"
308 static docstring const changetracking_none_def = from_ascii(
309 "\\newcommand{\\lyxadded}[3]{#3}\n"
310 "\\newcommand{\\lyxdeleted}[3]{}\n");
312 static docstring const textgreek_LGR_def = from_ascii(
313 "\\DeclareFontEncoding{LGR}{}{}\n");
314 static docstring const textgreek_def = from_ascii(
315 "\\DeclareRobustCommand{\\greektext}{%\n"
316 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
317 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n");
319 static docstring const textcyr_T2A_def = from_ascii(
320 "\\InputIfFileExists{t2aenc.def}{}{%\n"
321 " \\errmessage{File `t2aenc.def' not found: Cyrillic script not supported}}\n");
322 static docstring const textcyr_def = from_ascii(
323 "\\DeclareRobustCommand{\\cyrtext}{%\n"
324 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
325 "\\DeclareRobustCommand{\\textcyrillic}[1]{\\leavevmode{\\cyrtext #1}}\n");
327 static docstring const lyxmathsym_def = from_ascii(
328 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
329 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
331 static docstring const papersizedvi_def = from_ascii(
332 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n");
334 static docstring const papersizepdf_def = from_ascii(
335 "\\pdfpageheight\\paperheight\n"
336 "\\pdfpagewidth\\paperwidth\n");
338 static docstring const papersizepdflua_def = from_ascii(
339 "% Backwards compatibility for LuaTeX < 0.90\n"
340 "\\@ifundefined{pageheight}{\\let\\pageheight\\pdfpageheight}{}\n"
341 "\\@ifundefined{pagewidth}{\\let\\pagewidth\\pdfpagewidth}{}\n"
342 "\\pageheight\\paperheight\n"
343 "\\pagewidth\\paperwidth\n");
345 static docstring const cedilla_def = from_ascii(
346 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
347 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
349 static docstring const subring_def = from_ascii(
350 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
351 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
353 static docstring const subdot_def = from_ascii(
354 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
355 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
357 static docstring const subhat_def = from_ascii(
358 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
359 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
361 static docstring const subtilde_def = from_ascii(
362 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
363 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
365 static docstring const dacute_def = from_ascii(
366 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
368 static docstring const tipasymb_def = from_ascii(
369 "\\DeclareFontEncoding{T3}{}{}\n"
370 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n");
372 static docstring const dgrave_def = from_ascii(
373 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n");
375 static docstring const rcap_def = from_ascii(
376 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
378 static docstring const ogonek_def = from_ascii(
379 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
380 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
381 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
382 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
383 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
385 static docstring const lyxaccent_def = from_ascii(
386 "%% custom text accent \\LyxTextAccent[<rise value (length)>]{<accent>}{<base>}\n"
387 "\\newcommand*{\\LyxTextAccent}[3][0ex]{%\n"
388 " \\hmode@bgroup\\ooalign{\\null#3\\crcr\\hidewidth\n"
389 " \\raise#1\\hbox{#2}\\hidewidth}\\egroup}\n"
390 "%% select a font size smaller than the current font size:\n"
391 "\\newcommand{\\LyxAccentSize}[1][\\sf@size]{%\n"
392 " \\check@mathfonts\\fontsize#1\\z@\\math@fontsfalse\\selectfont\n"
395 static docstring const textcommabelow_def = from_ascii(
396 "\\ProvideTextCommandDefault{\\textcommabelow}[1]{%%\n"
397 " \\LyxTextAccent[-.31ex]{\\LyxAccentSize,}{#1}}\n");
399 static docstring const textcommaabove_def = from_ascii(
400 "\\ProvideTextCommandDefault{\\textcommaabove}[1]{%%\n"
401 " \\LyxTextAccent[.5ex]{\\LyxAccentSize`}{#1}}\n");
403 static docstring const textcommaaboveright_def = from_ascii(
404 "\\ProvideTextCommandDefault{\\textcommaaboveright}[1]{%%\n"
405 " \\LyxTextAccent[.5ex]{\\LyxAccentSize\\ '}{#1}}\n");
407 // Baltic languages use a comma-accent instead of a cedilla
408 static docstring const textbaltic_def = from_ascii(
409 "%% use comma accent instead of cedilla for these characters:\n"
410 "\\DeclareTextCompositeCommand{\\c}{T1}{g}{\\textcommaabove{g}}\n"
411 "\\DeclareTextCompositeCommand{\\c}{T1}{G}{\\textcommabelow{G}}\n"
412 "\\DeclareTextCompositeCommand{\\c}{T1}{k}{\\textcommabelow{k}}\n"
413 "\\DeclareTextCompositeCommand{\\c}{T1}{K}{\\textcommabelow{K}}\n"
414 "\\DeclareTextCompositeCommand{\\c}{T1}{l}{\\textcommabelow{l}}\n"
415 "\\DeclareTextCompositeCommand{\\c}{T1}{L}{\\textcommabelow{L}}\n"
416 "\\DeclareTextCompositeCommand{\\c}{T1}{n}{\\textcommabelow{n}}\n"
417 "\\DeclareTextCompositeCommand{\\c}{T1}{N}{\\textcommabelow{N}}\n"
418 "\\DeclareTextCompositeCommand{\\c}{T1}{r}{\\textcommabelow{r}}\n"
419 "\\DeclareTextCompositeCommand{\\c}{T1}{R}{\\textcommabelow{R}}\n");
421 // Use cyrillic fonts to provide letter schwa in text (see #11062)
422 static docstring const textschwa_def = from_ascii(
423 "%% letter schwa missing in Latin fonts, use Cyrillic schwa\n"
424 "\\DeclareTextSymbolDefault{\\CYRSCHWA}{T2A}\n"
425 "\\DeclareTextSymbolDefault{\\cyrschwa}{T2A}\n"
426 "\\ProvideTextCommandDefault{\\textSchwa}{\\CYRSCHWA}\n"
427 "\\ProvideTextCommandDefault{\\textschwa}{\\cyrschwa}\n");
429 // split-level fractions
430 static docstring const xfrac_def = from_ascii(
431 "\\usepackage{xfrac}\n");
432 static docstring const smallLetterFrac_def = from_ascii(
433 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{default}{text}\n"
434 " {phantom=c, scale-factor=1.0, slash-left-kern=-.05em}\n"
435 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{lmr}{text}\n"
436 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
437 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{lmss}{text}\n"
438 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
439 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{cmr}{text}\n"
440 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
441 "\\DeclareCollectionInstance{smallLetterFrac}{xfrac}{cmss}{text}\n"
442 " {slash-symbol-font=ptm, phantom=c, scale-factor=1, slash-left-kern=-.05em}\n"
443 "\\newcommand{\\smallLetterFrac}[2]{%\n"
444 " {\\UseCollection{xfrac}{smallLetterFrac}\\sfrac{#1}{#2}}}\n");
446 static docstring const lyxref_def = from_ascii(
447 "\\RS@ifundefined{subsecref}\n"
448 " {\\newref{subsec}{name = \\RSsectxt}}\n"
450 "\\RS@ifundefined{thmref}\n"
451 " {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
453 "\\RS@ifundefined{lemref}\n"
454 " {\\def\\RSlemtxt{lemma~}\\newref{lem}{name = \\RSlemtxt}}\n"
457 // Make sure the columns are also outputed as rtl
458 static docstring const rtloutputdblcol_def = from_ascii(
459 "\\def\\@outputdblcol{%\n"
460 " \\if@firstcolumn\n"
461 " \\global \\@firstcolumnfalse\n"
462 " \\global \\setbox\\@leftcolumn \\box\\@outputbox\n"
464 " \\global \\@firstcolumntrue\n"
465 " \\setbox\\@outputbox \\vbox {%\n"
466 " \\hb@xt@\\textwidth {%\n"
467 " \\kern\\textwidth \\kern-\\columnwidth %**\n"
468 " \\hb@xt@\\columnwidth {%\n"
469 " \\box\\@leftcolumn \\hss}%\n"
470 " \\kern-\\textwidth %**\n"
472 " {\\normalcolor\\vrule \\@width\\columnseprule}%\n"
474 " \\kern-\\textwidth %**\n"
475 " \\hb@xt@\\columnwidth {%\n"
476 " \\box\\@outputbox \\hss}%\n"
477 " \\kern-\\columnwidth \\kern\\textwidth %**\n"
480 " \\@combinedblfloats\n"
483 " \\@dblfloatplacement\n"
484 " \\@startdblcolumn\n"
485 " \\@whilesw\\if@fcolmade \\fi\n"
487 " \\@startdblcolumn}%\n"
491 "\\@mparswitchtrue\n");
493 static docstring const lyxmintcaption_def = from_ascii(
494 "\\long\\def\\lyxmintcaption[#1]#2{%\n"
495 " \\ifx#1t\\vskip\\baselineskip\\fi%\n"
496 " \\refstepcounter{listing}\\noindent%\n"
497 " \\addcontentsline{lol}{listing}%\n"
498 " {\\protect\\numberline{\\thelisting}{\\ignorespaces #2}}%\n"
499 " \\setbox\\@tempboxa\\hbox{\\listingscaption~\\thelisting: #2}%\n"
500 " \\ifdim \\wd\\@tempboxa >\\linewidth%\n"
501 " \\parbox[t]{\\linewidth}{\\unhbox\\@tempboxa}\\else%\n"
502 " \\hbox to\\linewidth{\\hfil\\box\\@tempboxa\\hfil}\\fi%\n"
503 " \\ifx#1b\\vskip\\baselineskip\\fi\n"
507 /////////////////////////////////////////////////////////////////////
511 /////////////////////////////////////////////////////////////////////
513 static docstring const lyxnoun_style = from_ascii(
515 " font-variant: small-caps;\n"
519 // this is how it normally renders, but it might not always do so.
520 static docstring const lyxstrikeout_style = from_ascii(
522 " text-decoration: line-through;\n"
526 /////////////////////////////////////////////////////////////////////
530 /////////////////////////////////////////////////////////////////////
533 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
534 OutputParams const & r)
535 : buffer_(&b), params_(p), runparams_(r), in_float_(false),
536 in_deleted_inset_(false)
540 LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
542 string const local_lp = bufferParams().lang_package;
544 // Locally, custom is just stored as a string
545 // in bufferParams().lang_package.
546 if (local_lp != "auto"
547 && local_lp != "babel"
548 && local_lp != "default"
549 && local_lp != "none")
550 return LANG_PACK_CUSTOM;
552 if (local_lp == "none")
553 return LANG_PACK_NONE;
555 /* If "auto" is selected, we load polyglossia with non-TeX fonts,
556 * else we select babel.
557 * If babel is selected (either directly or via the "auto"
558 * mechanism), we really do only require it if we have
559 * a language that needs it.
561 bool const polyglossia_required =
562 params_.useNonTeXFonts
563 && isAvailable("polyglossia")
564 && !isProvided("babel")
565 && this->hasOnlyPolyglossiaLanguages();
566 bool const babel_required =
567 !bufferParams().language->babel().empty()
568 || !this->getBabelLanguages().empty();
570 if (local_lp == "auto") {
571 // polyglossia requirement has priority over babel
572 if (polyglossia_required)
573 return LANG_PACK_POLYGLOSSIA;
574 else if (babel_required)
575 return LANG_PACK_BABEL;
578 if (local_lp == "babel") {
580 return LANG_PACK_BABEL;
583 if (local_lp == "default") {
584 switch (lyxrc.language_package_selection) {
586 // polyglossia requirement has priority over babel
587 if (polyglossia_required)
588 return LANG_PACK_POLYGLOSSIA;
589 else if (babel_required)
590 return LANG_PACK_BABEL;
592 case LyXRC::LP_BABEL:
594 return LANG_PACK_BABEL;
596 case LyXRC::LP_CUSTOM:
597 return LANG_PACK_CUSTOM;
599 return LANG_PACK_NONE;
603 return LANG_PACK_NONE;
607 void LaTeXFeatures::require(string const & name)
609 features_.insert(name);
613 void LaTeXFeatures::require(set<string> const & names)
615 features_.insert(names.begin(), names.end());
619 void LaTeXFeatures::provide(string const & name)
621 provides_.insert(name);
625 void LaTeXFeatures::useLayout(docstring const & layoutname)
627 useLayout(layoutname, 0);
631 void LaTeXFeatures::useLayout(docstring const & layoutname, int level)
633 // Some code to avoid loops in dependency definition
634 const int maxlevel = 30;
635 if (level > maxlevel) {
636 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
637 << "recursion attained by layout "
638 << to_utf8(layoutname) << endl;
642 DocumentClass const & tclass = params_.documentClass();
643 if (tclass.hasLayout(layoutname)) {
644 // Is this layout already in usedLayouts?
645 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
646 != usedLayouts_.end())
649 Layout const & layout = tclass[layoutname];
650 require(layout.requires());
652 if (!layout.depends_on().empty()) {
653 useLayout(layout.depends_on(), level + 1);
655 usedLayouts_.push_back(layoutname);
657 lyxerr << "LaTeXFeatures::useLayout: layout `"
658 << to_utf8(layoutname) << "' does not exist in this class"
664 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
666 docstring const & lname = lay.name();
667 DocumentClass const & tclass = params_.documentClass();
669 // this is a default inset layout, nothing useful here
670 if (!tclass.hasInsetLayout(lname))
672 // Is this layout already in usedInsetLayouts?
673 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
674 != usedInsetLayouts_.end())
677 require(lay.requires());
678 usedInsetLayouts_.push_back(lname);
682 bool LaTeXFeatures::isRequired(string const & name) const
684 return features_.find(name) != features_.end();
688 bool LaTeXFeatures::isProvided(string const & name) const
690 // Currently, this is only features provided by babel languages
691 // (such as textgreek)
692 if (provides_.find(name) != provides_.end())
695 if (params_.useNonTeXFonts)
696 return params_.documentClass().provides(name);
698 bool const ot1 = (params_.main_font_encoding() == "default"
699 || params_.main_font_encoding() == "OT1");
700 bool const complete = (params_.fontsSans() == "default"
701 && params_.fontsTypewriter() == "default");
702 bool const nomath = (params_.fontsMath() == "default");
703 return params_.documentClass().provides(name)
704 || theLaTeXFonts().getLaTeXFont(
705 from_ascii(params_.fontsRoman())).provides(name, ot1,
708 || theLaTeXFonts().getLaTeXFont(
709 from_ascii(params_.fontsSans())).provides(name, ot1,
712 || theLaTeXFonts().getLaTeXFont(
713 from_ascii(params_.fontsTypewriter())).provides(name, ot1,
716 || theLaTeXFonts().getLaTeXFont(
717 from_ascii(params_.fontsMath())).provides(name, ot1,
723 bool LaTeXFeatures::mustProvide(string const & name) const
725 return isRequired(name) && !isProvided(name);
729 bool LaTeXFeatures::isAvailable(string const & name)
731 string::size_type const i = name.find("->");
732 if (i != string::npos) {
733 string const from = name.substr(0,i);
734 string const to = name.substr(i+2);
735 //LYXERR0("from=[" << from << "] to=[" << to << "]");
736 return theConverters().isReachable(from, to);
738 return LaTeXPackages::isAvailable(name);
744 void addSnippet(std::list<TexString> & list, TexString ts, bool allow_dupes)
747 // test the absense of duplicates, i.e. elements with same str
748 none_of(list.begin(), list.end(), [&](TexString const & ts2){
749 return ts.str == ts2.str;
752 list.push_back(move(ts));
756 TexString getSnippets(std::list<TexString> const & list)
758 otexstringstream snip;
759 for (TexString const & ts : list)
760 snip << TexString(ts) << '\n';
761 return snip.release();
767 void LaTeXFeatures::addPreambleSnippet(TexString ts, bool allow_dupes)
769 addSnippet(preamble_snippets_, move(ts), allow_dupes);
773 void LaTeXFeatures::addPreambleSnippet(docstring const & str, bool allow_dupes)
775 addSnippet(preamble_snippets_, TexString(str), allow_dupes);
779 void LaTeXFeatures::addCSSSnippet(std::string const & snippet)
781 addSnippet(css_snippets_, TexString(from_ascii(snippet)), false);
785 TexString LaTeXFeatures::getPreambleSnippets() const
787 return getSnippets(preamble_snippets_);
791 docstring LaTeXFeatures::getCSSSnippets() const
793 return getSnippets(css_snippets_).str;
798 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
800 if (!usedFloats_[name])
801 usedFloats_[name] = subfloat;
804 // We only need float.sty if we use non builtin floats, or if we
805 // use the "H" modifier. This includes modified table and
806 // figure floats. (Lgb)
807 Floating const & fl = params_.documentClass().floats().getType(name);
808 if (!fl.floattype().empty()) {
809 if (fl.usesFloatPkg())
811 if (!fl.requires().empty()) {
812 vector<string> reqs = getVectorFromString(fl.requires());
813 for (auto const req : reqs)
820 void LaTeXFeatures::useLanguage(Language const * lang)
822 if (!lang->babel().empty() || !lang->polyglossia().empty())
823 UsedLanguages_.insert(lang);
824 if (!lang->requires().empty())
825 require(lang->requires());
826 // currently only supported for Babel
827 if (!lang->provides().empty() && useBabel())
828 provide(lang->provides());
829 // CJK languages do not have a babel name.
830 // They use the CJK package
831 if (lang->encoding()->package() == Encoding::CJK)
833 // japanese babel language is special (tied to the pLaTeX engine).
834 if (lang->encoding()->package() == Encoding::japanese)
839 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
841 IncludedFiles_[key] = name;
845 bool LaTeXFeatures::hasLanguages() const
847 return !UsedLanguages_.empty();
851 bool LaTeXFeatures::hasOnlyPolyglossiaLanguages() const
853 // first the main language
854 if (params_.language->polyglossia().empty())
856 // now the secondary languages
857 LanguageList::const_iterator const begin = UsedLanguages_.begin();
858 for (LanguageList::const_iterator cit = begin;
859 cit != UsedLanguages_.end();
861 if ((*cit)->polyglossia().empty())
868 bool LaTeXFeatures::hasPolyglossiaExclusiveLanguages() const
870 // first the main language
871 if (params_.language->isPolyglossiaExclusive())
873 // now the secondary languages
874 LanguageList::const_iterator const begin = UsedLanguages_.begin();
875 for (LanguageList::const_iterator cit = begin;
876 cit != UsedLanguages_.end();
878 if ((*cit)->isPolyglossiaExclusive())
885 vector<string> LaTeXFeatures::getPolyglossiaExclusiveLanguages() const
887 vector<string> result;
888 // first the main language
889 if (params_.language->isPolyglossiaExclusive())
890 result.push_back(params_.language->display());
891 // now the secondary languages
892 LanguageList::const_iterator const begin = UsedLanguages_.begin();
893 for (LanguageList::const_iterator cit = begin;
894 cit != UsedLanguages_.end();
896 if ((*cit)->isPolyglossiaExclusive())
897 result.push_back((*cit)->display());
903 vector<string> LaTeXFeatures::getBabelExclusiveLanguages() const
905 vector<string> result;
906 // first the main language
907 if (params_.language->isBabelExclusive())
908 result.push_back(params_.language->display());
909 // now the secondary languages
910 LanguageList::const_iterator const begin = UsedLanguages_.begin();
911 for (LanguageList::const_iterator cit = begin;
912 cit != UsedLanguages_.end();
914 if ((*cit)->isBabelExclusive())
915 result.push_back((*cit)->display());
921 string LaTeXFeatures::getBabelLanguages() const
926 LanguageList::const_iterator const begin = UsedLanguages_.begin();
927 for (LanguageList::const_iterator cit = begin;
928 cit != UsedLanguages_.end();
930 if ((*cit)->babel().empty())
936 langs << (*cit)->babel();
942 set<string> LaTeXFeatures::getPolyglossiaLanguages() const
946 LanguageList::const_iterator const begin = UsedLanguages_.begin();
947 for (LanguageList::const_iterator cit = begin;
948 cit != UsedLanguages_.end();
950 // We do not need the variants here
951 langs.insert((*cit)->polyglossia());
957 string LaTeXFeatures::getActiveChars() const
960 // first the main language
961 res += params_.language->activeChars();
962 // now the secondary languages
963 LanguageList::const_iterator const begin = UsedLanguages_.begin();
964 for (LanguageList::const_iterator cit = begin;
965 cit != UsedLanguages_.end(); ++cit)
966 res += ((*cit)->activeChars());
971 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
973 // This does only find encodings of languages supported by babel, but
974 // that does not matter since we don't have a language with an
975 // encoding supported by inputenc but without babel support.
977 for (auto const & lang : UsedLanguages_)
978 if (lang->encoding()->latexName() != doc_encoding &&
979 lang->encoding()->package() == Encoding::inputenc)
980 encs.insert(lang->encoding()->latexName());
985 void LaTeXFeatures::getFontEncodings(vector<string> & encs, bool const onlylangs) const
988 // these must be loaded if glyphs of this script are used
989 // unless a language providing them is used in the document
990 if (mustProvide("textgreek")
991 && find(encs.begin(), encs.end(), "LGR") == encs.end())
992 encs.insert(encs.begin(), "LGR");
993 if ((mustProvide("textcyrillic") || mustProvide("textschwa"))
994 && find(encs.begin(), encs.end(), "T2A") == encs.end())
995 encs.insert(encs.begin(), "T2A");
998 for (auto const & lang : UsedLanguages_) {
999 vector<string> extraencs =
1000 getVectorFromString(lang->fontenc(buffer().masterParams()));
1001 for (auto const & extra : extraencs) {
1002 if (extra != "none" && find(encs.begin(), encs.end(), extra) == encs.end())
1003 encs.insert(encs.begin(), extra);
1009 bool LaTeXFeatures::hasRTLLanguage() const
1011 if (params_.language->rightToLeft())
1013 for (auto const & lang : UsedLanguages_)
1014 if (lang->rightToLeft())
1022 char const * simplefeatures[] = {
1023 // note that the package order here will be the same in the LaTeX-output
1030 // subfig is handled in BufferParams.cpp
1034 /*For a successful cooperation of the `wrapfig' package with the
1035 `float' package you should load the `wrapfig' package *after*
1036 the `float' package. See the caption package documentation
1065 // listings is handled in BufferParams.cpp
1095 char const * bibliofeatures[] = {
1096 // Known bibliography packages (will be loaded before natbib)
1112 int const nb_bibliofeatures = sizeof(bibliofeatures) / sizeof(char const *);
1114 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
1119 string const LaTeXFeatures::getColorOptions() const
1121 ostringstream colors;
1123 // Handling the color packages separately is needed to be able to load them
1124 // before babel when hyperref is loaded with the colorlinks option
1125 // for more info see Bufferparams.cpp
1128 if (mustProvide("color") || mustProvide("xcolor")) {
1129 string const package =
1130 (mustProvide("xcolor") ? "xcolor" : "color");
1131 if (params_.graphics_driver == "default"
1132 || params_.graphics_driver == "none")
1133 colors << "\\usepackage{" << package << "}\n";
1135 colors << "\\usepackage["
1136 << params_.graphics_driver
1137 << "]{" << package << "}\n";
1140 // pdfcolmk must be loaded after color
1141 if (mustProvide("pdfcolmk"))
1142 colors << "\\usepackage{pdfcolmk}\n";
1144 // the following 3 color commands must be set after color
1145 // is loaded and before pdfpages, therefore add the command
1146 // here define the set color
1147 if (mustProvide("pagecolor")) {
1148 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
1149 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
1150 // set the page color
1151 colors << "\\pagecolor{page_backgroundcolor}\n";
1154 if (mustProvide("fontcolor")) {
1155 colors << "\\definecolor{document_fontcolor}{rgb}{";
1156 colors << outputLaTeXColor(params_.fontcolor) << "}\n";
1158 colors << "\\color{document_fontcolor}\n";
1161 if (mustProvide("lyxgreyedout")) {
1162 colors << "\\definecolor{note_fontcolor}{rgb}{";
1163 colors << outputLaTeXColor(params_.notefontcolor) << "}\n";
1164 // the color will be set together with the definition of
1165 // the lyxgreyedout environment (see lyxgreyedout_def)
1168 // color for shaded boxes
1169 if (isRequired("framed") && mustProvide("color")) {
1170 colors << "\\definecolor{shadecolor}{rgb}{";
1171 colors << outputLaTeXColor(params_.boxbgcolor) << "}\n";
1172 // this color is automatically used by the LaTeX-package "framed"
1175 return colors.str();
1179 string const LaTeXFeatures::getPackageOptions() const
1181 ostringstream packageopts;
1182 // Output all the package option stuff we have been asked to do.
1183 map<string, string>::const_iterator it =
1184 params_.documentClass().packageOptions().begin();
1185 map<string, string>::const_iterator en =
1186 params_.documentClass().packageOptions().end();
1187 for (; it != en; ++it)
1188 if (mustProvide(it->first))
1189 packageopts << "\\PassOptionsToPackage{" << it->second << "}"
1190 << "{" << it->first << "}\n";
1191 return packageopts.str();
1195 string const LaTeXFeatures::getPackages() const
1197 ostringstream packages;
1199 // FIXME: currently, we can only load packages and macros known
1201 // However, with the Require tag of layouts/custom insets,
1202 // also unknown packages can be requested. They are silently
1203 // swallowed now. We should change this eventually.
1205 // These are all the 'simple' includes. i.e
1206 // packages which we just \usepackage{package}
1207 for (int i = 0; i < nb_simplefeatures; ++i) {
1208 if (mustProvide(simplefeatures[i]))
1209 packages << "\\usepackage{" << simplefeatures[i] << "}\n";
1212 // The rest of these packages are somewhat more complicated
1213 // than those above.
1215 if (mustProvide("changebar") && !mustProvide("ct-dvipost")) {
1216 packages << "\\usepackage{changebar}\n";
1219 if (mustProvide("footnote")) {
1220 if (isRequired("hyperref"))
1221 packages << "\\usepackage{footnotehyper}\n";
1223 packages << "\\usepackage{footnote}\n";
1226 // [pdf]lscape is used to rotate longtables
1227 if (mustProvide("lscape")) {
1228 if (runparams_.flavor == OutputParams::LATEX
1229 || runparams_.flavor == OutputParams::DVILUATEX)
1230 packages << "\\usepackage{lscape}\n";
1232 packages << "\\usepackage{pdflscape}\n";
1235 // The tipa package and its extensions (tipx, tone) must not
1236 // be loaded with non-TeX fonts, since fontspec includes the
1237 // respective macros
1238 if (mustProvide("tipa") && !params_.useNonTeXFonts)
1239 packages << "\\usepackage{tipa}\n";
1240 if (mustProvide("tipx") && !params_.useNonTeXFonts)
1241 packages << "\\usepackage{tipx}\n";
1242 if (mustProvide("extraipa") && !params_.useNonTeXFonts)
1243 packages << "\\usepackage{extraipa}\n";
1244 if (mustProvide("tone") && !params_.useNonTeXFonts)
1245 packages << "\\usepackage{tone}\n";
1247 // if fontspec or newtxmath is used, AMS packages have to be loaded
1248 // before fontspec (in BufferParams)
1249 string const amsPackages = loadAMSPackages();
1250 bool const ot1 = (params_.main_font_encoding() == "default"
1251 || params_.main_font_encoding() == "OT1");
1252 bool const use_newtxmath =
1253 theLaTeXFonts().getLaTeXFont(from_ascii(params_.fontsMath())).getUsedPackage(
1254 ot1, false, false) == "newtxmath";
1256 if (!params_.useNonTeXFonts && !use_newtxmath && !amsPackages.empty())
1257 packages << amsPackages;
1259 if (mustProvide("cancel") &&
1260 params_.use_package("cancel") != BufferParams::package_off)
1261 packages << "\\usepackage{cancel}\n";
1263 // marvosym and bbding both define the \Cross macro
1264 if (mustProvide("marvosym")) {
1265 if (mustProvide("bbding"))
1266 packages << "\\let\\Cross\\relax\n";
1267 packages << "\\usepackage{marvosym}\n";
1270 // accents must be loaded after amsmath
1271 if (mustProvide("accents") &&
1272 params_.use_package("accents") != BufferParams::package_off)
1273 packages << "\\usepackage{accents}\n";
1275 // mathdots must be loaded after amsmath
1276 if (mustProvide("mathdots") &&
1277 params_.use_package("mathdots") != BufferParams::package_off)
1278 packages << "\\usepackage{mathdots}\n";
1280 // yhmath must be loaded after amsmath
1281 if (mustProvide("yhmath") &&
1282 params_.use_package("yhmath") != BufferParams::package_off)
1283 packages << "\\usepackage{yhmath}\n";
1285 // stmaryrd must be loaded after amsmath
1286 if (mustProvide("stmaryrd") &&
1287 params_.use_package("stmaryrd") != BufferParams::package_off)
1288 packages << "\\usepackage{stmaryrd}\n";
1290 if (mustProvide("stackrel") &&
1291 params_.use_package("stackrel") != BufferParams::package_off)
1292 packages << "\\usepackage{stackrel}\n";
1294 if (mustProvide("undertilde") &&
1295 params_.use_package("undertilde") != BufferParams::package_off)
1296 packages << "\\usepackage{undertilde}\n";
1298 // [x]color and pdfcolmk are handled in getColorOptions() above
1301 if (isRequired("makeidx") || isRequired("splitidx")) {
1302 if (!isProvided("makeidx") && !isRequired("splitidx"))
1303 packages << "\\usepackage{makeidx}\n";
1304 if (mustProvide("splitidx"))
1305 packages << "\\usepackage{splitidx}\n";
1306 packages << "\\makeindex\n";
1310 if (mustProvide("graphicx") && params_.graphics_driver != "none") {
1311 if (params_.graphics_driver == "default")
1312 packages << "\\usepackage{graphicx}\n";
1314 packages << "\\usepackage["
1315 << params_.graphics_driver
1319 // These must be loaded after graphicx, since they try
1320 // to load graphicx without options
1321 if (mustProvide("rotating"))
1322 packages << "\\usepackage{rotating}\n";
1323 if (mustProvide("rotfloat"))
1324 packages << "\\usepackage{rotfloat}\n";
1326 // lyxskak.sty --- newer chess support based on skak.sty
1327 if (mustProvide("chess"))
1328 packages << "\\usepackage[ps,mover]{lyxskak}\n";
1331 if (mustProvide("setspace") && !isProvided("SetSpace"))
1332 packages << "\\usepackage{setspace}\n";
1334 // we need to assure that mhchem is loaded before esint and every other
1335 // package that redefines command of amsmath because mhchem loads amlatex
1336 // (this info is from the author of mhchem from June 2013)
1337 if (mustProvide("mhchem") &&
1338 params_.use_package("mhchem") != BufferParams::package_off)
1339 packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
1340 "\\usepackage{mhchem}\n";
1342 // wasysym is a simple feature, but it must be after amsmath if both
1344 // wasysym redefines some integrals (e.g. iint) from amsmath. That
1345 // leads to inconsistent integrals. We only load this package if
1346 // the document does not contain integrals (then isRequired("esint")
1347 // is false) or if esint is used, since esint redefines all relevant
1348 // integral symbols from wasysym and amsmath.
1349 // See http://www.lyx.org/trac/ticket/1942
1350 if (mustProvide("wasysym") &&
1351 params_.use_package("wasysym") != BufferParams::package_off &&
1352 (params_.use_package("esint") != BufferParams::package_off || !isRequired("esint")))
1353 packages << "\\usepackage{wasysym}\n";
1355 // esint must be after amsmath (and packages requiring amsmath, like mhchem)
1356 // and wasysym, since it will redeclare inconsistent integral symbols
1357 if (mustProvide("esint") &&
1358 params_.use_package("esint") != BufferParams::package_off)
1359 packages << "\\usepackage{esint}\n";
1361 // Known bibliography packages (simple \usepackage{package})
1362 for (int i = 0; i < nb_bibliofeatures; ++i) {
1363 if (mustProvide(bibliofeatures[i]))
1364 packages << "\\usepackage{"
1365 << bibliofeatures[i] << "}\n";
1368 // Compatibility between achicago and natbib
1369 if (mustProvide("achicago") && mustProvide("natbib"))
1370 packages << "\\let\\achicagobib\\thebibliography\n";
1373 // Some classes load natbib themselves, but still allow (or even require)
1374 // plain numeric citations (ReVTeX is such a case, see bug 5182).
1375 // This special case is indicated by the "natbib-internal" key.
1376 if (mustProvide("natbib")
1377 && !isProvided("natbib-internal")
1378 && !isProvided("biblatex")
1379 && !isProvided("biblatex-natbib")
1380 && !isProvided("jurabib")) {
1381 packages << "\\usepackage[";
1382 if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
1383 packages << "numbers";
1385 packages << "authoryear";
1386 if (!params_.biblio_opts.empty())
1387 packages << ',' << params_.biblio_opts;
1388 packages << "]{natbib}\n";
1391 // Compatibility between achicago and natbib
1392 if (mustProvide("achicago") && mustProvide("natbib")) {
1393 packages << "\\let\\thebibliography\\achicagobib\n";
1394 packages << "\\let\\SCcite\\astroncite\n";
1395 packages << "\\let\\UnexpandableProtect\\protect\n";
1398 // jurabib -- we need version 0.6 at least.
1399 if (mustProvide("jurabib")
1400 && !isProvided("natbib-internal")
1401 && !isProvided("natbib")
1402 && !isProvided("biblatex")
1403 && !isProvided("biblatex-natbib")) {
1404 packages << "\\usepackage";
1405 if (!params_.biblio_opts.empty())
1406 packages << '[' << params_.biblio_opts << ']';
1407 packages << "{jurabib}[2004/01/25]\n";
1410 // opcit -- we pass custombst as we output \bibliographystyle ourselves
1411 if (mustProvide("opcit")) {
1412 if (isRequired("hyperref"))
1413 packages << "\\usepackage[custombst,hyperref]{opcit}\n";
1415 packages << "\\usepackage[custombst]{opcit}\n";
1418 // xargs -- we need version 1.09 at least
1419 if (mustProvide("xargs"))
1420 packages << "\\usepackage{xargs}[2008/03/08]\n";
1422 if (mustProvide("xy"))
1423 packages << "\\usepackage[all]{xy}\n";
1425 if (mustProvide("feyn"))
1426 packages << "\\usepackage{feyn}\n"; //Diagram
1428 if (mustProvide("ulem"))
1429 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
1430 "\\usepackage{ulem}\n";
1432 if (mustProvide("nomencl")) {
1433 // Make it work with the new and old version of the package,
1434 // but don't use the compatibility option since it is
1435 // incompatible to other packages.
1436 packages << "\\usepackage{nomencl}\n"
1437 "% the following is useful when we have the old nomencl.sty package\n"
1438 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
1439 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
1440 "\\makenomenclature\n";
1443 // fixltx2e provides subscript
1444 if (mustProvide("subscript") && !isRequired("fixltx2e"))
1445 packages << "\\usepackage{subscript}\n";
1447 // footmisc must be loaded after setspace
1448 // Set options here, load the package after the user preamble to
1449 // avoid problems with manual loaded footmisc.
1450 if (mustProvide("footmisc"))
1451 packages << "\\PassOptionsToPackage{stable}{footmisc}\n";
1453 if (mustProvide("microtype")){
1454 packages << "\\usepackage{microtype}\n";
1457 return packages.str();
1461 TexString LaTeXFeatures::getMacros() const
1463 otexstringstream macros;
1465 if (!preamble_snippets_.empty()) {
1467 macros << getPreambleSnippets();
1470 if (mustProvide("xetexdashbreakstate"))
1471 macros << "\\XeTeXdashbreakstate 0" << '\n';
1473 if (mustProvide("papersize")) {
1474 if (runparams_.flavor == OutputParams::LATEX
1475 || runparams_.flavor == OutputParams::DVILUATEX)
1476 macros << papersizedvi_def << '\n';
1477 else if (runparams_.flavor == OutputParams::LUATEX)
1478 macros << papersizepdflua_def << '\n';
1480 macros << papersizepdf_def << '\n';
1483 if (mustProvide("LyX")) {
1484 macros << "\\providecommand{\\LyX}";
1485 // open conditional wrappers
1486 if (runparams_.use_polyglossia && hasRTLLanguage())
1487 macros << "{\\@ensure@LTR";
1488 if (isRequired("hyperref"))
1489 macros << "{\\texorpdfstring";
1491 macros << "{\\ensureascii";
1494 // close conditional wrappers
1497 if (isRequired("hyperref"))
1499 if (runparams_.use_polyglossia && hasRTLLanguage())
1504 if (mustProvide("noun"))
1505 macros << noun_def << '\n';
1507 if (mustProvide("lyxarrow"))
1508 macros << lyxarrow_def << '\n';
1510 if (mustProvide("lyxzerowidthspace"))
1511 macros << lyxZWSP_def << '\n';
1513 if (!usePolyglossia() && mustProvide("textgreek")) {
1514 // ensure LGR font encoding is defined also if fontenc is not loaded by LyX
1515 if (params_.main_font_encoding() == "default")
1516 macros << textgreek_LGR_def;
1517 macros << textgreek_def << '\n';
1520 if (!usePolyglossia() && mustProvide("textcyrillic")) {
1521 // ensure T2A font encoding is set up also if fontenc is not loaded by LyX
1522 if (params_.main_font_encoding() == "default")
1523 macros << textcyr_T2A_def;
1524 macros << textcyr_def << '\n';
1527 // non-standard text accents:
1528 if (mustProvide("textcommaabove") || mustProvide("textcommaaboveright") ||
1529 mustProvide("textcommabelow") || mustProvide("textbaltic"))
1530 macros << lyxaccent_def;
1532 if (mustProvide("textcommabelow") || mustProvide("textbaltic"))
1533 macros << textcommabelow_def << '\n';
1535 if (mustProvide("textcommaabove") || mustProvide("textbaltic"))
1536 macros << textcommaabove_def << '\n';
1538 if (mustProvide("textcommaaboveright"))
1539 macros << textcommaaboveright_def << '\n';
1541 if (mustProvide("textbaltic"))
1542 macros << textbaltic_def << '\n';
1544 if (mustProvide("textschwa"))
1545 macros << textschwa_def << '\n';
1547 // split-level fractions
1548 if (mustProvide("xfrac") || mustProvide("smallLetterFrac"))
1549 macros << xfrac_def << '\n';
1551 if (mustProvide("smallLetterFrac"))
1552 macros << smallLetterFrac_def << '\n';
1554 if (mustProvide("lyxmathsym"))
1555 macros << lyxmathsym_def << '\n';
1557 if (mustProvide("cedilla"))
1558 macros << cedilla_def << '\n';
1560 if (mustProvide("subring"))
1561 macros << subring_def << '\n';
1563 if (mustProvide("subdot"))
1564 macros << subdot_def << '\n';
1566 if (mustProvide("subhat"))
1567 macros << subhat_def << '\n';
1569 if (mustProvide("subtilde"))
1570 macros << subtilde_def << '\n';
1572 if (mustProvide("dacute"))
1573 macros << dacute_def << '\n';
1575 if (mustProvide("tipasymb"))
1576 macros << tipasymb_def << '\n';
1578 if (mustProvide("dgrave"))
1579 macros << dgrave_def << '\n';
1581 if (mustProvide("rcap"))
1582 macros << rcap_def << '\n';
1584 if (mustProvide("ogonek"))
1585 macros << ogonek_def << '\n';
1588 if (mustProvide("quotesinglbase"))
1589 macros << quotesinglbase_def << '\n';
1590 if (mustProvide("quotedblbase"))
1591 macros << quotedblbase_def << '\n';
1592 if (mustProvide("guilsinglleft"))
1593 macros << guilsinglleft_def << '\n';
1594 if (mustProvide("guilsinglright"))
1595 macros << guilsinglright_def << '\n';
1596 if (mustProvide("guillemotleft"))
1597 macros << guillemotleft_def << '\n';
1598 if (mustProvide("guillemotright"))
1599 macros << guillemotright_def << '\n';
1600 if (mustProvide("textquotedbl"))
1601 macros << textquotedbl_def << '\n';
1602 if (mustProvide("textquotesinglep")) {
1603 if (runparams_.flavor == OutputParams::XETEX)
1604 macros << textquotesinglep_xetex_def << '\n';
1606 macros << textquotesinglep_luatex_def << '\n';
1608 if (mustProvide("textquotedblp")) {
1609 if (runparams_.flavor == OutputParams::XETEX)
1610 macros << textquotedblp_xetex_def << '\n';
1612 macros << textquotedblp_luatex_def << '\n';
1616 if (mustProvide("binom") && !isRequired("amsmath"))
1617 macros << binom_def << '\n';
1618 if (mustProvide("mathcircumflex"))
1619 macros << mathcircumflex_def << '\n';
1622 if (mustProvide("ParagraphLeftIndent"))
1623 macros << paragraphleftindent_def;
1624 if (mustProvide("NeedLyXFootnoteCode"))
1625 macros << floatingfootnote_def;
1627 // some problems with tex->html converters
1628 if (mustProvide("NeedTabularnewline"))
1629 macros << tabularnewline_def;
1631 // greyed-out environment (note inset)
1632 // the color is specified in the routine
1633 // getColorOptions() to avoid LaTeX-package clashes
1634 if (mustProvide("lyxgreyedout")) {
1635 // We need different version for RTL (#8647)
1636 if (hasRTLLanguage()) {
1637 if (runparams_.flavor == OutputParams::LUATEX)
1639 macros << lyxgreyedout_luartl_babel_def;
1641 macros << lyxgreyedout_luartl_def;
1643 macros << lyxgreyedout_rtl_def;
1645 macros << lyxgreyedout_def;
1648 if (mustProvide("lyxdot"))
1649 macros << lyxdot_def << '\n';
1652 getFloatDefinitions(macros);
1654 if (mustProvide("refstyle"))
1655 macros << lyxref_def << '\n';
1658 if (mustProvide("ct-dvipost")) {
1659 if (isRequired("changebar"))
1660 macros << changetracking_dvipost_cb_def;
1662 macros << changetracking_dvipost_def;
1665 if (mustProvide("ct-xcolor-ulem")) {
1666 streamsize const prec = macros.os().precision(2);
1668 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
1669 macros << "\\providecolor{lyxadded}{rgb}{"
1670 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
1672 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
1673 macros << "\\providecolor{lyxdeleted}{rgb}{"
1674 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
1676 macros.os().precision(prec);
1678 if (isRequired("changebar")) {
1679 if (isRequired("hyperref"))
1680 macros << changetracking_xcolor_ulem_hyperref_cb_def;
1682 macros << changetracking_xcolor_ulem_cb_def;
1684 if (isRequired("hyperref"))
1685 macros << changetracking_xcolor_ulem_hyperref_def;
1687 macros << changetracking_xcolor_ulem_def;
1691 if (mustProvide("ct-tikz-math-sout"))
1692 macros << changetracking_tikz_math_sout_def;
1694 if (mustProvide("ct-none"))
1695 macros << changetracking_none_def;
1697 if (mustProvide("rtloutputdblcol"))
1698 macros << rtloutputdblcol_def;
1700 if (mustProvide("lyxmintcaption"))
1701 macros << lyxmintcaption_def;
1703 return macros.release();
1707 docstring const LaTeXFeatures::getBabelPresettings() const
1709 odocstringstream tmp;
1711 for (Language const * lang : UsedLanguages_)
1712 if (!lang->babel_presettings().empty())
1713 tmp << lang->babel_presettings() << '\n';
1714 if (!params_.language->babel_presettings().empty())
1715 tmp << params_.language->babel_presettings() << '\n';
1717 if (!contains(tmp.str(), '@'))
1720 return "\\makeatletter\n" + tmp.str() + "\\makeatother\n";
1724 docstring const LaTeXFeatures::getBabelPostsettings() const
1726 odocstringstream tmp;
1728 for (Language const * lang : UsedLanguages_)
1729 if (!lang->babel_postsettings().empty())
1730 tmp << lang->babel_postsettings() << '\n';
1731 if (!params_.language->babel_postsettings().empty())
1732 tmp << params_.language->babel_postsettings() << '\n';
1734 if (!contains(tmp.str(), '@'))
1737 return "\\makeatletter\n" + tmp.str() + "\\makeatother\n";
1741 string const LaTeXFeatures::loadAMSPackages() const
1745 if (mustProvide("amsmath")
1746 && params_.use_package("amsmath") != BufferParams::package_off) {
1747 tmp << "\\usepackage{amsmath}\n";
1749 // amsbsy and amstext are already provided by amsmath
1750 if (mustProvide("amsbsy"))
1751 tmp << "\\usepackage{amsbsy}\n";
1752 if (mustProvide("amstext"))
1753 tmp << "\\usepackage{amstext}\n";
1756 if (mustProvide("amsthm"))
1757 tmp << "\\usepackage{amsthm}\n";
1759 if (mustProvide("amssymb")
1760 && params_.use_package("amssymb") != BufferParams::package_off)
1761 tmp << "\\usepackage{amssymb}\n";
1767 docstring const LaTeXFeatures::getTClassPreamble() const
1769 // the text class specific preamble
1770 DocumentClass const & tclass = params_.documentClass();
1771 odocstringstream tcpreamble;
1773 tcpreamble << tclass.preamble();
1775 list<docstring>::const_iterator cit = usedLayouts_.begin();
1776 list<docstring>::const_iterator end = usedLayouts_.end();
1777 for (; cit != end; ++cit)
1778 // For InPreamble layouts, we output the preamble stuff earlier
1779 // (before the layouts). See Paragraph::Private::validate.
1780 if (!tclass[*cit].inpreamble)
1781 tcpreamble << tclass[*cit].preamble();
1783 cit = usedInsetLayouts_.begin();
1784 end = usedInsetLayouts_.end();
1785 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1786 for (; cit != end; ++cit) {
1787 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1788 if (it == ils.end())
1790 tcpreamble << it->second.preamble();
1793 return tcpreamble.str();
1797 docstring const LaTeXFeatures::getTClassHTMLPreamble() const
1799 DocumentClass const & tclass = params_.documentClass();
1800 odocstringstream tcpreamble;
1802 tcpreamble << tclass.htmlpreamble();
1804 list<docstring>::const_iterator cit = usedLayouts_.begin();
1805 list<docstring>::const_iterator end = usedLayouts_.end();
1806 for (; cit != end; ++cit)
1807 tcpreamble << tclass[*cit].htmlpreamble();
1809 cit = usedInsetLayouts_.begin();
1810 end = usedInsetLayouts_.end();
1811 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1812 for (; cit != end; ++cit) {
1813 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1814 if (it == ils.end())
1816 tcpreamble << it->second.htmlpreamble();
1819 return tcpreamble.str();
1823 docstring const LaTeXFeatures::getTClassHTMLStyles() const
1825 DocumentClass const & tclass = params_.documentClass();
1826 odocstringstream tcpreamble;
1828 if (mustProvide("noun"))
1829 tcpreamble << lyxnoun_style;
1830 // this isn't exact, but it won't hurt that much if it
1832 if (mustProvide("ulem"))
1833 tcpreamble << lyxstrikeout_style;
1835 tcpreamble << tclass.htmlstyles();
1837 list<docstring>::const_iterator cit = usedLayouts_.begin();
1838 list<docstring>::const_iterator end = usedLayouts_.end();
1839 for (; cit != end; ++cit)
1840 tcpreamble << tclass[*cit].htmlstyle();
1842 cit = usedInsetLayouts_.begin();
1843 end = usedInsetLayouts_.end();
1844 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
1845 for (; cit != end; ++cit) {
1846 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
1847 if (it == ils.end())
1849 tcpreamble << it->second.htmlstyle();
1852 return tcpreamble.str();
1858 docstring const getFloatI18nPreamble(docstring const & type,
1859 docstring const & name, Language const * lang,
1860 Encoding const & enc, bool const polyglossia)
1862 // Check whether name can be encoded in the buffer encoding
1863 bool encodable = true;
1864 for (size_t i = 0; i < name.size(); ++i) {
1865 if (!enc.encodable(name[i])) {
1871 docstring const language = polyglossia ? from_ascii(lang->polyglossia())
1872 : from_ascii(lang->babel());
1873 docstring const langenc = from_ascii(lang->encoding()->iconvName());
1874 docstring const texenc = from_ascii(lang->encoding()->latexName());
1875 docstring const bufenc = from_ascii(enc.iconvName());
1876 docstring const s1 = docstring(1, 0xF0000);
1877 docstring const s2 = docstring(1, 0xF0001);
1878 docstring const translated = encodable ? name
1879 : from_ascii("\\inputencoding{") + texenc + from_ascii("}")
1880 + s1 + langenc + s2 + name + s1 + bufenc + s2;
1882 odocstringstream os;
1883 os << "\\addto\\captions" << language
1884 << "{\\renewcommand{\\" << type << "name}{" << translated << "}}\n";
1889 docstring const i18npreamble(docstring const & templ, Language const * lang,
1890 Encoding const & enc, bool const polyglossia,
1891 bool const need_fixedwidth)
1896 string preamble = polyglossia ?
1897 subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
1898 subst(to_utf8(templ), "$$lang", lang->babel());
1900 string const langenc = lang->encoding()->iconvName();
1901 string const texenc = lang->encoding()->latexName();
1902 string const bufenc = enc.iconvName();
1903 Encoding const * testenc(&enc);
1904 bool lang_fallback = false;
1905 bool ascii_fallback = false;
1906 if (need_fixedwidth && !enc.hasFixedWidth()) {
1907 if (lang->encoding()->hasFixedWidth()) {
1908 testenc = lang->encoding();
1909 lang_fallback = true;
1911 // We need a fixed width encoding, but both the buffer
1912 // encoding and the language encoding are variable
1913 // width. As a last fallback, try to convert to pure
1914 // ASCII using the LaTeX commands defined in unicodesymbols.
1915 testenc = encodings.fromLyXName("ascii");
1918 ascii_fallback = true;
1921 // First and second character of plane 15 (Private Use Area)
1922 string const s1 = "\xf3\xb0\x80\x80"; // U+F0000
1923 string const s2 = "\xf3\xb0\x80\x81"; // U+F0001
1925 // lyx::regex is not unicode-safe.
1926 // Should use QRegExp or (boost::u32regex, but that requires ICU)
1927 static regex const reg("_\\(([^\\)]+)\\)");
1929 while (regex_search(preamble, sub, reg)) {
1930 string const key = sub.str(1);
1931 docstring const name = lang->translateLayout(key);
1932 // Check whether name can be encoded in the buffer encoding
1933 bool encodable = true;
1934 for (size_t i = 0; i < name.size() && encodable; ++i)
1935 if (!testenc->encodable(name[i]))
1938 if (encodable && !lang_fallback)
1939 translated = to_utf8(name);
1940 else if (ascii_fallback)
1941 translated = to_ascii(testenc->latexString(name).first);
1943 translated = "\\inputencoding{" + texenc + "}"
1944 + s1 + langenc + s2 + to_utf8(name)
1946 preamble = subst(preamble, sub.str(), translated);
1948 return from_utf8(preamble);
1954 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel,
1955 bool use_polyglossia, bool use_minted) const
1957 DocumentClass const & tclass = params_.documentClass();
1958 // collect preamble snippets in a set to prevent multiple identical
1959 // commands (would happen if e.g. both theorem and theorem* are used)
1960 set<docstring> snippets;
1961 typedef LanguageList::const_iterator lang_it;
1962 lang_it const lbeg = UsedLanguages_.begin();
1963 lang_it const lend = UsedLanguages_.end();
1964 list<docstring>::const_iterator cit = usedLayouts_.begin();
1965 list<docstring>::const_iterator end = usedLayouts_.end();
1966 for (; cit != end; ++cit) {
1967 // language dependent commands (once per document)
1968 snippets.insert(i18npreamble(tclass[*cit].langpreamble(),
1969 buffer().language(),
1970 buffer().params().encoding(),
1971 use_polyglossia, false));
1972 // commands for language changing (for multilanguage documents)
1973 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1974 snippets.insert(i18npreamble(
1975 tclass[*cit].babelpreamble(),
1976 buffer().language(),
1977 buffer().params().encoding(),
1978 use_polyglossia, false));
1979 for (lang_it lit = lbeg; lit != lend; ++lit)
1980 snippets.insert(i18npreamble(
1981 tclass[*cit].babelpreamble(),
1983 buffer().params().encoding(),
1984 use_polyglossia, false));
1987 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
1988 FloatList const & floats = params_.documentClass().floats();
1989 UsedFloats::const_iterator fit = usedFloats_.begin();
1990 UsedFloats::const_iterator fend = usedFloats_.end();
1991 for (; fit != fend; ++fit) {
1992 Floating const & fl = floats.getType(fit->first);
1993 // we assume builtin floats are translated
1994 if (fl.isPredefined())
1996 docstring const type = from_ascii(fl.floattype());
1997 docstring const flname = from_utf8(fl.name());
1998 docstring name = buffer().language()->translateLayout(fl.name());
1999 // only request translation if we have a real translation
2000 // (that differs from the source)
2002 snippets.insert(getFloatI18nPreamble(
2003 type, name, buffer().language(),
2004 buffer().params().encoding(),
2006 for (lang_it lit = lbeg; lit != lend; ++lit) {
2007 string const code = (*lit)->code();
2008 name = (*lit)->translateLayout(fl.name());
2009 // we assume we have a suitable translation if
2010 // either the language is English (we need to
2011 // translate into English if English is a secondary
2012 // language) or if translateIfPossible returns
2013 // something different to the English source.
2014 bool const have_translation =
2015 (flname != name || contains(code, "en"));
2016 if (have_translation)
2017 snippets.insert(getFloatI18nPreamble(
2019 buffer().params().encoding(),
2025 cit = usedInsetLayouts_.begin();
2026 end = usedInsetLayouts_.end();
2027 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
2028 for (; cit != end; ++cit) {
2029 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
2030 if (it == ils.end())
2032 // The listings package does not work with variable width
2033 // encodings, only with fixed width encodings. Therefore we
2034 // need to force a fixed width encoding for
2035 // \lstlistlistingname and \lstlistingname (bug 9382).
2036 // This needs to be consistent with InsetListings::latex()
2037 // rsp. InsetListings::forcedEncoding().
2038 bool const need_fixedwidth = !use_minted &&
2039 !runparams_.isFullUnicode() &&
2040 buffer().params().encoding().package() != Encoding::japanese &&
2041 it->second.fixedwidthpreambleencoding();
2042 // language dependent commands (once per document)
2043 snippets.insert(i18npreamble(it->second.langpreamble(),
2044 buffer().language(),
2045 buffer().params().encoding(),
2046 use_polyglossia, need_fixedwidth));
2047 // commands for language changing (for multilanguage documents)
2048 if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
2049 snippets.insert(i18npreamble(
2050 it->second.babelpreamble(),
2051 buffer().language(),
2052 buffer().params().encoding(),
2053 use_polyglossia, need_fixedwidth));
2054 for (lang_it lit = lbeg; lit != lend; ++lit)
2055 snippets.insert(i18npreamble(
2056 it->second.babelpreamble(),
2058 buffer().params().encoding(),
2059 use_polyglossia, need_fixedwidth));
2063 odocstringstream tcpreamble;
2064 set<docstring>::const_iterator const send = snippets.end();
2065 set<docstring>::const_iterator it = snippets.begin();
2066 for (; it != send; ++it)
2068 return tcpreamble.str();
2072 docstring const LaTeXFeatures::getLyXSGMLEntities() const
2074 // Definition of entities used in the document that are LyX related.
2075 odocstringstream entities;
2077 if (mustProvide("lyxarrow")) {
2078 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
2081 return entities.str();
2085 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
2087 odocstringstream sgmlpreamble;
2089 docstring const basename(from_utf8(onlyPath(fname)));
2091 FileMap::const_iterator end = IncludedFiles_.end();
2092 for (FileMap::const_iterator fi = IncludedFiles_.begin();
2095 sgmlpreamble << "\n<!ENTITY " << fi->first
2096 << (isSGMLFileName(fi->second) ? " SYSTEM \"" : " \"")
2097 << makeRelPath(from_utf8(fi->second), basename) << "\">";
2099 return sgmlpreamble.str();
2103 void LaTeXFeatures::showStruct() const
2105 lyxerr << "LyX needs the following commands when LaTeXing:"
2106 << "\n***** Packages:" << getPackages()
2107 << "\n***** Macros:" << to_utf8(getMacros().str)
2108 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
2109 << "\n***** done." << endl;
2113 Buffer const & LaTeXFeatures::buffer() const
2119 void LaTeXFeatures::setBuffer(Buffer const & buffer)
2125 BufferParams const & LaTeXFeatures::bufferParams() const
2131 void LaTeXFeatures::getFloatDefinitions(otexstream & os) const
2133 FloatList const & floats = params_.documentClass().floats();
2135 // Here we will output the code to create the needed float styles.
2136 // We will try to do this as minimal as possible.
2137 // \floatstyle{ruled}
2138 // \newfloat{algorithm}{htbp}{loa}
2139 // \providecommand{\algorithmname}{Algorithm}
2140 // \floatname{algorithm}{\protect\algorithmname}
2141 UsedFloats::const_iterator cit = usedFloats_.begin();
2142 UsedFloats::const_iterator end = usedFloats_.end();
2143 for (; cit != end; ++cit) {
2144 Floating const & fl = floats.getType(cit->first);
2146 // For builtin floats we do nothing.
2147 if (fl.isPredefined())
2150 // We have to special case "table" and "figure"
2151 if (fl.floattype() == "tabular" || fl.floattype() == "figure") {
2152 // Output code to modify "table" or "figure"
2153 // but only if builtin == false
2154 // and that have to be true at this point in the
2156 docstring const type = from_ascii(fl.floattype());
2157 docstring const placement = from_ascii(fl.placement());
2158 docstring const style = from_ascii(fl.style());
2159 if (!style.empty()) {
2160 os << "\\floatstyle{" << style << "}\n"
2161 << "\\restylefloat{" << type << "}\n";
2163 if (!placement.empty()) {
2164 os << "\\floatplacement{" << type << "}{"
2165 << placement << "}\n";
2168 // The other non builtin floats.
2170 docstring const type = from_ascii(fl.floattype());
2171 docstring const placement = from_ascii(fl.placement());
2172 docstring const ext = from_ascii(fl.ext());
2173 docstring const within = from_ascii(fl.within());
2174 docstring const style = from_ascii(fl.style());
2175 docstring const name =
2176 buffer().language()->translateLayout(fl.name());
2177 os << "\\floatstyle{" << style << "}\n"
2178 << "\\newfloat{" << type << "}{" << placement
2179 << "}{" << ext << '}';
2180 if (!within.empty())
2181 os << '[' << within << ']';
2183 << "\\providecommand{\\" << type << "name}{"
2185 << "\\floatname{" << type << "}{\\protect\\"
2186 << type << "name}\n";
2188 // What missing here is to code to minimalize the code
2189 // output so that the same floatstyle will not be
2190 // used several times, when the same style is still in
2194 // The subfig package is loaded later
2195 os << "\n\\AtBeginDocument{\\newsubfloat{" << from_ascii(fl.floattype()) << "}}\n";
2200 void LaTeXFeatures::resolveAlternatives()
2202 for (Features::iterator it = features_.begin(); it != features_.end();) {
2203 if (contains(*it, '|')) {
2204 vector<string> const alternatives = getVectorFromString(*it, "|");
2205 vector<string>::const_iterator const end = alternatives.end();
2206 vector<string>::const_iterator ita = alternatives.begin();
2207 // Is any alternative already required? => use that
2208 for (; ita != end; ++ita) {
2209 if (isRequired(*ita))
2212 // Is any alternative available? => use the first one
2215 for (ita = alternatives.begin(); ita != end; ++ita) {
2216 if (isAvailable(*ita)) {
2222 // This will not work, but not requiring something
2223 // would be more confusing
2225 require(alternatives.front());
2226 features_.erase(it);
2227 it = features_.begin();
2234 void LaTeXFeatures::expandMultiples()
2236 for (Features::iterator it = features_.begin(); it != features_.end();) {
2237 if (contains(*it, ',')) {
2238 vector<string> const multiples = getVectorFromString(*it, ",");
2239 vector<string>::const_iterator const end = multiples.end();
2240 vector<string>::const_iterator itm = multiples.begin();
2241 // Do nothing if any multiple is already required
2242 for (; itm != end; ++itm) {
2243 if (!isRequired(*itm))
2246 features_.erase(it);
2247 it = features_.begin();