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";
248 packages += externalPreambles;
254 string LaTeXFeatures::getMacros()
258 // always include this
260 macros += lyx_def + '\n';
263 macros += lyxline_def + '\n';
266 macros += noun_def + '\n';
270 macros += lyxarrow_def + '\n';
275 macros += quotesinglbase_def + '\n';
277 macros += quotedblbase_def + '\n';
279 macros += guilsinglleft_def + '\n';
281 macros += guilsinglright_def + '\n';
283 macros += guillemotleft_def + '\n';
285 macros += guillemotright_def + '\n';
288 if (boldsymbol && !amsstyle)
289 macros += boldsymbol_def + '\n';
290 if (binom && !amsstyle)
291 macros += binom_def + '\n';
294 if (NeedLyXMinipageIndent)
295 macros += minipageindent_def;
296 if (LyXParagraphIndent)
297 macros += paragraphindent_def;
298 if (NeedLyXFootnoteCode)
299 macros += floatingfootnote_def;
305 string LaTeXFeatures::getTClassPreamble()
307 // the text class specific preamble
308 LyXTextClass const & tclass =
309 textclasslist.TextClass(params.textclass);
310 string tcpreamble = tclass.preamble();
312 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
314 tcpreamble += tclass[i].preamble();
322 void LaTeXFeatures::showStruct() {
323 lyxerr << "LyX needs the following commands when LaTeXing:"
324 << "\n***** Packages:" << getPackages()
325 << "\n***** Macros:" << getMacros()
326 << "\n***** Textclass stuff:" << getTClassPreamble()
327 << "\n***** done." << endl;
331 BufferParams const & LaTeXFeatures::bufferParams() const