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, int 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 != "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 //#ifdef HAVE_SSTREAM
207 std::ostringstream value;
210 // ostrstream value(val, 30);
213 value << params.spacing.getValue(); // setw?
214 //#ifdef HAVE_SSTREAM
215 packages += string("\\setstretch{")
216 + value.str().c_str() + "}\n";
219 // packages += string("\\setstretch{")
220 // + value.str() + "}\n";
227 packages += "\\usepackage{longtable}\n";
231 packages += "\\usepackage{rotating}\n";
234 if (amssymb || params.use_amsmath)
235 packages += "\\usepackage{amssymb}\n";
239 packages += "\\usepackage{latexsym}\n";
243 packages += "\\usepackage{pifont}\n";
247 packages += "\\usepackage{subfigure}\n";
251 packages += "\\usepackage{floatflt}\n";
254 if (url && ! tclass.provides(LyXTextClass::url))
255 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
256 " {\\newcommand{\\url}{\\texttt}}\n";
260 packages += "\\usepackage{varioref}\n";
264 packages += "\\usepackage{prettyref}\n";
267 // This is not correct and needs fixing.
268 // We don't need float.sty if we only use unchanged
269 // table and figure floats. (Lgb)
270 if (!usedFloats.empty())
271 packages += "\\usepackage{float}\n";
273 packages += externalPreambles;
279 string const LaTeXFeatures::getMacros()
283 // always include this
285 macros += lyx_def + '\n';
288 macros += lyxline_def + '\n';
291 macros += noun_def + '\n';
295 macros += lyxarrow_def + '\n';
300 macros += quotesinglbase_def + '\n';
302 macros += quotedblbase_def + '\n';
304 macros += guilsinglleft_def + '\n';
306 macros += guilsinglright_def + '\n';
308 macros += guillemotleft_def + '\n';
310 macros += guillemotright_def + '\n';
313 if (boldsymbol && !amsstyle)
314 macros += boldsymbol_def + '\n';
315 if (binom && !amsstyle)
316 macros += binom_def + '\n';
319 if (NeedLyXMinipageIndent)
320 macros += minipageindent_def;
321 if (LyXParagraphIndent)
322 macros += paragraphindent_def;
323 if (NeedLyXFootnoteCode)
324 macros += floatingfootnote_def;
327 // Here we will output the code to create the needed float styles.
328 // We will try to do this as minimal as possible.
329 // \floatstyle{ruled}
330 // \newfloat{algorithm}{htbp}{loa}
331 // \floatname{algorithm}{Algorithm}
336 string const LaTeXFeatures::getTClassPreamble()
338 // the text class specific preamble
339 LyXTextClass const & tclass =
340 textclasslist.TextClass(params.textclass);
341 string tcpreamble = tclass.preamble();
343 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
345 tcpreamble += tclass[i].preamble();
353 string const LaTeXFeatures::getIncludedFiles()
356 FileMap::const_iterator end = IncludedFiles.end();
357 for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != end; ++fi)
358 sgmlpreamble += "\n<!entity " + fi->first
359 + " system \"" + fi->second + "\">";
365 void LaTeXFeatures::showStruct() {
366 lyxerr << "LyX needs the following commands when LaTeXing:"
367 << "\n***** Packages:" << getPackages()
368 << "\n***** Macros:" << getMacros()
369 << "\n***** Textclass stuff:" << getTClassPreamble()
370 << "\n***** done." << endl;
374 BufferParams const & LaTeXFeatures::bufferParams() const