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)
58 quotesinglbase = false;
60 guilsinglleft = false;
61 guilsinglright = false;
62 guillemotleft = false;
63 guillemotright = false;
71 LyXParagraphIndent = false;
72 NeedLyXFootnoteCode = false;
73 NeedLyXMinipageIndent = false;
76 void LaTeXFeatures::require(string const & name) {
77 if (name == "array") {
79 } else if (name == "color") {
81 } else if (name == "graphics") {
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") {
126 string LaTeXFeatures::getPackages()
129 LyXTextClass const & tclass =
130 textclasslist.TextClass(params.textclass);
134 packages += "\\usepackage{array}\n";
138 if (params.graphicsDriver == "default")
139 packages += "\\usepackage{color}\n";
141 packages += "\\usepackage["
142 + params.graphicsDriver + "]{color}\n";
147 if (! tclass.provides(LyXTextClass::makeidx)
148 && params.language != "french") // french provides
150 packages += "\\usepackage{makeidx}\n";
151 packages += "\\makeindex\n";
155 if (graphics && params.graphicsDriver != "none") {
156 if (params.graphicsDriver == "default")
157 packages += "\\usepackage{graphics}\n";
159 packages += "\\usepackage["
160 + params.graphicsDriver + "]{graphics}\n";
165 packages += "\\usepackage{verbatim}\n";
168 packages += "\\usepackage{algorithm}\n";
173 packages += "\\usepackage{lyxchess}\n";
177 if ((params.spacing.getSpace() != Spacing::Single
178 && !params.spacing.isDefault())
180 packages += "\\usepackage{setspace}\n";
182 switch (params.spacing.getSpace()) {
183 case Spacing::Default:
184 case Spacing::Single:
185 // we dont use setspace.sty so dont print anything
186 //packages += "\\singlespacing\n";
188 case Spacing::Onehalf:
189 packages += "\\onehalfspacing\n";
191 case Spacing::Double:
192 packages += "\\doublespacing\n";
196 std::ostringstream value;
199 ostrstream value(val, 30);
202 value << params.spacing.getValue(); // setw?
204 packages += string("\\setstretch{")
205 + value.str().c_str() + "}\n";
208 packages += string("\\setstretch{")
209 + value.str() + "}\n";
216 packages += "\\usepackage{longtable}\n";
220 packages += "\\usepackage{rotating}\n";
223 if (amssymb || params.use_amsmath)
224 packages += "\\usepackage{amssymb}\n";
228 packages += "\\usepackage{latexsym}\n";
232 packages += "\\usepackage{pifont}\n";
236 packages += "\\usepackage{subfigure}\n";
240 packages += "\\usepackage{floatflt}\n";
243 if (url && ! tclass.provides(LyXTextClass::url))
244 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
245 " {\\newcommand{\\url}{\\texttt}}\n";
249 packages += "\\usepackage{varioref}\n";
253 packages += "\\usepackage{prettyref}\n";
256 // This is not correct and needs fixing.
257 // We don't need float.sty if we only use unchanged
258 // table and figure floats. (Lgb)
259 if (!usedFloats.empty())
260 packages += "\\usepackage{float}\n";
262 packages += externalPreambles;
268 string LaTeXFeatures::getMacros()
272 // always include this
274 macros += lyx_def + '\n';
277 macros += lyxline_def + '\n';
280 macros += noun_def + '\n';
284 macros += lyxarrow_def + '\n';
289 macros += quotesinglbase_def + '\n';
291 macros += quotedblbase_def + '\n';
293 macros += guilsinglleft_def + '\n';
295 macros += guilsinglright_def + '\n';
297 macros += guillemotleft_def + '\n';
299 macros += guillemotright_def + '\n';
302 if (boldsymbol && !amsstyle)
303 macros += boldsymbol_def + '\n';
304 if (binom && !amsstyle)
305 macros += binom_def + '\n';
308 if (NeedLyXMinipageIndent)
309 macros += minipageindent_def;
310 if (LyXParagraphIndent)
311 macros += paragraphindent_def;
312 if (NeedLyXFootnoteCode)
313 macros += floatingfootnote_def;
316 // Here we will output the code to create the needed float styles.
317 // We will try to do this as minimal as possible.
318 // \floatstyle{ruled}
319 // \newfloat{algorithm}{htbp}{loa}
320 // \floatname{algorithm}{Algorithm}
325 string LaTeXFeatures::getTClassPreamble()
327 // the text class specific preamble
328 LyXTextClass const & tclass =
329 textclasslist.TextClass(params.textclass);
330 string tcpreamble = tclass.preamble();
332 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
334 tcpreamble += tclass[i].preamble();
342 string LaTeXFeatures::getIncludedFiles()
346 for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
347 sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
353 void LaTeXFeatures::showStruct() {
354 lyxerr << "LyX needs the following commands when LaTeXing:"
355 << "\n***** Packages:" << getPackages()
356 << "\n***** Macros:" << getMacros()
357 << "\n***** Textclass stuff:" << getTClassPreamble()
358 << "\n***** done." << endl;
362 BufferParams const & LaTeXFeatures::bufferParams() const