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"
21 #include "support/debug.h"
24 #include "FloatList.h"
29 #include "TextClass.h"
31 #include "support/docstream.h"
32 #include "support/FileName.h"
33 #include "support/filetools.h"
36 using namespace lyx::support;
40 /////////////////////////////////////////////////////////////////////
44 /////////////////////////////////////////////////////////////////////
46 //\NeedsTeXFormat{LaTeX2e}
47 //\ProvidesPackage{lyx}[1996/01/11 LLE v0.2 (LyX LaTeX Extensions)]
48 //\message{LyX LaTeX Extensions (LLE v0.2) of 11-Jan-1996.}
50 static string const lyx_def =
51 "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}";
53 static string const lyxline_def =
54 "\\newcommand{\\lyxline}[1][1pt]{%\n"
56 " \\rule[.5ex]{\\linewidth}{#1}\\par}";
58 static string const noun_def = "\\newcommand{\\noun}[1]{\\textsc{#1}}";
60 static string const lyxarrow_def =
61 "\\newcommand{\\lyxarrow}{\\leavevmode\\,$\\triangleright$\\,\\allowbreak}";
63 // for quotes without babel. This does not give perfect results, but
64 // anybody serious about non-english quotes should use babel (JMarc).
66 static string const quotedblbase_def =
67 "\\ProvideTextCommandDefault{\\quotedblbase}{%\n"
68 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquotedblright}%\n"
69 " \\penalty10000\\hskip0em\\relax%\n"
72 static string const quotesinglbase_def =
73 "\\ProvideTextCommandDefault{\\quotesinglbase}{%\n"
74 " \\raisebox{-1.4ex}[1ex][.5ex]{\\textquoteright}%\n"
75 " \\penalty10000\\hskip0em\\relax%\n"
78 static string const guillemotleft_def =
79 "\\ProvideTextCommandDefault{\\guillemotleft}{%\n"
80 " {\\usefont{U}{lasy}{m}{n}\\char'50\\kern-.15em\\char'50}%\n"
81 "\\penalty10000\\hskip0pt\\relax%\n"
84 static string const guillemotright_def =
85 "\\ProvideTextCommandDefault{\\guillemotright}{%\n"
86 " \\penalty10000\\hskip0pt%\n"
87 " {\\usefont{U}{lasy}{m}{n}\\char'51\\kern-.15em\\char'51}%\n"
90 static string const guilsinglleft_def =
91 "\\ProvideTextCommandDefault{\\guilsinglleft}{%\n"
92 " {\\usefont{U}{lasy}{m}{n}\\char'50}%\n"
93 " \\penalty10000\\hskip0pt\\relax%\n"
96 static string const guilsinglright_def =
97 "\\ProvideTextCommandDefault{\\guilsinglright}{%\n"
98 " \\penalty10000\\hskip0pt%\n"
99 " {\\usefont{U}{lasy}{m}{n}\\char'51}%\n"
102 static string const paragraphleftindent_def =
103 "\\newenvironment{LyXParagraphLeftIndent}[1]%\n"
105 " \\begin{list}{}{%\n"
106 " \\setlength{\\topsep}{0pt}%\n"
107 " \\addtolength{\\leftmargin}{#1}\n"
108 // ho hum, yet more things commented out with no hint as to why they
109 // weren't just removed
110 // "%% \\addtolength{\\leftmargin}{#1\\textwidth}\n"
111 // "%% \\setlength{\\textwidth}{#2\\textwidth}\n"
112 // "%% \\setlength\\listparindent\\parindent%\n"
113 // "%% \\setlength\\itemindent\\parindent%\n"
114 " \\setlength{\\parsep}{0pt plus 1pt}%\n"
120 static string const floatingfootnote_def =
121 "%% Special footnote code from the package 'stblftnt.sty'\n"
122 "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
123 "\\let\\SF@@footnote\\footnote\n"
124 "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
125 " \\expandafter\\SF@@footnote\n"
127 " \\expandafter\\SF@gobble@opt\n"
130 "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
131 " \\SF@gobble@twobracket\n"
134 "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
135 " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
136 "\\def\\SF@gobble@twobracket[#1]#2{}\n";
138 static string const boldsymbol_def =
139 "%% Bold symbol macro for standard LaTeX users\n"
140 "\\providecommand{\\boldsymbol}[1]{\\mbox{\\boldmath $#1$}}\n";
142 static string const binom_def =
143 "%% Binom macro for standard LaTeX users\n"
144 "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n";
146 static string const mathcircumflex_def =
147 "%% For printing a cirumflex inside a formula\n"
148 "\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n";
150 static string const tabularnewline_def =
151 "%% Because html converters don't know tabularnewline\n"
152 "\\providecommand{\\tabularnewline}{\\\\}\n";
154 static string const lyxgreyedout_def =
155 "%% The greyedout annotation environment\n"
156 "\\newenvironment{lyxgreyedout}{\\textcolor[gray]{0.8}\\bgroup}{\\egroup}\n";
158 // We want to omit the file extension for includegraphics, but this does not
159 // work when the filename contains other dots.
160 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
161 static string const lyxdot_def =
162 "%% A simple dot to overcome graphicx limitations\n"
163 "\\newcommand{\\lyxdot}{.}\n";
165 static string const changetracking_dvipost_def =
166 "%% Change tracking with dvipost\n"
168 "\\dvipost{osstart color push Red}\n"
169 "\\dvipost{osend color pop}\n"
170 "\\dvipost{cbstart color push Blue}\n"
171 "\\dvipost{cbend color pop}\n"
172 "\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
173 "\\newcommand{\\lyxdeleted}[3]{%\n"
174 "\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n";
176 static string const changetracking_none_def =
177 "\\newcommand{\\lyxadded}[3]{#3}\n"
178 "\\newcommand{\\lyxdeleted}[3]{}\n";
180 static string const textgreek_def =
181 "\\DeclareRobustCommand{\\greektext}{%\n"
182 " \\fontencoding{LGR}\\selectfont\n"
183 " \\def\\encodingdefault{LGR}}\n"
184 "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n"
185 "\\DeclareFontEncoding{LGR}{}{}\n";
187 static string const textcyr_def =
188 "\\DeclareRobustCommand{\\cyrtext}{%\n"
189 " \\fontencoding{T2A}\\selectfont\n"
190 " \\def\\encodingdefault{T2A}}\n"
191 "\\DeclareRobustCommand{\\textcyr}[1]{\\leavevmode{\\cyrtext #1}}\n"
192 "\\DeclareFontEncoding{T2A}{}{}\n";
194 static string const newlyxcommand_def =
195 "%% Math macros with multiple optional parameters\n"
197 "\\def\\newlyxcommand#1{\n"
198 " \\@ifnextchar[%]\n"
199 " {\\newlyxcommand@arity{#1}}\n"
200 " {\\newlyxcommand@arity{#1}[0]}\n"
203 "% #1<-\\foo #2<-arity\n"
204 "\\def\\newlyxcommand@arity#1[#2]{\n"
205 " \\@ifnextchar[%]\n"
206 " {\\newlyxcommand@firstopt{#1}{}{#2}}\n"
207 " {\\newlyxcommand@def#1{#2}}\n"
210 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
211 "\\def\\newlyxcommand@firstopt#1#2#3[#4]{\n"
213 " \\def\\@defclause##1{\n"
215 " \\@ifnextchar[%]\n"
217 " {##1{}{#4}[#4]}}\n"
219 " \\expandafter\\@defclause\\csname\\expandafter\\@gobble\\string#1@\\endcsname\n"
220 " \\@ifnextchar[%]\n"
221 " {\\newlyxcommand@opt{#1}{#2}{#3}}\n"
222 " {\\newlyxcommand@last{#1}{#2}{#3}[#4]}\n"
227 "\\gdef\\@myempty{Q}\n"
230 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
231 "\\def\\newlyxcommand@opt#1#2#3[#4]{\n"
232 " % ##1<-\\foo@iii ##2<-\\foo@iiii \n"
233 " % ####1<-{a}{b}{c} ####2<-default value ####3<- default arg\n"
234 " \\def\\@defclause##1##2{\n"
235 " \\def##1####1####2[####3]{\n"
236 " \\ifx\\@myempty####3\\@myempty%\n"
237 " \\def\\@callnext{\n"
238 " \\@ifnextchar[%]\n"
239 " {##2{####1{####2}}{#4}}\n"
240 " {##2{####1{####2}}{#4}[#4]}\n"
243 " \\def\\@callnext{\n"
244 " \\@ifnextchar[%]\n"
245 " {##2{####1{####3}}{#4}}\n"
246 " {##2{####1{####3}}{#4}[#4]}\n"
252 " \\expandafter\\def\\expandafter\\@clausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2\\endcsname}\n"
253 " \\expandafter\\def\\expandafter\\@nextclausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname}\n"
254 " \\expandafter\\expandafter\\expandafter \n"
255 " \\@defclause\\expandafter\\@clausename\\@nextclausename\n"
256 " \\@ifnextchar[%]\n"
257 " {\\newlyxcommand@opt{#1}{#2i}{#3}}\n"
258 " {\\newlyxcommand@last{#1}{#2i}{#3}[#4]}\n"
261 "% #1<-\\foo #2<-iii #3<-arity #4<-default value for (#2+1)th argument\n"
262 "\\def\\newlyxcommand@last#1#2#3[#4]{\n"
263 " \\def\\@defclause##1##2{\n"
264 " \\def##1####1####2[####3]{\n"
265 " \\ifx\\@myempty####3\\@myempty%\n"
266 " \\def\\@callnext{##2####1{####2}}\n"
268 " \\def\\@callnext{##2####1{####3}}\n"
273 " \\expandafter\\def\\expandafter\\@clausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2\\endcsname}\n"
274 " \\expandafter\\def\\expandafter\\@nextclausename\\expandafter{\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname}\n"
275 " \\expandafter\\expandafter\\expandafter\n"
276 " \\@defclause\\expandafter\\@clausename\\@nextclausename\n"
277 " \\expandafter\\newlyxcommand@def\\csname\\expandafter\\@gobble\\string#1@#2i\\endcsname{#3}\n"
280 "% #1<-\\foo #2<-arity #3<-definition\n"
281 "\\def\\newlyxcommand@def#1#2#3{\n"
285 " \\def\\@splitargs##1#2##2.{\\def#1##1#2}\\@splitargs##1##2##3##4##5##6##7##8##9.{#3}\n"
289 /////////////////////////////////////////////////////////////////////
293 /////////////////////////////////////////////////////////////////////
295 LaTeXFeatures::PackagesList LaTeXFeatures::packages_;
298 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
299 OutputParams const & r)
300 : buffer_(&b), params_(p), runparams_(r)
304 bool LaTeXFeatures::useBabel() const
306 return lyxrc.language_use_babel ||
307 (bufferParams().language->lang() != lyxrc.default_language &&
308 !bufferParams().language->babel().empty()) ||
309 this->hasLanguages();
313 void LaTeXFeatures::require(string const & name)
315 if (isRequired(name))
318 features_.push_back(name);
322 void LaTeXFeatures::getAvailable()
325 support::FileName const real_file = libFileSearch("", "packages.lst");
327 if (real_file.empty())
330 lex.setFile(real_file);
335 // Make sure that we are clean
338 bool finished = false;
340 while (lex.isOK() && !finished) {
342 case Lexer::LEX_FEOF:
346 string const name = lex.getString();
347 PackagesList::const_iterator begin = packages_.begin();
348 PackagesList::const_iterator end = packages_.end();
349 if (find(begin, end, name) == end)
350 packages_.push_back(name);
356 void LaTeXFeatures::useLayout(docstring const & layoutname)
358 // Some code to avoid loops in dependency definition
359 static int level = 0;
360 const int maxlevel = 30;
361 if (level > maxlevel) {
362 lyxerr << "LaTeXFeatures::useLayout: maximum level of "
363 << "recursion attained by layout "
364 << to_utf8(layoutname) << endl;
368 TextClass const & tclass = params_.getTextClass();
369 if (tclass.hasLayout(layoutname)) {
370 // Is this layout already in usedLayouts?
371 list<docstring>::const_iterator cit = usedLayouts_.begin();
372 list<docstring>::const_iterator end = usedLayouts_.end();
373 for (; cit != end; ++cit) {
374 if (layoutname == *cit)
378 LayoutPtr const & lyt = tclass[layoutname];
379 if (!lyt->depends_on().empty()) {
381 useLayout(lyt->depends_on());
384 usedLayouts_.push_back(layoutname);
386 lyxerr << "LaTeXFeatures::useLayout: layout `"
387 << to_utf8(layoutname) << "' does not exist in this class"
395 bool LaTeXFeatures::isRequired(string const & name) const
397 return find(features_.begin(), features_.end(), name) != features_.end();
401 bool LaTeXFeatures::mustProvide(string const & name) const
403 return isRequired(name) && !params_.getTextClass().provides(name);
407 bool LaTeXFeatures::isAvailable(string const & name)
410 if (packages_.empty())
412 size_t loc = n.rfind(".sty");
413 if (loc == n.length() - 4)
414 n = n.erase(name.length() - 4);
415 return find(packages_.begin(), packages_.end(), n) != packages_.end();
419 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
421 FeaturesList::const_iterator begin = preamble_snippets_.begin();
422 FeaturesList::const_iterator end = preamble_snippets_.end();
423 if (find(begin, end, preamble) == end)
424 preamble_snippets_.push_back(preamble);
428 void LaTeXFeatures::useFloat(string const & name)
430 usedFloats_.insert(name);
431 // We only need float.sty if we use non builtin floats, or if we
432 // use the "H" modifier. This includes modified table and
433 // figure floats. (Lgb)
434 Floating const & fl = params_.getTextClass().floats().getType(name);
435 if (!fl.type().empty() && !fl.builtin()) {
441 void LaTeXFeatures::useLanguage(Language const * lang)
443 if (!lang->babel().empty())
444 UsedLanguages_.insert(lang);
445 // CJK languages do not have a babel name.
446 // They use the CJK package
447 if (lang->encoding()->package() == Encoding::CJK)
452 void LaTeXFeatures::includeFile(docstring const & key, string const & name)
454 IncludedFiles_[key] = name;
458 bool LaTeXFeatures::hasLanguages() const
460 return !UsedLanguages_.empty();
464 string LaTeXFeatures::getLanguages() const
466 ostringstream languages;
468 LanguageList::const_iterator const begin = UsedLanguages_.begin();
469 for (LanguageList::const_iterator cit = begin;
470 cit != UsedLanguages_.end();
474 languages << (*cit)->babel();
476 return languages.str();
480 set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
482 // This does only find encodings of languages supported by babel, but
483 // that does not matter since we don't have a language with an
484 // encoding supported by inputenc but without babel support.
485 set<string> encodings;
486 LanguageList::const_iterator it = UsedLanguages_.begin();
487 LanguageList::const_iterator end = UsedLanguages_.end();
488 for (; it != end; ++it)
489 if ((*it)->encoding()->latexName() != doc_encoding &&
490 (*it)->encoding()->package() == Encoding::inputenc)
491 encodings.insert((*it)->encoding()->latexName());
497 char const * simplefeatures[] = {
498 // note that the package order here will be the same in the LaTeX-output
508 /*For a successful cooperation of the `wrapfig' package with the
509 `float' package you should load the `wrapfig' package *after*
510 the `float' package. See the caption package documentation
539 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
544 string const LaTeXFeatures::getPackages() const
546 ostringstream packages;
547 TextClass const & tclass = params_.getTextClass();
549 // FIXME: currently, we can only load packages and macros known
551 // However, with the Require tag of layouts/custom insets,
552 // also inknown packages can be requested. They are silently
553 // swallowed now. We should change this eventually.
556 // These are all the 'simple' includes. i.e
557 // packages which we just \usepackage{package}
559 for (int i = 0; i < nb_simplefeatures; ++i) {
560 if (mustProvide(simplefeatures[i]))
561 packages << "\\usepackage{"
562 << simplefeatures[i] << "}\n";
566 // The rest of these packages are somewhat more complicated
570 // esint is preferred for esintoramsmath
571 if ((mustProvide("amsmath") &&
572 params_.use_amsmath != BufferParams::package_off) ||
573 (mustProvide("esintoramsmath") &&
574 params_.use_esint == BufferParams::package_off)) {
575 packages << "\\usepackage{amsmath}\n";
578 // wasysym is a simple feature, but it must be after amsmath if both
580 // wasysym redefines some integrals (e.g. iint) from amsmath. That
581 // leads to inconsistent integrals. We only load this package if
582 // the document does not contain integrals (then isRequired("esint")
583 // is false) or if esint is used, since esint redefines all relevant
584 // integral symbols from wasysym and amsmath.
585 // See http://bugzilla.lyx.org/show_bug.cgi?id=1942
586 if (mustProvide("wasysym") &&
587 (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
588 packages << "\\usepackage{wasysym}\n";
591 if (mustProvide("color")) {
592 if (params_.graphicsDriver == "default")
593 packages << "\\usepackage{color}\n";
595 packages << "\\usepackage["
596 << params_.graphicsDriver
601 if (isRequired("makeidx")) {
602 if (!tclass.provides("makeidx"))
603 packages << "\\usepackage{makeidx}\n";
604 packages << "\\makeindex\n";
608 if (mustProvide("graphicx") && params_.graphicsDriver != "none") {
609 if (params_.graphicsDriver == "default")
610 packages << "\\usepackage{graphicx}\n";
612 packages << "\\usepackage["
613 << params_.graphicsDriver
616 // shadecolor for shaded
617 if (isRequired("framed") && mustProvide("color")) {
618 RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
619 //255.0 to force conversion to double
620 //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
621 //to use the xcolor package instead, and then we can do
622 // \define{shadcolor}{RGB}...
623 //and not do any conversion. We'd then need to require xcolor
624 //in InsetNote::validate().
625 int const stmSize = packages.precision(2);
626 packages << "\\definecolor{shadecolor}{rgb}{"
627 << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n";
628 packages.precision(stmSize);
631 // lyxskak.sty --- newer chess support based on skak.sty
632 if (mustProvide("chess")) {
633 packages << "\\usepackage[ps,mover]{lyxskak}\n";
637 if ((params_.spacing().getSpace() != Spacing::Single
638 && !params_.spacing().isDefault())
639 || isRequired("setspace")) {
640 packages << "\\usepackage{setspace}\n";
642 switch (params_.spacing().getSpace()) {
643 case Spacing::Default:
644 case Spacing::Single:
645 // we dont use setspace.sty so dont print anything
646 //packages += "\\singlespacing\n";
648 case Spacing::Onehalf:
649 packages << "\\onehalfspacing\n";
651 case Spacing::Double:
652 packages << "\\doublespacing\n";
655 packages << "\\setstretch{"
656 << params_.spacing().getValue() << "}\n";
661 if (mustProvide("amssymb")
662 || params_.use_amsmath == BufferParams::package_on)
663 packages << "\\usepackage{amssymb}\n";
665 // esint must be after amsmath and wasysym, since it will redeclare
666 // inconsistent integral symbols
667 if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
668 params_.use_esint != BufferParams::package_off)
669 packages << "\\usepackage{esint}\n";
672 if (mustProvide("natbib")) {
673 packages << "\\usepackage[";
674 if (params_.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL) {
675 packages << "numbers";
677 packages << "authoryear";
679 packages << "]{natbib}\n";
682 // jurabib -- we need version 0.6 at least.
683 if (mustProvide("jurabib")) {
684 packages << "\\usepackage{jurabib}[2004/01/25]\n";
687 // bibtopic -- the dot provides the aux file naming which
689 if (mustProvide("bibtopic")) {
690 packages << "\\usepackage[dot]{bibtopic}\n";
693 if (mustProvide("xy"))
694 packages << "\\usepackage[all]{xy}\n";
696 if (mustProvide("nomencl")) {
697 // Make it work with the new and old version of the package,
698 // but don't use the compatibility option since it is
699 // incompatible to other packages.
700 packages << "\\usepackage{nomencl}\n"
701 "% the following is useful when we have the old nomencl.sty package\n"
702 "\\providecommand{\\printnomenclature}{\\printglossary}\n"
703 "\\providecommand{\\makenomenclature}{\\makeglossary}\n"
704 "\\makenomenclature\n";
707 if (mustProvide("listings"))
708 packages << "\\usepackage{listings}\n";
710 return packages.str();
714 string const LaTeXFeatures::getMacros() const
716 ostringstream macros;
718 if (!preamble_snippets_.empty())
720 FeaturesList::const_iterator pit = preamble_snippets_.begin();
721 FeaturesList::const_iterator pend = preamble_snippets_.end();
722 for (; pit != pend; ++pit)
723 macros << *pit << '\n';
725 if (mustProvide("LyX"))
726 macros << lyx_def << '\n';
728 if (mustProvide("lyxline"))
729 macros << lyxline_def << '\n';
731 if (mustProvide("noun"))
732 macros << noun_def << '\n';
734 if (mustProvide("lyxarrow"))
735 macros << lyxarrow_def << '\n';
737 if (mustProvide("textgreek"))
738 macros << textgreek_def << '\n';
740 if (mustProvide("textcyr"))
741 macros << textcyr_def << '\n';
744 if (mustProvide("quotesinglbase"))
745 macros << quotesinglbase_def << '\n';
746 if (mustProvide("quotedblbase"))
747 macros << quotedblbase_def << '\n';
748 if (mustProvide("guilsinglleft"))
749 macros << guilsinglleft_def << '\n';
750 if (mustProvide("guilsinglright"))
751 macros << guilsinglright_def << '\n';
752 if (mustProvide("guillemotleft"))
753 macros << guillemotleft_def << '\n';
754 if (mustProvide("guillemotright"))
755 macros << guillemotright_def << '\n';
758 if (mustProvide("boldsymbol") && !isRequired("amsmath"))
759 macros << boldsymbol_def << '\n';
760 if (mustProvide("binom") && !isRequired("amsmath"))
761 macros << binom_def << '\n';
762 if (mustProvide("mathcircumflex"))
763 macros << mathcircumflex_def << '\n';
764 if (mustProvide("newlyxcommand"))
765 macros << newlyxcommand_def << '\n';
768 if (mustProvide("ParagraphLeftIndent"))
769 macros << paragraphleftindent_def;
770 if (mustProvide("NeedLyXFootnoteCode"))
771 macros << floatingfootnote_def;
773 // some problems with tex->html converters
774 if (mustProvide("NeedTabularnewline"))
775 macros << tabularnewline_def;
777 // greyedout environment (note inset)
778 if (mustProvide("lyxgreyedout"))
779 macros << lyxgreyedout_def;
781 if (mustProvide("lyxdot"))
782 macros << lyxdot_def << '\n';
785 getFloatDefinitions(macros);
788 if (mustProvide("ct-dvipost"))
789 macros << changetracking_dvipost_def;
791 if (mustProvide("ct-xcolor-soul")) {
792 int const prec = macros.precision(2);
794 RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
795 macros << "\\providecolor{lyxadded}{rgb}{"
796 << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
798 RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
799 macros << "\\providecolor{lyxdeleted}{rgb}{"
800 << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
802 macros.precision(prec);
804 macros << "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
805 << "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\st{#3}}}\n";
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 TextClass const & tclass = params_.getTextClass();
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_.getTextClass().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));
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