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)
57 quotesinglbase = false;
59 guilsinglleft = false;
60 guilsinglright = false;
61 guillemotleft = false;
62 guillemotright = false;
70 LyXParagraphIndent = false;
71 NeedLyXFootnoteCode = false;
72 NeedLyXMinipageIndent = false;
75 void LaTeXFeatures::require(string const & name) {
76 if (name == "color") {
78 } else if (name == "graphics") {
84 } else if (name == "setspace") {
86 } else if (name == "makeidx") {
88 } else if (name == "verbatim") {
90 } else if (name == "longtable") {
92 } else if (name == "algorithm") {
94 } else if (name == "rotating") {
96 } else if (name == "amssymb") {
98 } else if (name == "latexsym") {
100 } else if (name == "pifont") {
102 } else if (name == "subfigure") {
104 } else if (name == "floatflt") {
106 } else if (name == "url") {
108 } else if (name == "varioref") {
110 } else if (name == "prettyref") {
112 } else if (name == "chess") {
114 } else if (name == "amsstyle") {
116 } else if (name == "boldsymbol") {
118 } else if (name == "binom") {
123 string LaTeXFeatures::getPackages()
126 LyXTextClass const & tclass =
127 textclasslist.TextClass(params.textclass);
131 if (params.graphicsDriver == "default")
132 packages += "\\usepackage{color}\n";
134 packages += "\\usepackage["
135 + params.graphicsDriver + "]{color}\n";
140 if (! tclass.provides(LyXTextClass::makeidx)
141 && params.language != "french") // french provides
143 packages += "\\usepackage{makeidx}\n";
144 packages += "\\makeindex\n";
148 if (graphics && params.graphicsDriver != "none") {
149 if (params.graphicsDriver == "default")
150 packages += "\\usepackage{graphics}\n";
152 packages += "\\usepackage["
153 + params.graphicsDriver + "]{graphics}\n";
158 packages += "\\usepackage{verbatim}\n";
161 packages += "\\usepackage{algorithm}\n";
166 packages += "\\usepackage{lyxchess}\n";
170 if ((params.spacing.getSpace() != Spacing::Single
171 && !params.spacing.isDefault())
173 packages += "\\usepackage{setspace}\n";
175 switch (params.spacing.getSpace()) {
176 case Spacing::Default:
177 case Spacing::Single:
178 // we dont use setspace.sty so dont print anything
179 //packages += "\\singlespacing\n";
181 case Spacing::Onehalf:
182 packages += "\\onehalfspacing\n";
184 case Spacing::Double:
185 packages += "\\doublespacing\n";
189 std::ostringstream value;
192 ostrstream value(val, 30);
195 value << params.spacing.getValue(); // setw?
197 packages += string("\\setstretch{")
198 + value.str().c_str() + "}\n";
201 packages += string("\\setstretch{")
202 + value.str() + "}\n";
209 packages += "\\usepackage{longtable}\n";
213 packages += "\\usepackage{rotating}\n";
216 if (amssymb || params.use_amsmath)
217 packages += "\\usepackage{amssymb}\n";
221 packages += "\\usepackage{latexsym}\n";
225 packages += "\\usepackage{pifont}\n";
229 packages += "\\usepackage{subfigure}\n";
233 packages += "\\usepackage{floatflt}\n";
236 if (url && ! tclass.provides(LyXTextClass::url))
237 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
238 " {\\newcommand{\\url}{\\texttt}}\n";
242 packages += "\\usepackage{varioref}\n";
246 packages += "\\usepackage{prettyref}\n";
249 // This is not correct and needs fixing.
250 // We don't need float.sty if we only use unchanged
251 // table and figure floats. (Lgb)
252 if (!usedFloats.empty())
253 packages += "\\usepackage{float}\n";
255 packages += externalPreambles;
261 string LaTeXFeatures::getMacros()
265 // always include this
267 macros += lyx_def + '\n';
270 macros += lyxline_def + '\n';
273 macros += noun_def + '\n';
277 macros += lyxarrow_def + '\n';
282 macros += quotesinglbase_def + '\n';
284 macros += quotedblbase_def + '\n';
286 macros += guilsinglleft_def + '\n';
288 macros += guilsinglright_def + '\n';
290 macros += guillemotleft_def + '\n';
292 macros += guillemotright_def + '\n';
295 if (boldsymbol && !amsstyle)
296 macros += boldsymbol_def + '\n';
297 if (binom && !amsstyle)
298 macros += binom_def + '\n';
301 if (NeedLyXMinipageIndent)
302 macros += minipageindent_def;
303 if (LyXParagraphIndent)
304 macros += paragraphindent_def;
305 if (NeedLyXFootnoteCode)
306 macros += floatingfootnote_def;
309 // Here we will output the code to create the needed float styles.
310 // We will try to do this as minimal as possible.
311 // \floatstyle{ruled}
312 // \newfloat{algorithm}{htbp}{loa}
313 // \floatname{algorithm}{Algorithm}
318 string LaTeXFeatures::getTClassPreamble()
320 // the text class specific preamble
321 LyXTextClass const & tclass =
322 textclasslist.TextClass(params.textclass);
323 string tcpreamble = tclass.preamble();
325 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
327 tcpreamble += tclass[i].preamble();
335 string LaTeXFeatures::getIncludedFiles()
339 for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
340 sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
346 void LaTeXFeatures::showStruct() {
347 lyxerr << "LyX needs the following commands when LaTeXing:"
348 << "\n***** Packages:" << getPackages()
349 << "\n***** Macros:" << getMacros()
350 << "\n***** Textclass stuff:" << getTClassPreamble()
351 << "\n***** done." << endl;
355 BufferParams const & LaTeXFeatures::bufferParams() const