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"
31 LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
32 : layout(n, false), params(p)
37 graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
62 quotesinglbase = false;
64 guilsinglleft = false;
65 guilsinglright = false;
66 guillemotleft = false;
67 guillemotright = false;
75 LyXParagraphIndent = false;
76 NeedLyXFootnoteCode = false;
77 NeedLyXMinipageIndent = false;
81 void LaTeXFeatures::require(string const & name)
83 if (name == "array") {
85 } else if (name == "color") {
87 } else if (name == "graphics") {
89 graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
90 } else if (name == "setspace") {
92 } else if (name == "makeidx") {
94 } else if (name == "verbatim") {
96 } else if (name == "longtable") {
98 } else if (name == "algorithm") {
100 } else if (name == "rotating") {
102 } else if (name == "amssymb") {
104 } else if (name == "latexsym") {
106 } else if (name == "pifont") {
108 } else if (name == "subfigure") {
110 } else if (name == "floatflt") {
112 } else if (name == "url") {
114 } else if (name == "varioref") {
116 } else if (name == "prettyref") {
118 } else if (name == "chess") {
120 } else if (name == "amsstyle") {
122 } else if (name == "boldsymbol") {
124 } else if (name == "binom") {
130 string const LaTeXFeatures::getPackages()
133 LyXTextClass const & tclass =
134 textclasslist.TextClass(params.textclass);
138 packages += "\\usepackage{array}\n";
142 if (params.graphicsDriver == "default")
143 packages += "\\usepackage{color}\n";
145 packages += "\\usepackage["
146 + params.graphicsDriver + "]{color}\n";
151 if (! tclass.provides(LyXTextClass::makeidx)
152 && params.language->babel() != "french") // french provides
154 packages += "\\usepackage{makeidx}\n";
155 packages += "\\makeindex\n";
159 if (graphicx && params.graphicsDriver != "none") {
160 if (params.graphicsDriver == "default")
161 packages += "\\usepackage{graphicx}\n";
163 packages += "\\usepackage["
164 + params.graphicsDriver + "]{graphicx}\n";
167 // INSET_GRAPHICS: remove this when InsetFig is thrown.
169 if (graphics && params.graphicsDriver != "none") {
170 if (params.graphicsDriver == "default")
171 packages += "\\usepackage{graphics}\n";
173 packages += "\\usepackage["
174 + params.graphicsDriver + "]{graphics}\n";
179 packages += "\\usepackage{verbatim}\n";
182 packages += "\\usepackage{algorithm}\n";
187 packages += "\\usepackage{lyxchess}\n";
191 if ((params.spacing.getSpace() != Spacing::Single
192 && !params.spacing.isDefault())
194 packages += "\\usepackage{setspace}\n";
196 switch (params.spacing.getSpace()) {
197 case Spacing::Default:
198 case Spacing::Single:
199 // we dont use setspace.sty so dont print anything
200 //packages += "\\singlespacing\n";
202 case Spacing::Onehalf:
203 packages += "\\onehalfspacing\n";
205 case Spacing::Double:
206 packages += "\\doublespacing\n";
209 std::ostringstream value;
210 value << params.spacing.getValue(); // setw?
211 packages += string("\\setstretch{")
212 + value.str().c_str() + "}\n";
218 packages += "\\usepackage{longtable}\n";
222 packages += "\\usepackage{rotating}\n";
225 if (amssymb || params.use_amsmath)
226 packages += "\\usepackage{amssymb}\n";
230 packages += "\\usepackage{latexsym}\n";
234 packages += "\\usepackage{pifont}\n";
238 packages += "\\usepackage{subfigure}\n";
242 packages += "\\usepackage{floatflt}\n";
245 if (url && ! tclass.provides(LyXTextClass::url))
246 packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
247 " {\\newcommand{\\url}{\\texttt}}\n";
251 packages += "\\usepackage{varioref}\n";
255 packages += "\\usepackage{prettyref}\n";
258 // We only need float.sty if we use non builtin floats. This includes
259 // modified table and figure floats. (Lgb)
260 if (!usedFloats.empty()) {
261 bool use_float = false;
262 UsedFloats::const_iterator beg = usedFloats.begin();
263 UsedFloats::const_iterator end = usedFloats.end();
264 for (; beg != end; ++beg) {
265 Floating const & fl = floatList.getType((*beg));
266 if (!fl.type().empty() && !fl.builtin()) {
272 packages += "\\usepackage{float}\n";
275 packages += externalPreambles;
281 string const LaTeXFeatures::getMacros()
285 // always include this
287 macros += lyx_def + '\n';
290 macros += lyxline_def + '\n';
293 macros += noun_def + '\n';
297 macros += lyxarrow_def + '\n';
302 macros += quotesinglbase_def + '\n';
304 macros += quotedblbase_def + '\n';
306 macros += guilsinglleft_def + '\n';
308 macros += guilsinglright_def + '\n';
310 macros += guillemotleft_def + '\n';
312 macros += guillemotright_def + '\n';
315 if (boldsymbol && !amsstyle)
316 macros += boldsymbol_def + '\n';
317 if (binom && !amsstyle)
318 macros += binom_def + '\n';
321 if (NeedLyXMinipageIndent)
322 macros += minipageindent_def;
323 if (LyXParagraphIndent)
324 macros += paragraphindent_def;
325 if (NeedLyXFootnoteCode)
326 macros += floatingfootnote_def;
329 // Here we will output the code to create the needed float styles.
330 // We will try to do this as minimal as possible.
331 // \floatstyle{ruled}
332 // \newfloat{algorithm}{htbp}{loa}
333 // \floatname{algorithm}{Algorithm}
334 UsedFloats::const_iterator cit = usedFloats.begin();
335 UsedFloats::const_iterator end = usedFloats.end();
336 ostringstream floats;
337 for (; cit != end; ++cit) {
338 Floating const & fl = floatList.getType((*cit));
340 // For builtin floats we do nothing.
341 if (fl.builtin()) continue;
343 // We have to special case "table" and "figure"
344 if (fl.type() == "tabular" || fl.type() == "figure") {
345 // Output code to modify "table" or "figure"
346 // but only if builtin == false
348 // The other non builtin floats.
350 string type = fl.type();
351 string placement = fl.placement();
352 string ext = fl.ext();
353 string within = fl.within();
354 string style = fl.style();
355 string name = fl.name();
356 floats << "\\floatstyle{" << style << "}\n"
357 << "\\newfloat{" << type << "}{" << placement
358 << "}{" << ext << "}";
360 floats << "[" << within << "]";
362 << "\\floatname{" << type << "}{"
365 // What missing here is to code to minimalize the code
366 // outputted so that the same flotastyle will not be
367 // used several times. when the same style is still in
371 macros += floats.str().c_str();
373 for (LanguageList::const_iterator cit = UsedLanguages.begin();
374 cit != UsedLanguages.end(); ++cit)
375 if (!(*cit)->latex_options().empty())
376 macros += (*cit)->latex_options() + '\n';
377 if (!params.language->latex_options().empty())
378 macros += params.language->latex_options() + '\n';
384 string const LaTeXFeatures::getTClassPreamble()
386 // the text class specific preamble
387 LyXTextClass const & tclass =
388 textclasslist.TextClass(params.textclass);
389 string tcpreamble = tclass.preamble();
391 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
393 tcpreamble += tclass[i].preamble();
401 string const LaTeXFeatures::getIncludedFiles(string const fname) const
404 string basename = OnlyPath(fname);
406 FileMap::const_iterator end = IncludedFiles.end();
407 for (FileMap::const_iterator fi = IncludedFiles.begin();
409 sgmlpreamble += "\n<!ENTITY " + fi->first
410 + (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
411 + MakeRelPath(fi->second,basename) + "\">";
417 void LaTeXFeatures::showStruct() {
418 lyxerr << "LyX needs the following commands when LaTeXing:"
419 << "\n***** Packages:" << getPackages()
420 << "\n***** Macros:" << getMacros()
421 << "\n***** Textclass stuff:" << getTClassPreamble()
422 << "\n***** done." << endl;
426 BufferParams const & LaTeXFeatures::bufferParams() const