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"
25 #include "support/filetools.h"
26 #include "FloatList.h"
30 LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
31 : layout(n, false), params(p)
36 graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
61 quotesinglbase = false;
63 guilsinglleft = false;
64 guilsinglright = false;
65 guillemotleft = false;
66 guillemotright = false;
74 LyXParagraphIndent = false;
75 NeedLyXFootnoteCode = false;
76 NeedLyXMinipageIndent = false;
80 void LaTeXFeatures::require(string const & name)
82 if (name == "array") {
84 } else if (name == "color") {
86 } else if (name == "graphics") {
88 graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
89 } else if (name == "setspace") {
91 } else if (name == "makeidx") {
93 } else if (name == "verbatim") {
95 } else if (name == "longtable") {
97 } else if (name == "algorithm") {
99 } else if (name == "rotating") {
101 } else if (name == "amssymb") {
103 } else if (name == "latexsym") {
105 } else if (name == "pifont") {
107 } else if (name == "subfigure") {
109 } else if (name == "floatflt") {
111 } else if (name == "url") {
113 } else if (name == "varioref") {
115 } else if (name == "prettyref") {
117 } else if (name == "chess") {
119 } else if (name == "amsstyle") {
121 } else if (name == "boldsymbol") {
123 } else if (name == "binom") {
129 string const LaTeXFeatures::getPackages()
132 LyXTextClass const & tclass =
133 textclasslist.TextClass(params.textclass);
137 packages += "\\usepackage{array}\n";
141 if (params.graphicsDriver == "default")
142 packages += "\\usepackage{color}\n";
144 packages += "\\usepackage["
145 + params.graphicsDriver + "]{color}\n";
150 if (! tclass.provides(LyXTextClass::makeidx)
151 && params.language->babel() != "french") // french provides
153 packages += "\\usepackage{makeidx}\n";
154 packages += "\\makeindex\n";
158 if (graphicx && params.graphicsDriver != "none") {
159 if (params.graphicsDriver == "default")
160 packages += "\\usepackage{graphicx}\n";
162 packages += "\\usepackage["
163 + params.graphicsDriver + "]{graphicx}\n";
166 // INSET_GRAPHICS: remove this when InsetFig is thrown.
168 if (graphics && params.graphicsDriver != "none") {
169 if (params.graphicsDriver == "default")
170 packages += "\\usepackage{graphics}\n";
172 packages += "\\usepackage["
173 + params.graphicsDriver + "]{graphics}\n";
178 packages += "\\usepackage{verbatim}\n";
181 packages += "\\usepackage{algorithm}\n";
186 packages += "\\usepackage{lyxchess}\n";
190 if ((params.spacing.getSpace() != Spacing::Single
191 && !params.spacing.isDefault())
193 packages += "\\usepackage{setspace}\n";
195 switch (params.spacing.getSpace()) {
196 case Spacing::Default:
197 case Spacing::Single:
198 // we dont use setspace.sty so dont print anything
199 //packages += "\\singlespacing\n";
201 case Spacing::Onehalf:
202 packages += "\\onehalfspacing\n";
204 case Spacing::Double:
205 packages += "\\doublespacing\n";
208 std::ostringstream value;
209 value << params.spacing.getValue(); // setw?
210 packages += string("\\setstretch{")
211 + value.str().c_str() + "}\n";
217 packages += "\\usepackage{longtable}\n";
221 packages += "\\usepackage{rotating}\n";
224 if (amssymb || params.use_amsmath)
225 packages += "\\usepackage{amssymb}\n";
229 packages += "\\usepackage{latexsym}\n";
233 packages += "\\usepackage{pifont}\n";
237 packages += "\\usepackage{subfigure}\n";
241 packages += "\\usepackage{floatflt}\n";
244 if (url && ! tclass.provides(LyXTextClass::url))
245 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
246 " {\\newcommand{\\url}{\\texttt}}\n";
250 packages += "\\usepackage{varioref}\n";
254 packages += "\\usepackage{prettyref}\n";
257 // We only need float.sty if we use non builtin floats. This includes
258 // modified table and figure floats. (Lgb)
259 if (!usedFloats.empty()) {
260 bool use_float = false;
261 UsedFloats::const_iterator beg = usedFloats.begin();
262 UsedFloats::const_iterator end = usedFloats.end();
263 for (; beg != end; ++beg) {
264 Floating const & fl = floatList.getType((*beg));
265 if (!fl.type().empty() && !fl.builtin()) {
271 packages += "\\usepackage{float}\n";
274 packages += externalPreambles;
280 string const LaTeXFeatures::getMacros()
284 // always include this
286 macros += lyx_def + '\n';
289 macros += lyxline_def + '\n';
292 macros += noun_def + '\n';
296 macros += lyxarrow_def + '\n';
301 macros += quotesinglbase_def + '\n';
303 macros += quotedblbase_def + '\n';
305 macros += guilsinglleft_def + '\n';
307 macros += guilsinglright_def + '\n';
309 macros += guillemotleft_def + '\n';
311 macros += guillemotright_def + '\n';
314 if (boldsymbol && !amsstyle)
315 macros += boldsymbol_def + '\n';
316 if (binom && !amsstyle)
317 macros += binom_def + '\n';
320 if (NeedLyXMinipageIndent)
321 macros += minipageindent_def;
322 if (LyXParagraphIndent)
323 macros += paragraphindent_def;
324 if (NeedLyXFootnoteCode)
325 macros += floatingfootnote_def;
328 // Here we will output the code to create the needed float styles.
329 // We will try to do this as minimal as possible.
330 // \floatstyle{ruled}
331 // \newfloat{algorithm}{htbp}{loa}
332 // \floatname{algorithm}{Algorithm}
333 UsedFloats::const_iterator cit = usedFloats.begin();
334 UsedFloats::const_iterator end = usedFloats.end();
335 ostringstream floats;
336 for (; cit != end; ++cit) {
337 Floating const & fl = floatList.getType((*cit));
339 // For builtin floats we do nothing.
340 if (fl.builtin()) continue;
342 // We have to special case "table" and "figure"
343 if (fl.type() == "tabular" || fl.type() == "figure") {
344 // Output code to modify "table" or "figure"
345 // but only if builtin == false
347 // The other non builtin floats.
349 string type = fl.type();
350 string placement = fl.placement();
351 string ext = fl.ext();
352 string within = fl.within();
353 string style = fl.style();
354 string name = fl.name();
355 floats << "\\floatstyle{" << style << "}\n"
356 << "\\newfloat{" << type << "}{" << placement
357 << "}{" << ext << "}";
359 floats << "[" << within << "]";
361 << "\\floatname{" << type << "}{"
364 // What missing here is to code to minimalize the code
365 // outputted so that the same flotastyle will not be
366 // used several times. when the same style is still in
370 macros += floats.str().c_str();
372 for (LanguageList::const_iterator cit = UsedLanguages.begin();
373 cit != UsedLanguages.end(); ++cit)
374 if (!(*cit)->latex_options().empty())
375 macros += (*cit)->latex_options() + '\n';
376 if (!params.language->latex_options().empty())
377 macros += params.language->latex_options() + '\n';
383 string const LaTeXFeatures::getTClassPreamble()
385 // the text class specific preamble
386 LyXTextClass const & tclass =
387 textclasslist.TextClass(params.textclass);
388 string tcpreamble = tclass.preamble();
390 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
392 tcpreamble += tclass[i].preamble();
400 string const LaTeXFeatures::getIncludedFiles(string const fname) const
403 string basename = OnlyPath(fname);
405 FileMap::const_iterator end = IncludedFiles.end();
406 for (FileMap::const_iterator fi = IncludedFiles.begin();
408 sgmlpreamble += "\n<!ENTITY " + fi->first
409 + (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
410 + MakeRelPath(fi->second,basename) + "\">";
416 void LaTeXFeatures::showStruct() {
417 lyxerr << "LyX needs the following commands when LaTeXing:"
418 << "\n***** Packages:" << getPackages()
419 << "\n***** Macros:" << getMacros()
420 << "\n***** Textclass stuff:" << getTClassPreamble()
421 << "\n***** done." << endl;
425 BufferParams const & LaTeXFeatures::bufferParams() const