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"
23 #include "FloatList.h"
28 #include "TextClass.h"
30 #include "support/debug.h"
31 #include "support/docstream.h"
32 #include "support/FileName.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
37 using namespace lyx::support;
41 /////////////////////////////////////////////////////////////////////
45 /////////////////////////////////////////////////////////////////////
47 //\NeedsTeXFormat{LaTeX2e}
48 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
49 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
51 static string const lyx_def =
52 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}";
54 static string const lyxline_def =
55 "\\newcommand{\\lyxline}[1][1pt]{%\n"
57 " \\rule[.5ex]{\\linewidth}{#1}\\par}";
59 static string const noun_def = "\\newcommand{\\noun}[1]{\\textsc{#1}}";
61 static string const lyxarrow_def =
62 "\\newcommand{\\lyxarrow}{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}";
64 // for quotes without babel. This does not give perfect results, but
65 // anybody serious about non-english quotes should use babel (JMarc).
67 static string const quotedblbase_def =
68 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
69 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
70 " \\penalty10000\\hskip0em\\relax%\n"
73 static string const quotesinglbase_def =
74 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
75 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
76 " \\penalty10000\\hskip0em\\relax%\n"
79 static string const guillemotleft_def =
80 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
81 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
82 "\\penalty10000\\hskip0pt\\relax%\n"
85 static string const guillemotright_def =
86 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
87 " \\penalty10000\\hskip0pt%\n"
88 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
91 static string const guilsinglleft_def =
92 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
93 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
94 " \\penalty10000\\hskip0pt\\relax%\n"
97 static string const guilsinglright_def =
98 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
99 " \\penalty10000\\hskip0pt%\n"
100 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
103 static string const paragraphleftindent_def =
104 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
106 " \\begin{list}{}{%\n"
107 " \\setlength{\\topsep}{0pt}%\n"
108 " \\addtolength{\\leftmargin}{#1}\n"
109 // ho hum, yet more things commented out with no hint as to why they
110 // weren't just removed
111 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
112 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
113 // "%% \\setlength\\listparindent\\parindent%\n"
114 // "%% \\setlength\\itemindent\\parindent%\n"
115 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
121 static string const floatingfootnote_def =
122 "%% Special footnote code from the package 'stblftnt.sty'\n"
123 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
124 "\\let\\SF@@footnote\\footnote\n"
125 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
126 " \\expandafter\\SF@@footnote\n"
128 " \\expandafter\\SF@gobble@opt\n"
131 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
132 " \\SF@gobble@twobracket\n"
135 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
136 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
137 "\\def\\SF@gobble@twobracket[#1]#2{}\n";
139 static string const boldsymbol_def =
140 "%% Bold symbol macro for standard LaTeX users\n"
141 "\\providecommand{\\boldsymbol}[1]{\\mbox{\\boldmath $#1$}}\n";
143 static string const binom_def =
144 "%% Binom macro for standard LaTeX users\n"
145 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n";
147 static string const mathcircumflex_def =
148 "%% For printing a cirumflex inside a formula\n"
149 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n";
151 static string const tabularnewline_def =
152 "%% Because html converters don't know tabularnewline\n"
153 "\\providecommand{\\tabularnewline}{\\\\}\n";
155 static string const lyxgreyedout_def =
156 "%% The greyedout annotation environment\n"
157 "\\newenvironment{lyxgreyedout}{\\textcolor[gray]{0.8}\\bgroup}{\\egroup}\n";
159 // We want to omit the file extension for includegraphics, but this does not
160 // work when the filename contains other dots.
161 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
162 static string const lyxdot_def =
163 "%% A simple dot to overcome graphicx limitations\n"
164 "\\newcommand{\\lyxdot}{.}\n";
166 static string const changetracking_dvipost_def =
167 "%% Change tracking with dvipost\n"
169 "\\dvipost{osstart color push Red}\n"
170 "\\dvipost{osend color pop}\n"
171 "\\dvipost{cbstart color push Blue}\n"
172 "\\dvipost{cbend color pop}\n"
173 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
174 "\\newcommand{\\lyxdeleted}[3]{%\n"
175 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n";
177 static string const changetracking_xcolor_soul_def =
178 "%% Change tracking with soul\n"
179 "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
180 "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\st{#3}}}\n";
182 static string const changetracking_xcolor_soul_hyperref_def =
183 "%% Change tracking with soul\n"
184 "\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}}{}#3}}\n"
185 "\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\st{#3}}{}}}\n";
187 static string const changetracking_none_def =
188 "\\newcommand{\\lyxadded}[3]{#3}\n"
189 "\\newcommand{\\lyxdeleted}[3]{}\n";
191 static string const textgreek_def =
192 "\\DeclareRobustCommand{\\greektext}{%\n"
193 " \\fontencoding{LGR}\\selectfont\n"
194 " \\def\\encodingdefault{LGR}}\n"
195 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
196 "\\DeclareFontEncoding{LGR}{}{}\n";
198 static string const textcyr_def =
199 "\\DeclareRobustCommand{\\cyrtext}{%\n"
200 " \\fontencoding{T2A}\\selectfont\n"
201 " \\def\\encodingdefault{T2A}}\n"
202 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
203 "\\DeclareFontEncoding{T2A}{}{}\n";
205 static string const newlyxcommand_def =
206 "%% Math macros with multiple optional parameters\n"
208 "\\def\\newlyxcommand#1{\n"
209 " \\@ifnextchar[%]\n"
210 " {\\newlyxcommand@arity{#1}}\n"
211 " {\\newlyxcommand@arity{#1}[0]}\n"
214 "% #1<-\\foo #2<-arity\n"
215 "\\def\\newlyxcommand@arity#1[#2]{\n"
216 " \\@ifnextchar[%]\n"
217 " {\\newlyxcommand@firstopt{#1}{}{#2}}\n"
218 " {\\newlyxcommand@def#1{#2}}\n"
221 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
222 "\\def\\newlyxcommand@firstopt#1#2#3[#4]{\n"
224 " \\def\\@defclause##1{\n"
226 " \\@ifnextchar[%]\n"
228 " {##1{}{#4}[#4]}}\n"
230 " \\expandafter\\@defclause\\csname\\expandafter\\@gobble\\string#1@\\endcsname\n"
231 " \\@ifnextchar[%]\n"
232 " {\\newlyxcommand@opt{#1}{#2}{#3}}\n"
233 " {\\newlyxcommand@last{#1}{#2}{#3}[#4]}\n"
238 "\\gdef\\@myempty{Q}\n"
241 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
242 "\\def\\newlyxcommand@opt#1#2#3[#4]{\n"
243 " % ##1<-\\foo@iii ##2<-\\foo@iiii \n"
244 " % ####1<-{a}{b}{c} ####2<-default value ####3<- default arg\n"
245 " \\def\\@defclause##1##2{\n"
246 " \\def##1####1####2[####3]{\n"
247 " \\ifx\\@myempty####3\\@myempty%\n"
248 " \\def\\@callnext{\n"
249 " \\@ifnextchar[%]\n"
250 " {##2{####1{####2}}{#4}}\n"
251 " {##2{####1{####2}}{#4}[#4]}\n"
254 " \\def\\@callnext{\n"
255 " \\@ifnextchar[%]\n"
256 " {##2{####1{####3}}{#4}}\n"
257 " {##2{####1{####3}}{#4}[#4]}\n"
263 " \\expandafter\\def\\expandafter\\@clausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2\\endcsname}\n"
264 " \\expandafter\\def\\expandafter\\@nextclausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname}\n"
265 " \\expandafter\\expandafter\\expandafter \n"
266 " \\@defclause\\expandafter\\@clausename\\@nextclausename\n"
267 " \\@ifnextchar[%]\n"
268 " {\\newlyxcommand@opt{#1}{#2i}{#3}}\n"
269 " {\\newlyxcommand@last{#1}{#2i}{#3}[#4]}\n"
272 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
273 "\\def\\newlyxcommand@last#1#2#3[#4]{\n"
274 " \\def\\@defclause##1##2{\n"
275 " \\def##1####1####2[####3]{\n"
276 " \\ifx\\@myempty####3\\@myempty%\n"
277 " \\def\\@callnext{##2####1{####2}}\n"
279 " \\def\\@callnext{##2####1{####3}}\n"
284 " \\expandafter\\def\\expandafter\\@clausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2\\endcsname}\n"
285 " \\expandafter\\def\\expandafter\\@nextclausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname}\n"
286 " \\expandafter\\expandafter\\expandafter\n"
287 " \\@defclause\\expandafter\\@clausename\\@nextclausename\n"
288 " \\expandafter\\newlyxcommand@def\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname{#3}\n"
291 "% #1<-\\foo #2<-arity #3<-definition\n"
292 "\\def\\newlyxcommand@def#1#2#3{\n"
296 " \\def\\@splitargs##1#2##2.{\\def#1##1#2}\\@splitargs##1##2##3##4##5##6##7##8##9.{#3}\n"
300 /////////////////////////////////////////////////////////////////////
304 /////////////////////////////////////////////////////////////////////
306 LaTeXFeatures::Packages LaTeXFeatures::packages_;
309 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
310 OutputParams const & r)
311 : buffer_(&b), params_(p), runparams_(r)
315 bool LaTeXFeatures::useBabel() const
317 return lyxrc.language_use_babel ||
318 (bufferParams().language->lang() != lyxrc.default_language &&
319 !bufferParams().language->babel().empty()) ||
320 this->hasLanguages();
324 void LaTeXFeatures::require(string const & name)
326 features_.insert(name);
330 void LaTeXFeatures::require(set<string> const & names)
332 features_.insert(names.begin(), names.end());
336 void LaTeXFeatures::getAvailable()
339 support::FileName const real_file = libFileSearch("", "packages.lst");
341 if (real_file.empty())
344 lex.setFile(real_file);
349 // Make sure that we are clean
352 bool finished = false;
354 while (lex.isOK() && !finished) {
356 case Lexer::LEX_FEOF:
360 packages_.insert(lex.getString());
366 void LaTeXFeatures::useLayout(docstring const & layoutname)
368 // Some code to avoid loops in dependency definition
369 static int level = 0;
370 const int maxlevel = 30;
371 if (level > maxlevel) {
372 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
373 << "recursion attained by layout "
374 << to_utf8(layoutname) << endl;
378 DocumentClass const & tclass = params_.documentClass();
379 if (tclass.hasLayout(layoutname)) {
380 // Is this layout already in usedLayouts?
381 if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
382 != usedLayouts_.end())
385 Layout const & layout = tclass[layoutname];
386 require(layout.requires());
388 if (!layout.depends_on().empty()) {
390 useLayout(layout.depends_on());
393 usedLayouts_.push_back(layoutname);
395 lyxerr << "LaTeXFeatures::useLayout: layout `"
396 << to_utf8(layoutname) << "' does not exist in this class"
404 bool LaTeXFeatures::isRequired(string const & name) const
406 return features_.find(name) != features_.end();
410 bool LaTeXFeatures::mustProvide(string const & name) const
412 return isRequired(name) && !params_.documentClass().provides(name);
416 bool LaTeXFeatures::isAvailable(string const & name)
418 if (packages_.empty())
421 if (suffixIs(n, ".sty"))
422 n.erase(name.length() - 4);
423 return packages_.find(n) != packages_.end();
427 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
429 SnippetList::const_iterator begin = preamble_snippets_.begin();
430 SnippetList::const_iterator end = preamble_snippets_.end();
431 if (find(begin, end, preamble) == end)
432 preamble_snippets_.push_back(preamble);
436 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
438 if (!usedFloats_[name])
439 usedFloats_[name] = subfloat;
442 // We only need float.sty if we use non builtin floats, or if we
443 // use the "H" modifier. This includes modified table and
444 // figure floats. (Lgb)
445 Floating const & fl = params_.documentClass().floats().getType(name);
446 if (!fl.type().empty() && !fl.builtin()) {
452 void LaTeXFeatures::useLanguage(Language const * lang)
454 if (!lang->babel().empty())
455 UsedLanguages_.insert(lang);
456 // CJK languages do not have a babel name.
457 // They use the CJK package
458 if (lang->encoding()->package() == Encoding::CJK)
463 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
465 IncludedFiles_[key] = name;
469 bool LaTeXFeatures::hasLanguages() const
471 return !UsedLanguages_.empty();
475 string LaTeXFeatures::getLanguages() const
477 ostringstream languages;
479 LanguageList::const_iterator const begin = UsedLanguages_.begin();
480 for (LanguageList::const_iterator cit = begin;
481 cit != UsedLanguages_.end();
485 languages << (*cit)->babel();
487 return languages.str();
491 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
493 // This does only find encodings of languages supported by babel, but
494 // that does not matter since we don't have a language with an
495 // encoding supported by inputenc but without babel support.
496 set<string> encodings;
497 LanguageList::const_iterator it = UsedLanguages_.begin();
498 LanguageList::const_iterator end = UsedLanguages_.end();
499 for (; it != end; ++it)
500 if ((*it)->encoding()->latexName() != doc_encoding &&
501 (*it)->encoding()->package() == Encoding::inputenc)
502 encodings.insert((*it)->encoding()->latexName());
508 char const * simplefeatures[] = {
509 // note that the package order here will be the same in the LaTeX-output
519 /*For a successful cooperation of the `wrapfig' package with the
520 `float' package you should load the `wrapfig' package *after*
521 the `float' package. See the caption package documentation
553 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
558 string const LaTeXFeatures::getPackages() const
560 ostringstream packages;
561 DocumentClass const & tclass = params_.documentClass();
563 // FIXME: currently, we can only load packages and macros known
565 // However, with the Require tag of layouts/custom insets,
566 // also inknown packages can be requested. They are silently
567 // swallowed now. We should change this eventually.
570 // These are all the 'simple' includes. i.e
571 // packages which we just \usepackage{package}
573 for (int i = 0; i < nb_simplefeatures; ++i) {
574 if (mustProvide(simplefeatures[i]))
575 packages << "\\usepackage{"
576 << simplefeatures[i] << "}\n";
580 // The rest of these packages are somewhat more complicated
584 // esint is preferred for esintoramsmath
585 if ((mustProvide("amsmath") &&
586 params_.use_amsmath != BufferParams::package_off) ||
587 (mustProvide("esintoramsmath") &&
588 params_.use_esint == BufferParams::package_off)) {
589 packages << "\\usepackage{amsmath}\n";
592 // wasysym is a simple feature, but it must be after amsmath if both
594 // wasysym redefines some integrals (e.g. iint) from amsmath. That
595 // leads to inconsistent integrals. We only load this package if
596 // the document does not contain integrals (then isRequired("esint")
597 // is false) or if esint is used, since esint redefines all relevant
598 // integral symbols from wasysym and amsmath.
599 // See http://bugzilla.lyx.org/show_bug.cgi?id=1942
600 if (mustProvide("wasysym") &&
601 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
602 packages << "\\usepackage{wasysym}\n";
605 if (mustProvide("color") || mustProvide("xcolor")) {
606 string const package =
607 (mustProvide("xcolor") ? "xcolor" : "color");
608 if (params_.graphicsDriver == "default")
609 packages << "\\usepackage{" << package << "}\n";
611 packages << "\\usepackage["
612 << params_.graphicsDriver
613 << "]{" << package << "}\n";
616 // pdfcolmk must be loaded after color
617 if (mustProvide("pdfcolmk")) {
618 packages << "\\usepackage{pdfcolmk}\n";
622 if (isRequired("makeidx")) {
623 if (!tclass.provides("makeidx"))
624 packages << "\\usepackage{makeidx}\n";
625 packages << "\\makeindex\n";
629 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
630 if (params_.graphicsDriver == "default")
631 packages << "\\usepackage{graphicx}\n";
633 packages << "\\usepackage["
634 << params_.graphicsDriver
637 // shadecolor for shaded
638 if (isRequired("framed") && mustProvide("color")) {
639 RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
640 //255.0 to force conversion to double
641 //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
642 //to use the xcolor package instead, and then we can do
643 // \define{shadcolor}{RGB}...
644 //and not do any conversion. We'd then need to require xcolor
645 //in InsetNote::validate().
646 int const stmSize = packages.precision(2);
647 packages << "\\definecolor{shadecolor}{rgb}{"
648 << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
649 packages.precision(stmSize);
652 // lyxskak.sty --- newer chess support based on skak.sty
653 if (mustProvide("chess")) {
654 packages << "\\usepackage[ps,mover]{lyxskak}\n";
658 if (mustProvide("setspace") && !tclass.provides("SetSpace"))
659 packages << "\\usepackage{setspace}\n";
662 if (mustProvide("amssymb")
663 || params_.use_amsmath == BufferParams::package_on)
664 packages << "\\usepackage{amssymb}\n";
666 // esint must be after amsmath and wasysym, since it will redeclare
667 // inconsistent integral symbols
668 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
669 params_.use_esint != BufferParams::package_off)
670 packages << "\\usepackage{esint}\n";
673 if (mustProvide("natbib")) {
674 packages << "\\usepackage[";
675 if (params_.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL) {
676 packages << "numbers";
678 packages << "authoryear";
680 packages << "]{natbib}\n";
683 // jurabib -- we need version 0.6 at least.
684 if (mustProvide("jurabib")) {
685 packages << "\\usepackage{jurabib}[2004/01/25]\n";
688 // bibtopic -- the dot provides the aux file naming which
690 if (mustProvide("bibtopic")) {
691 packages << "\\usepackage[dot]{bibtopic}\n";
694 if (mustProvide("xy"))
695 packages << "\\usepackage[all]{xy}\n";
697 if (mustProvide("nomencl")) {
698 // Make it work with the new and old version of the package,
699 // but don't use the compatibility option since it is
700 // incompatible to other packages.
701 packages << "\\usepackage{nomencl}\n"
702 "% the following is useful when we have the old nomencl.sty package\n"
703 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
704 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
705 "\\makenomenclature\n";
708 return packages.str();
712 string const LaTeXFeatures::getMacros() const
714 ostringstream macros;
716 if (!preamble_snippets_.empty())
718 SnippetList::const_iterator pit = preamble_snippets_.begin();
719 SnippetList::const_iterator pend = preamble_snippets_.end();
720 for (; pit != pend; ++pit)
721 macros << *pit << '\n';
723 if (mustProvide("LyX"))
724 macros << lyx_def << '\n';
726 if (mustProvide("lyxline"))
727 macros << lyxline_def << '\n';
729 if (mustProvide("noun"))
730 macros << noun_def << '\n';
732 if (mustProvide("lyxarrow"))
733 macros << lyxarrow_def << '\n';
735 if (mustProvide("textgreek"))
736 macros << textgreek_def << '\n';
738 if (mustProvide("textcyr"))
739 macros << textcyr_def << '\n';
742 if (mustProvide("quotesinglbase"))
743 macros << quotesinglbase_def << '\n';
744 if (mustProvide("quotedblbase"))
745 macros << quotedblbase_def << '\n';
746 if (mustProvide("guilsinglleft"))
747 macros << guilsinglleft_def << '\n';
748 if (mustProvide("guilsinglright"))
749 macros << guilsinglright_def << '\n';
750 if (mustProvide("guillemotleft"))
751 macros << guillemotleft_def << '\n';
752 if (mustProvide("guillemotright"))
753 macros << guillemotright_def << '\n';
756 if (mustProvide("boldsymbol") && !isRequired("amsmath"))
757 macros << boldsymbol_def << '\n';
758 if (mustProvide("binom") && !isRequired("amsmath"))
759 macros << binom_def << '\n';
760 if (mustProvide("mathcircumflex"))
761 macros << mathcircumflex_def << '\n';
762 if (mustProvide("newlyxcommand"))
763 macros << newlyxcommand_def << '\n';
766 if (mustProvide("ParagraphLeftIndent"))
767 macros << paragraphleftindent_def;
768 if (mustProvide("NeedLyXFootnoteCode"))
769 macros << floatingfootnote_def;
771 // some problems with tex->html converters
772 if (mustProvide("NeedTabularnewline"))
773 macros << tabularnewline_def;
775 // greyedout environment (note inset)
776 if (mustProvide("lyxgreyedout"))
777 macros << lyxgreyedout_def;
779 if (mustProvide("lyxdot"))
780 macros << lyxdot_def << '\n';
783 getFloatDefinitions(macros);
786 if (mustProvide("ct-dvipost"))
787 macros << changetracking_dvipost_def;
789 if (mustProvide("ct-xcolor-soul")) {
790 int const prec = macros.precision(2);
792 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
793 macros << "\\providecolor{lyxadded}{rgb}{"
794 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
796 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
797 macros << "\\providecolor{lyxdeleted}{rgb}{"
798 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
800 macros.precision(prec);
802 if (isRequired("hyperref"))
803 macros << changetracking_xcolor_soul_hyperref_def;
805 macros << changetracking_xcolor_soul_def;
808 if (mustProvide("ct-none"))
809 macros << changetracking_none_def;
815 string const LaTeXFeatures::getBabelOptions() const
819 LanguageList::const_iterator it = UsedLanguages_.begin();
820 LanguageList::const_iterator end = UsedLanguages_.end();
821 for (; it != end; ++it)
822 if (!(*it)->latex_options().empty())
823 tmp << (*it)->latex_options() << '\n';
824 if (!params_.language->latex_options().empty())
825 tmp << params_.language->latex_options() << '\n';
831 docstring const LaTeXFeatures::getTClassPreamble() const
833 // the text class specific preamble
834 DocumentClass const & tclass = params_.documentClass();
835 odocstringstream tcpreamble;
837 tcpreamble << tclass.preamble();
839 list<docstring>::const_iterator cit = usedLayouts_.begin();
840 list<docstring>::const_iterator end = usedLayouts_.end();
841 for (; cit != end; ++cit) {
842 tcpreamble << tclass[*cit].preamble();
845 return tcpreamble.str();
849 docstring const LaTeXFeatures::getLyXSGMLEntities() const
851 // Definition of entities used in the document that are LyX related.
852 odocstringstream entities;
854 if (mustProvide("lyxarrow")) {
855 entities << "<!ENTITY lyxarrow \"->\">" << '\n';
858 return entities.str();
862 docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const
864 odocstringstream sgmlpreamble;
866 docstring const basename(from_utf8(onlyPath(fname)));
868 FileMap::const_iterator end = IncludedFiles_.end();
869 for (FileMap::const_iterator fi = IncludedFiles_.begin();
872 sgmlpreamble << "\n<!ENTITY " << fi->first
873 << (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"")
874 << makeRelPath(from_utf8(fi->second), basename) << "\">";
876 return sgmlpreamble.str();
880 void LaTeXFeatures::showStruct() const {
881 lyxerr << "LyX needs the following commands when LaTeXing:"
882 << "\n***** Packages:" << getPackages()
883 << "\n***** Macros:" << getMacros()
884 << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble())
885 << "\n***** done." << endl;
889 Buffer const & LaTeXFeatures::buffer() const
895 void LaTeXFeatures::setBuffer(Buffer const & buffer)
901 BufferParams const & LaTeXFeatures::bufferParams() const
907 void LaTeXFeatures::getFloatDefinitions(ostream & os) const
909 FloatList const & floats = params_.documentClass().floats();
911 // Here we will output the code to create the needed float styles.
912 // We will try to do this as minimal as possible.
913 // \floatstyle{ruled}
914 // \newfloat{algorithm}{htbp}{loa}
915 // \floatname{algorithm}{Algorithm}
916 UsedFloats::const_iterator cit = usedFloats_.begin();
917 UsedFloats::const_iterator end = usedFloats_.end();
918 // ostringstream floats;
919 for (; cit != end; ++cit) {
920 Floating const & fl = floats.getType((cit->first));
922 // For builtin floats we do nothing.
923 if (fl.builtin()) continue;
925 // We have to special case "table" and "figure"
926 if (fl.type() == "tabular" || fl.type() == "figure") {
927 // Output code to modify "table" or "figure"
928 // but only if builtin == false
929 // and that have to be true at this point in the
931 string const type = fl.type();
932 string const placement = fl.placement();
933 string const style = fl.style();
934 if (!style.empty()) {
935 os << "\\floatstyle{" << style << "}\n"
936 << "\\restylefloat{" << type << "}\n";
938 if (!placement.empty()) {
939 os << "\\floatplacement{" << type << "}{"
940 << placement << "}\n";
943 // The other non builtin floats.
945 string const type = fl.type();
946 string const placement = fl.placement();
947 string const ext = fl.ext();
948 string const within = fl.within();
949 string const style = fl.style();
950 string const name = fl.name();
951 os << "\\floatstyle{" << style << "}\n"
952 << "\\newfloat{" << type << "}{" << placement
953 << "}{" << ext << '}';
955 os << '[' << within << ']';
957 << "\\floatname{" << type << "}{"
960 // What missing here is to code to minimalize the code
961 // output so that the same floatstyle will not be
962 // used several times, when the same style is still in
966 os << "\n\\newsubfloat{" << fl.type() << "}\n";