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;
77 void LaTeXFeatures::require(string const & name) {
78 if (name == "array") {
80 } else if (name == "color") {
82 } else if (name == "graphics") {
84 graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
85 } else if (name == "setspace") {
87 } else if (name == "makeidx") {
89 } else if (name == "verbatim") {
91 } else if (name == "longtable") {
93 } else if (name == "algorithm") {
95 } else if (name == "rotating") {
97 } else if (name == "amssymb") {
99 } else if (name == "latexsym") {
101 } else if (name == "pifont") {
103 } else if (name == "subfigure") {
105 } else if (name == "floatflt") {
107 } else if (name == "url") {
109 } else if (name == "varioref") {
111 } else if (name == "prettyref") {
113 } else if (name == "chess") {
115 } else if (name == "amsstyle") {
117 } else if (name == "boldsymbol") {
119 } else if (name == "binom") {
124 string LaTeXFeatures::getPackages()
127 LyXTextClass const & tclass =
128 textclasslist.TextClass(params.textclass);
132 packages += "\\usepackage{array}\n";
136 if (params.graphicsDriver == "default")
137 packages += "\\usepackage{color}\n";
139 packages += "\\usepackage["
140 + params.graphicsDriver + "]{color}\n";
145 if (! tclass.provides(LyXTextClass::makeidx)
146 && params.language != "french") // french provides
148 packages += "\\usepackage{makeidx}\n";
149 packages += "\\makeindex\n";
153 if (graphicx && params.graphicsDriver != "none") {
154 if (params.graphicsDriver == "default")
155 packages += "\\usepackage{graphicx}\n";
157 packages += "\\usepackage["
158 + params.graphicsDriver + "]{graphicx}\n";
161 // INSET_GRAPHICS: remove this when InsetFig is thrown.
163 if (graphics && params.graphicsDriver != "none") {
164 if (params.graphicsDriver == "default")
165 packages += "\\usepackage{graphics}\n";
167 packages += "\\usepackage["
168 + params.graphicsDriver + "]{graphics}\n";
173 packages += "\\usepackage{verbatim}\n";
176 packages += "\\usepackage{algorithm}\n";
181 packages += "\\usepackage{lyxchess}\n";
185 if ((params.spacing.getSpace() != Spacing::Single
186 && !params.spacing.isDefault())
188 packages += "\\usepackage{setspace}\n";
190 switch (params.spacing.getSpace()) {
191 case Spacing::Default:
192 case Spacing::Single:
193 // we dont use setspace.sty so dont print anything
194 //packages += "\\singlespacing\n";
196 case Spacing::Onehalf:
197 packages += "\\onehalfspacing\n";
199 case Spacing::Double:
200 packages += "\\doublespacing\n";
204 std::ostringstream value;
207 ostrstream value(val, 30);
210 value << params.spacing.getValue(); // setw?
212 packages += string("\\setstretch{")
213 + value.str().c_str() + "}\n";
216 packages += string("\\setstretch{")
217 + value.str() + "}\n";
224 packages += "\\usepackage{longtable}\n";
228 packages += "\\usepackage{rotating}\n";
231 if (amssymb || params.use_amsmath)
232 packages += "\\usepackage{amssymb}\n";
236 packages += "\\usepackage{latexsym}\n";
240 packages += "\\usepackage{pifont}\n";
244 packages += "\\usepackage{subfigure}\n";
248 packages += "\\usepackage{floatflt}\n";
251 if (url && ! tclass.provides(LyXTextClass::url))
252 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
253 " {\\newcommand{\\url}{\\texttt}}\n";
257 packages += "\\usepackage{varioref}\n";
261 packages += "\\usepackage{prettyref}\n";
264 // This is not correct and needs fixing.
265 // We don't need float.sty if we only use unchanged
266 // table and figure floats. (Lgb)
267 if (!usedFloats.empty())
268 packages += "\\usepackage{float}\n";
270 packages += externalPreambles;
276 string LaTeXFeatures::getMacros()
280 // always include this
282 macros += lyx_def + '\n';
285 macros += lyxline_def + '\n';
288 macros += noun_def + '\n';
292 macros += lyxarrow_def + '\n';
297 macros += quotesinglbase_def + '\n';
299 macros += quotedblbase_def + '\n';
301 macros += guilsinglleft_def + '\n';
303 macros += guilsinglright_def + '\n';
305 macros += guillemotleft_def + '\n';
307 macros += guillemotright_def + '\n';
310 if (boldsymbol && !amsstyle)
311 macros += boldsymbol_def + '\n';
312 if (binom && !amsstyle)
313 macros += binom_def + '\n';
316 if (NeedLyXMinipageIndent)
317 macros += minipageindent_def;
318 if (LyXParagraphIndent)
319 macros += paragraphindent_def;
320 if (NeedLyXFootnoteCode)
321 macros += floatingfootnote_def;
324 // Here we will output the code to create the needed float styles.
325 // We will try to do this as minimal as possible.
326 // \floatstyle{ruled}
327 // \newfloat{algorithm}{htbp}{loa}
328 // \floatname{algorithm}{Algorithm}
333 string LaTeXFeatures::getTClassPreamble()
335 // the text class specific preamble
336 LyXTextClass const & tclass =
337 textclasslist.TextClass(params.textclass);
338 string tcpreamble = tclass.preamble();
340 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
342 tcpreamble += tclass[i].preamble();
350 string LaTeXFeatures::getIncludedFiles()
354 for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
355 sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
361 void LaTeXFeatures::showStruct() {
362 lyxerr << "LyX needs the following commands when LaTeXing:"
363 << "\n***** Packages:" << getPackages()
364 << "\n***** Macros:" << getMacros()
365 << "\n***** Textclass stuff:" << getTClassPreamble()
366 << "\n***** done." << endl;
370 BufferParams const & LaTeXFeatures::bufferParams() const