2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 the LyX Team.
10 * ====================================================== */
15 #pragma implementation "LaTeXFeatures.h"
22 #include "LaTeXFeatures.h"
23 #include "bufferparams.h"
28 LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
29 : layout(n, false), params(p)
34 graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
59 quotesinglbase = false;
61 guilsinglleft = false;
62 guilsinglright = false;
63 guillemotleft = false;
64 guillemotright = false;
72 LyXParagraphIndent = false;
73 NeedLyXFootnoteCode = false;
74 NeedLyXMinipageIndent = false;
78 void LaTeXFeatures::require(string const & name)
80 if (name == "array") {
82 } else if (name == "color") {
84 } else if (name == "graphics") {
86 graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
87 } else if (name == "setspace") {
89 } else if (name == "makeidx") {
91 } else if (name == "verbatim") {
93 } else if (name == "longtable") {
95 } else if (name == "algorithm") {
97 } else if (name == "rotating") {
99 } else if (name == "amssymb") {
101 } else if (name == "latexsym") {
103 } else if (name == "pifont") {
105 } else if (name == "subfigure") {
107 } else if (name == "floatflt") {
109 } else if (name == "url") {
111 } else if (name == "varioref") {
113 } else if (name == "prettyref") {
115 } else if (name == "chess") {
117 } else if (name == "amsstyle") {
119 } else if (name == "boldsymbol") {
121 } else if (name == "binom") {
127 string const LaTeXFeatures::getPackages()
130 LyXTextClass const & tclass =
131 textclasslist.TextClass(params.textclass);
135 packages += "\\usepackage{array}\n";
139 if (params.graphicsDriver == "default")
140 packages += "\\usepackage{color}\n";
142 packages += "\\usepackage["
143 + params.graphicsDriver + "]{color}\n";
148 if (! tclass.provides(LyXTextClass::makeidx)
149 && params.language->babel() != "french") // french provides
151 packages += "\\usepackage{makeidx}\n";
152 packages += "\\makeindex\n";
156 if (graphicx && params.graphicsDriver != "none") {
157 if (params.graphicsDriver == "default")
158 packages += "\\usepackage{graphicx}\n";
160 packages += "\\usepackage["
161 + params.graphicsDriver + "]{graphicx}\n";
164 // INSET_GRAPHICS: remove this when InsetFig is thrown.
166 if (graphics && params.graphicsDriver != "none") {
167 if (params.graphicsDriver == "default")
168 packages += "\\usepackage{graphics}\n";
170 packages += "\\usepackage["
171 + params.graphicsDriver + "]{graphics}\n";
176 packages += "\\usepackage{verbatim}\n";
179 packages += "\\usepackage{algorithm}\n";
184 packages += "\\usepackage{lyxchess}\n";
188 if ((params.spacing.getSpace() != Spacing::Single
189 && !params.spacing.isDefault())
191 packages += "\\usepackage{setspace}\n";
193 switch (params.spacing.getSpace()) {
194 case Spacing::Default:
195 case Spacing::Single:
196 // we dont use setspace.sty so dont print anything
197 //packages += "\\singlespacing\n";
199 case Spacing::Onehalf:
200 packages += "\\onehalfspacing\n";
202 case Spacing::Double:
203 packages += "\\doublespacing\n";
206 std::ostringstream value;
207 value << params.spacing.getValue(); // setw?
208 packages += string("\\setstretch{")
209 + value.str().c_str() + "}\n";
215 packages += "\\usepackage{longtable}\n";
219 packages += "\\usepackage{rotating}\n";
222 if (amssymb || params.use_amsmath)
223 packages += "\\usepackage{amssymb}\n";
227 packages += "\\usepackage{latexsym}\n";
231 packages += "\\usepackage{pifont}\n";
235 packages += "\\usepackage{subfigure}\n";
239 packages += "\\usepackage{floatflt}\n";
242 if (url && ! tclass.provides(LyXTextClass::url))
243 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
244 " {\\newcommand{\\url}{\\texttt}}\n";
248 packages += "\\usepackage{varioref}\n";
252 packages += "\\usepackage{prettyref}\n";
255 // This is not correct and needs fixing.
256 // We don't need float.sty if we only use unchanged
257 // table and figure floats. (Lgb)
258 if (!usedFloats.empty())
259 packages += "\\usepackage{float}\n";
261 packages += externalPreambles;
267 string const LaTeXFeatures::getMacros()
271 // always include this
273 macros += lyx_def + '\n';
276 macros += lyxline_def + '\n';
279 macros += noun_def + '\n';
283 macros += lyxarrow_def + '\n';
288 macros += quotesinglbase_def + '\n';
290 macros += quotedblbase_def + '\n';
292 macros += guilsinglleft_def + '\n';
294 macros += guilsinglright_def + '\n';
296 macros += guillemotleft_def + '\n';
298 macros += guillemotright_def + '\n';
301 if (boldsymbol && !amsstyle)
302 macros += boldsymbol_def + '\n';
303 if (binom && !amsstyle)
304 macros += binom_def + '\n';
307 if (NeedLyXMinipageIndent)
308 macros += minipageindent_def;
309 if (LyXParagraphIndent)
310 macros += paragraphindent_def;
311 if (NeedLyXFootnoteCode)
312 macros += floatingfootnote_def;
315 // Here we will output the code to create the needed float styles.
316 // We will try to do this as minimal as possible.
317 // \floatstyle{ruled}
318 // \newfloat{algorithm}{htbp}{loa}
319 // \floatname{algorithm}{Algorithm}
324 string const LaTeXFeatures::getTClassPreamble()
326 // the text class specific preamble
327 LyXTextClass const & tclass =
328 textclasslist.TextClass(params.textclass);
329 string tcpreamble = tclass.preamble();
331 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
333 tcpreamble += tclass[i].preamble();
341 string const LaTeXFeatures::getIncludedFiles()
344 FileMap::const_iterator end = IncludedFiles.end();
345 for (FileMap::const_iterator fi = IncludedFiles.begin();
347 sgmlpreamble += "\n<!entity " + fi->first
348 + " system \"" + fi->second + "\">";
354 void LaTeXFeatures::showStruct() {
355 lyxerr << "LyX needs the following commands when LaTeXing:"
356 << "\n***** Packages:" << getPackages()
357 << "\n***** Macros:" << getMacros()
358 << "\n***** Textclass stuff:" << getTClassPreamble()
359 << "\n***** done." << endl;
363 BufferParams const & LaTeXFeatures::bufferParams() const