2 * \file LaTeXFeatures.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
17 #include "LaTeXFeatures.h"
20 #include "BufferParams.h"
22 #include "Converter.h"
25 #include "FloatList.h"
30 #include "TextClass.h"
32 #include "insets/InsetLayout.h"
34 #include "support/debug.h"
35 #include "support/docstream.h"
36 #include "support/FileName.h"
37 #include "support/filetools.h"
38 #include "support/lstrings.h"
41 using namespace lyx::support;
46 /////////////////////////////////////////////////////////////////////
50 /////////////////////////////////////////////////////////////////////
52 //\NeedsTeXFormat{LaTeX2e}
53 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
54 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
56 static string const lyx_def =
57 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}";
59 static string const lyxline_def =
60 "\\newcommand{\\lyxline}[1][1pt]{%\n"
62 " \\rule[.5ex]{\\linewidth}{#1}\\par}";
64 static string const noun_def = "\\newcommand{\\noun}[1]{\\textsc{#1}}";
66 static string const lyxarrow_def =
67 "\\DeclareRobustCommand*{\\lyxarrow}{%\n"
69 "{\\leavevmode\\,$\\triangleleft$\\,\\allowbreak}\n"
70 "{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}}";
72 // for quotes without babel. This does not give perfect results, but
73 // anybody serious about non-english quotes should use babel (JMarc).
75 static string const quotedblbase_def =
76 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
77 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
78 " \\penalty10000\\hskip0em\\relax%\n"
81 static string const quotesinglbase_def =
82 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
83 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
84 " \\penalty10000\\hskip0em\\relax%\n"
87 static string const guillemotleft_def =
88 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
89 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
90 "\\penalty10000\\hskip0pt\\relax%\n"
93 static string const guillemotright_def =
94 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
95 " \\penalty10000\\hskip0pt%\n"
96 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
99 static string const guilsinglleft_def =
100 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
101 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
102 " \\penalty10000\\hskip0pt\\relax%\n"
105 static string const guilsinglright_def =
106 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
107 " \\penalty10000\\hskip0pt%\n"
108 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
111 static string const paragraphleftindent_def =
112 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
114 " \\begin{list}{}{%\n"
115 " \\setlength{\\topsep}{0pt}%\n"
116 " \\addtolength{\\leftmargin}{#1}\n"
117 // ho hum, yet more things commented out with no hint as to why they
118 // weren't just removed
119 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
120 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
121 // "%% \\setlength\\listparindent\\parindent%\n"
122 // "%% \\setlength\\itemindent\\parindent%\n"
123 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
129 static string const floatingfootnote_def =
130 "%% Special footnote code from the package 'stblftnt.sty'\n"
131 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
132 "\\let\\SF@@footnote\\footnote\n"
133 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
134 " \\expandafter\\SF@@footnote\n"
136 " \\expandafter\\SF@gobble@opt\n"
139 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
140 " \\SF@gobble@twobracket\n"
143 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
144 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
145 "\\def\\SF@gobble@twobracket[#1]#2{}\n";
147 static string const binom_def =
148 "%% Binom macro for standard LaTeX users\n"
149 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n";
151 static string const mathcircumflex_def =
152 "%% For printing a cirumflex inside a formula\n"
153 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n";
155 static string const tabularnewline_def =
156 "%% Because html converters don't know tabularnewline\n"
157 "\\providecommand{\\tabularnewline}{\\\\}\n";
159 static string const lyxgreyedout_def =
160 "%% The greyedout annotation environment\n"
161 "\\newenvironment{lyxgreyedout}{\\textcolor[gray]{0.8}\\bgroup}{\\egroup}\n";
163 // We want to omit the file extension for includegraphics, but this does not
164 // work when the filename contains other dots.
165 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
166 static string const lyxdot_def =
167 "%% A simple dot to overcome graphicx limitations\n"
168 "\\newcommand{\\lyxdot}{.}\n";
170 static string const changetracking_dvipost_def =
171 "%% Change tracking with dvipost\n"
173 "\\dvipost{osstart color push Red}\n"
174 "\\dvipost{osend color pop}\n"
175 "\\dvipost{cbstart color push Blue}\n"
176 "\\dvipost{cbend color pop}\n"
177 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
178 "\\newcommand{\\lyxdeleted}[3]{%\n"
179 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n";
181 static string const changetracking_xcolor_ulem_def =
182 "%% Change tracking with ulem\n"
183 "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
184 "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n";
186 static string const changetracking_xcolor_ulem_hyperref_def =
187 "%% Change tracking with ulem\n"
188 "\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}}{}#3}}\n"
189 "\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n";
191 static string const changetracking_none_def =
192 "\\newcommand{\\lyxadded}[3]{#3}\n"
193 "\\newcommand{\\lyxdeleted}[3]{}\n";
195 static string const textgreek_def =
196 "\\DeclareRobustCommand{\\greektext}{%\n"
197 " \\fontencoding{LGR}\\selectfont\\def\\encodingdefault{LGR}}\n"
198 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
199 "\\DeclareFontEncoding{LGR}{}{}\n";
201 static string const textcyr_def =
202 "\\DeclareRobustCommand{\\cyrtext}{%\n"
203 " \\fontencoding{T2A}\\selectfont\\def\\encodingdefault{T2A}}\n"
204 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
205 "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n";
207 static string const lyxmathsym_def =
208 "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
209 " \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n";
211 static string const papersizedvi_def =
212 "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n";
214 static string const papersizepdf_def =
215 "\\pdfpageheight\\paperheight\n"
216 "\\pdfpagewidth\\paperwidth\n";
218 static string const cedilla_def =
219 "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
220 "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n";
222 static string const subring_def =
223 "\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
224 "\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n";
226 static string const subdot_def =
227 "\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
228 "\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n";
230 static string const subhat_def =
231 "\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
232 "\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n";
234 static string const subtilde_def =
235 "\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
236 "\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n";
238 static string const dacute_def =
239 "\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n";
241 static string const tipasymb_def =
242 "\\DeclareFontEncoding{T3}{}{}\n"
243 "\\DeclareSymbolFont{tipasymb}{T3}{cmr}{m}{n}\n";
245 static string const dgrave_def =
246 "\\DeclareMathAccent{\\dgrave}{\\mathord}{tipasymb}{'15}\n";
248 static string const rcap_def =
249 "\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n";
251 static string const ogonek_def =
252 "\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
253 " \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
254 " \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
255 " \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
256 "\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n";
258 /////////////////////////////////////////////////////////////////////
262 /////////////////////////////////////////////////////////////////////
264 LaTeXFeatures::Packages LaTeXFeatures::packages_;
267 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
268 OutputParams const & r)
269 : buffer_(&b), params_(p), runparams_(r), in_float_(false)
273 bool LaTeXFeatures::useBabel() const
275 return lyxrc.language_use_babel ||
276 (bufferParams().language->lang() != lyxrc.default_language &&
277 !bufferParams().language->babel().empty()) ||
278 this->hasLanguages();
282 void LaTeXFeatures::require(string const & name)
284 features_.insert(name);
288 void LaTeXFeatures::require(set<string> const & names)
290 features_.insert(names.begin(), names.end());
294 void LaTeXFeatures::getAvailable()
297 support::FileName const real_file = libFileSearch("", "packages.lst");
299 if (real_file.empty())
302 lex.setFile(real_file);
307 // Make sure that we are clean
310 bool finished = false;
312 while (lex.isOK() && !finished) {
314 case Lexer::LEX_FEOF:
318 packages_.insert(lex.getString());
324 void LaTeXFeatures::useLayout(docstring const & layoutname)
326 // Some code to avoid loops in dependency definition
327 static int level = 0;
328 const int maxlevel = 30;
329 if (level > maxlevel) {
330 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
331 << "recursion attained by layout "
332 << to_utf8(layoutname) << endl;
336 DocumentClass const & tclass = params_.documentClass();
337 if (tclass.hasLayout(layoutname)) {
338 // Is this layout already in usedLayouts?
339 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
340 != usedLayouts_.end())
343 Layout const & layout = tclass[layoutname];
344 require(layout.requires());
346 if (!layout.depends_on().empty()) {
348 useLayout(layout.depends_on());
351 usedLayouts_.push_back(layoutname);
353 lyxerr << "LaTeXFeatures::useLayout: layout `"
354 << to_utf8(layoutname) << "' does not exist in this class"
362 void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
364 docstring const & lname = lay.name();
365 DocumentClass const & tclass = params_.documentClass();
366 if (!tclass.hasInsetLayout(lname)) {
367 lyxerr << "LaTeXFeatures::useInsetLayout: layout `"
368 << to_utf8(lname) << "' does not exist in this class"
372 // Is this layout already in usedInsetLayouts?
373 if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
374 != usedInsetLayouts_.end())
377 require(lay.requires());
378 usedInsetLayouts_.push_back(lname);
382 bool LaTeXFeatures::isRequired(string const & name) const
384 return features_.find(name) != features_.end();
388 bool LaTeXFeatures::mustProvide(string const & name) const
390 return isRequired(name) && !params_.documentClass().provides(name);
394 bool LaTeXFeatures::isAvailable(string const & name)
396 string::size_type const i = name.find("->");
397 if (i != string::npos) {
398 string const from = name.substr(0,i);
399 string const to = name.substr(i+2);
400 LYXERR0("from=[" << from << "] to=[" << to << "]");
401 return theConverters().isReachable(from, to);
404 if (packages_.empty())
407 if (suffixIs(n, ".sty"))
408 n.erase(name.length() - 4);
409 return packages_.find(n) != packages_.end();
413 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
415 SnippetList::const_iterator begin = preamble_snippets_.begin();
416 SnippetList::const_iterator end = preamble_snippets_.end();
417 if (find(begin, end, preamble) == end)
418 preamble_snippets_.push_back(preamble);
422 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
424 if (!usedFloats_[name])
425 usedFloats_[name] = subfloat;
428 // We only need float.sty if we use non builtin floats, or if we
429 // use the "H" modifier. This includes modified table and
430 // figure floats. (Lgb)
431 Floating const & fl = params_.documentClass().floats().getType(name);
432 if (!fl.type().empty() && !fl.builtin()) {
438 void LaTeXFeatures::useLanguage(Language const * lang)
440 if (!lang->babel().empty())
441 UsedLanguages_.insert(lang);
442 if (lang->lang() == "vietnamese")
443 require("vietnamese");
444 // CJK languages do not have a babel name.
445 // They use the CJK package
446 if (lang->encoding()->package() == Encoding::CJK)
448 // japanese package is special
449 if (lang->encoding()->package() == Encoding::japanese)
454 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
456 IncludedFiles_[key] = name;
460 bool LaTeXFeatures::hasLanguages() const
462 return !UsedLanguages_.empty();
466 string LaTeXFeatures::getLanguages() const
468 ostringstream languages;
470 LanguageList::const_iterator const begin = UsedLanguages_.begin();
471 for (LanguageList::const_iterator cit = begin;
472 cit != UsedLanguages_.end();
476 languages << (*cit)->babel();
478 return languages.str();
482 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
484 // This does only find encodings of languages supported by babel, but
485 // that does not matter since we don't have a language with an
486 // encoding supported by inputenc but without babel support.
487 set<string> encodings;
488 LanguageList::const_iterator it = UsedLanguages_.begin();
489 LanguageList::const_iterator end = UsedLanguages_.end();
490 for (; it != end; ++it)
491 if ((*it)->encoding()->latexName() != doc_encoding &&
492 ((*it)->encoding()->package() == Encoding::inputenc
493 || (*it)->encoding()->package() == Encoding::japanese))
494 encodings.insert((*it)->encoding()->latexName());
500 char const * simplefeatures[] = {
501 // note that the package order here will be the same in the LaTeX-output
508 // subfig is handled in BufferParams.cpp
511 /*For a successful cooperation of the `wrapfig' package with the
512 `float' package you should load the `wrapfig' package *after*
513 the `float' package. See the caption package documentation
542 // listings is handled in BufferParams.cpp
549 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
554 string const LaTeXFeatures::getColorOptions() const
556 ostringstream colors;
558 // Handling the color packages separately is needed to be able to load them
559 // before babel when hyperref is loaded with the colorlinks option
560 // for more info see Bufferparams.cpp
563 if (mustProvide("color") || mustProvide("xcolor")) {
564 string const package =
565 (mustProvide("xcolor") ? "xcolor" : "color");
566 if (params_.graphicsDriver == "default"
567 || params_.graphicsDriver == "none")
568 colors << "\\usepackage{" << package << "}\n";
570 colors << "\\usepackage["
571 << params_.graphicsDriver
572 << "]{" << package << "}\n";
575 // pdfcolmk must be loaded after color
576 if (mustProvide("pdfcolmk"))
577 colors << "\\usepackage{pdfcolmk}\n";
579 if (mustProvide("pagecolor")) {
580 // the \pagecolor command must be set after color is loaded and
581 // before pdfpages, therefore add the command here
582 // define the set color
583 colors << "\\definecolor{page_backgroundcolor}{rgb}{";
584 colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
585 // set the page color
586 colors << "\\pagecolor{page_backgroundcolor}\n";
593 string const LaTeXFeatures::getPackages() const
595 ostringstream packages;
596 DocumentClass const & tclass = params_.documentClass();
598 // FIXME: currently, we can only load packages and macros known
600 // However, with the Require tag of layouts/custom insets,
601 // also inknown packages can be requested. They are silently
602 // swallowed now. We should change this eventually.
605 // These are all the 'simple' includes. i.e
606 // packages which we just \usepackage{package}
608 for (int i = 0; i < nb_simplefeatures; ++i) {
609 if (mustProvide(simplefeatures[i]))
610 packages << "\\usepackage{"
611 << simplefeatures[i] << "}\n";
615 // The rest of these packages are somewhat more complicated
619 // esint is preferred for esintoramsmath
620 if ((mustProvide("amsmath")
621 && params_.use_amsmath != BufferParams::package_off)
622 || (mustProvide("esintoramsmath")
623 && params_.use_esint == BufferParams::package_off
624 && params_.use_amsmath != BufferParams::package_off)) {
625 packages << "\\usepackage{amsmath}\n";
627 // amsbsy and amstext are already provided by amsmath
628 if (mustProvide("amsbsy"))
629 packages << "\\usepackage{amsbsy}\n";
630 if (mustProvide("amstext"))
631 packages << "\\usepackage{amstext}\n";
634 // wasysym is a simple feature, but it must be after amsmath if both
636 // wasysym redefines some integrals (e.g. iint) from amsmath. That
637 // leads to inconsistent integrals. We only load this package if
638 // the document does not contain integrals (then isRequired("esint")
639 // is false) or if esint is used, since esint redefines all relevant
640 // integral symbols from wasysym and amsmath.
641 // See http://bugzilla.lyx.org/show_bug.cgi?id=1942
642 if (mustProvide("wasysym") &&
643 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
644 packages << "\\usepackage{wasysym}\n";
646 // accents must be loaded after amsmath
647 if (mustProvide("accents"))
648 packages << "\\usepackage{accents}\n";
650 // [x]color and pdfcolmk are handled in getColorOptions() above
653 if (isRequired("makeidx") || isRequired("splitidx")) {
654 if (!tclass.provides("makeidx") && !isRequired("splitidx"))
655 packages << "\\usepackage{makeidx}\n";
656 if (!tclass.provides("splitidx") && isRequired("splitidx"))
657 packages << "\\usepackage{splitidx}\n";
658 packages << "\\makeindex\n";
662 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
663 if (params_.graphicsDriver == "default")
664 packages << "\\usepackage{graphicx}\n";
666 packages << "\\usepackage["
667 << params_.graphicsDriver
670 // shadecolor for shaded
671 if (isRequired("framed") && mustProvide("color")) {
672 RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
673 //255.0 to force conversion to double
674 //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
675 //to use the xcolor package instead, and then we can do
676 // \define{shadcolor}{RGB}...
677 //and not do any conversion. We'd then need to require xcolor
678 //in InsetNote::validate().
679 int const stmSize = packages.precision(2);
680 packages << "\\definecolor{shadecolor}{rgb}{"
681 << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
682 packages.precision(stmSize);
685 // lyxskak.sty --- newer chess support based on skak.sty
686 if (mustProvide("chess"))
687 packages << "\\usepackage[ps,mover]{lyxskak}\n";
690 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
691 packages << "\\usepackage{setspace}\n";
694 if (mustProvide("amssymb")
695 || params_.use_amsmath == BufferParams::package_on)
696 packages << "\\usepackage{amssymb}\n";
698 // esint must be after amsmath and wasysym, since it will redeclare
699 // inconsistent integral symbols
700 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
701 params_.use_esint != BufferParams::package_off)
702 packages << "\\usepackage{esint}\n";
705 // Some classes load natbib themselves, but still allow (or even require)
706 // plain numeric citations (ReVTeX is such a case, see bug 5182).
707 // This special case is indicated by the "natbib-internal" key.
708 if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
709 packages << "\\usepackage[";
710 if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
711 packages << "numbers";
713 packages << "authoryear";
714 packages << "]{natbib}\n";
717 // jurabib -- we need version 0.6 at least.
718 if (mustProvide("jurabib"))
719 packages << "\\usepackage{jurabib}[2004/01/25]\n";
721 // xargs -- we need version 1.09 at least
722 if (mustProvide("xargs"))
723 packages << "\\usepackage{xargs}[2008/03/08]\n";
725 // bibtopic -- the dot provides the aux file naming which
727 if (mustProvide("bibtopic"))
728 packages << "\\usepackage[dot]{bibtopic}\n";
730 if (mustProvide("xy"))
731 packages << "\\usepackage[all]{xy}\n";
733 if (mustProvide("ulem"))
734 packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
735 "\\usepackage{ulem}\n";
737 if (mustProvide("nomencl")) {
738 // Make it work with the new and old version of the package,
739 // but don't use the compatibility option since it is
740 // incompatible to other packages.
741 packages << "\\usepackage{nomencl}\n"
742 "% the following is useful when we have the old nomencl.sty package\n"
743 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
744 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
745 "\\makenomenclature\n";
748 return packages.str();
752 string const LaTeXFeatures::getMacros() const
754 ostringstream macros;
756 if (!preamble_snippets_.empty())
758 SnippetList::const_iterator pit = preamble_snippets_.begin();
759 SnippetList::const_iterator pend = preamble_snippets_.end();
760 for (; pit != pend; ++pit)
761 macros << *pit << '\n';
763 if (mustProvide("papersize")) {
764 if (runparams_.flavor == OutputParams::LATEX)
765 macros << papersizedvi_def << '\n';
767 macros << papersizepdf_def << '\n';
770 if (mustProvide("LyX"))
771 macros << lyx_def << '\n';
773 if (mustProvide("lyxline"))
774 macros << lyxline_def << '\n';
776 if (mustProvide("noun"))
777 macros << noun_def << '\n';
779 if (mustProvide("lyxarrow"))
780 macros << lyxarrow_def << '\n';
782 if (mustProvide("textgreek"))
783 macros << textgreek_def << '\n';
785 if (mustProvide("textcyr"))
786 macros << textcyr_def << '\n';
788 if (mustProvide("lyxmathsym"))
789 macros << lyxmathsym_def << '\n';
791 if (mustProvide("cedilla"))
792 macros << cedilla_def << '\n';
794 if (mustProvide("subring"))
795 macros << subring_def << '\n';
797 if (mustProvide("subdot"))
798 macros << subdot_def << '\n';
800 if (mustProvide("subhat"))
801 macros << subhat_def << '\n';
803 if (mustProvide("subtilde"))
804 macros << subtilde_def << '\n';
806 if (mustProvide("dacute"))
807 macros << dacute_def << '\n';
809 if (mustProvide("tipasymb"))
810 macros << tipasymb_def << '\n';
812 if (mustProvide("dgrave"))
813 macros << dgrave_def << '\n';
815 if (mustProvide("rcap"))
816 macros << rcap_def << '\n';
818 if (mustProvide("ogonek"))
819 macros << ogonek_def << '\n';
822 if (mustProvide("quotesinglbase"))
823 macros << quotesinglbase_def << '\n';
824 if (mustProvide("quotedblbase"))
825 macros << quotedblbase_def << '\n';
826 if (mustProvide("guilsinglleft"))
827 macros << guilsinglleft_def << '\n';
828 if (mustProvide("guilsinglright"))
829 macros << guilsinglright_def << '\n';
830 if (mustProvide("guillemotleft"))
831 macros << guillemotleft_def << '\n';
832 if (mustProvide("guillemotright"))
833 macros << guillemotright_def << '\n';
836 if (mustProvide("binom") && !isRequired("amsmath"))
837 macros << binom_def << '\n';
838 if (mustProvide("mathcircumflex"))
839 macros << mathcircumflex_def << '\n';
842 if (mustProvide("ParagraphLeftIndent"))
843 macros << paragraphleftindent_def;
844 if (mustProvide("NeedLyXFootnoteCode"))
845 macros << floatingfootnote_def;
847 // some problems with tex->html converters
848 if (mustProvide("NeedTabularnewline"))
849 macros << tabularnewline_def;
851 // greyedout environment (note inset)
852 if (mustProvide("lyxgreyedout"))
853 macros << lyxgreyedout_def;
855 if (mustProvide("lyxdot"))
856 macros << lyxdot_def << '\n';
859 getFloatDefinitions(macros);
862 if (mustProvide("ct-dvipost"))
863 macros << changetracking_dvipost_def;
865 if (mustProvide("ct-xcolor-ulem")) {
866 int const prec = macros.precision(2);
868 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
869 macros << "\\providecolor{lyxadded}{rgb}{"
870 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
872 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
873 macros << "\\providecolor{lyxdeleted}{rgb}{"
874 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
876 macros.precision(prec);
878 if (isRequired("hyperref"))
879 macros << changetracking_xcolor_ulem_hyperref_def;
881 macros << changetracking_xcolor_ulem_def;
884 if (mustProvide("ct-none"))
885 macros << changetracking_none_def;
891 string const LaTeXFeatures::getBabelOptions() const
895 LanguageList::const_iterator it = UsedLanguages_.begin();
896 LanguageList::const_iterator end = UsedLanguages_.end();
897 for (; it != end; ++it)
898 if (!(*it)->latex_options().empty())
899 tmp << (*it)->latex_options() << '\n';
900 if (!params_.language->latex_options().empty())
901 tmp << params_.language->latex_options() << '\n';
907 docstring const LaTeXFeatures::getTClassPreamble() const
909 // the text class specific preamble
910 DocumentClass const & tclass = params_.documentClass();
911 odocstringstream tcpreamble;
913 tcpreamble << tclass.preamble();
915 list<docstring>::const_iterator cit = usedLayouts_.begin();
916 list<docstring>::const_iterator end = usedLayouts_.end();
917 for (; cit != end; ++cit)
918 tcpreamble << tclass[*cit].preamble();
920 cit = usedInsetLayouts_.begin();
921 end = usedInsetLayouts_.end();
922 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
923 for (; cit != end; ++cit) {
924 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
927 tcpreamble << it->second.preamble();
930 return tcpreamble.str();
934 docstring const LaTeXFeatures::getTClassHTMLPreamble() const {
935 DocumentClass const & tclass = params_.documentClass();
936 odocstringstream tcpreamble;
938 tcpreamble << tclass.htmlpreamble();
940 list<docstring>::const_iterator cit = usedLayouts_.begin();
941 list<docstring>::const_iterator end = usedLayouts_.end();
942 for (; cit != end; ++cit)
943 tcpreamble << tclass[*cit].htmlstyle();
945 cit = usedInsetLayouts_.begin();
946 end = usedInsetLayouts_.end();
947 TextClass::InsetLayouts const & ils = tclass.insetLayouts();
948 for (; cit != end; ++cit) {
949 TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
952 tcpreamble << it->second.htmlstyle();
955 return tcpreamble.str();
959 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
961 DocumentClass const & tclass = params_.documentClass();
962 // collect preamble snippets in a set to prevent multiple identical
963 // commands (would happen if e.g. both theorem and theorem* are used)
964 set<docstring> snippets;
965 typedef LanguageList::const_iterator lang_it;
966 lang_it const lbeg = UsedLanguages_.begin();
967 lang_it const lend = UsedLanguages_.end();
968 list<docstring>::const_iterator cit = usedLayouts_.begin();
969 list<docstring>::const_iterator end = usedLayouts_.end();
970 for (; cit != end; ++cit) {
971 // language dependent commands (once per document)
972 snippets.insert(tclass[*cit].langpreamble(buffer().language()));
973 // commands for language changing (for multilanguage documents)
974 if (use_babel && !UsedLanguages_.empty()) {
975 snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
976 for (lang_it lit = lbeg; lit != lend; ++lit)
977 snippets.insert(tclass[*cit].babelpreamble(*lit));
981 odocstringstream tcpreamble;
982 set<docstring>::const_iterator const send = snippets.end();
983 set<docstring>::const_iterator it = snippets.begin();
984 for (; it != send; ++it)
986 return tcpreamble.str();
990 docstring const LaTeXFeatures::getLyXSGMLEntities() const
992 // Definition of entities used in the document that are LyX related.
993 odocstringstream entities;
995 if (mustProvide("lyxarrow")) {
996 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
999 return entities.str();
1003 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
1005 odocstringstream sgmlpreamble;
1007 docstring const basename(from_utf8(onlyPath(fname)));
1009 FileMap::const_iterator end = IncludedFiles_.end();
1010 for (FileMap::const_iterator fi = IncludedFiles_.begin();
1013 sgmlpreamble << "\n<!ENTITY " << fi->first
1014 << (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"")
1015 << makeRelPath(from_utf8(fi->second), basename) << "\">";
1017 return sgmlpreamble.str();
1021 void LaTeXFeatures::showStruct() const
1023 lyxerr << "LyX needs the following commands when LaTeXing:"
1024 << "\n***** Packages:" << getPackages()
1025 << "\n***** Macros:" << getMacros()
1026 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
1027 << "\n***** done." << endl;
1031 Buffer const & LaTeXFeatures::buffer() const
1037 void LaTeXFeatures::setBuffer(Buffer const & buffer)
1043 BufferParams const & LaTeXFeatures::bufferParams() const
1049 void LaTeXFeatures::getFloatDefinitions(ostream & os) const
1051 FloatList const & floats = params_.documentClass().floats();
1053 // Here we will output the code to create the needed float styles.
1054 // We will try to do this as minimal as possible.
1055 // \floatstyle{ruled}
1056 // \newfloat{algorithm}{htbp}{loa}
1057 // \floatname{algorithm}{Algorithm}
1058 UsedFloats::const_iterator cit = usedFloats_.begin();
1059 UsedFloats::const_iterator end = usedFloats_.end();
1060 // ostringstream floats;
1061 for (; cit != end; ++cit) {
1062 Floating const & fl = floats.getType((cit->first));
1064 // For builtin floats we do nothing.
1065 if (fl.builtin()) continue;
1067 // We have to special case "table" and "figure"
1068 if (fl.type() == "tabular" || fl.type() == "figure") {
1069 // Output code to modify "table" or "figure"
1070 // but only if builtin == false
1071 // and that have to be true at this point in the
1073 string const type = fl.type();
1074 string const placement = fl.placement();
1075 string const style = fl.style();
1076 if (!style.empty()) {
1077 os << "\\floatstyle{" << style << "}\n"
1078 << "\\restylefloat{" << type << "}\n";
1080 if (!placement.empty()) {
1081 os << "\\floatplacement{" << type << "}{"
1082 << placement << "}\n";
1085 // The other non builtin floats.
1087 string const type = fl.type();
1088 string const placement = fl.placement();
1089 string const ext = fl.ext();
1090 string const within = fl.within();
1091 string const style = fl.style();
1092 string const name = fl.name();
1093 os << "\\floatstyle{" << style << "}\n"
1094 << "\\newfloat{" << type << "}{" << placement
1095 << "}{" << ext << '}';
1096 if (!within.empty())
1097 os << '[' << within << ']';
1099 << "\\floatname{" << type << "}{"
1102 // What missing here is to code to minimalize the code
1103 // output so that the same floatstyle will not be
1104 // used several times, when the same style is still in
1108 os << "\n\\newsubfloat{" << fl.type() << "}\n";