1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 the LyX Team.
9 * ====================================================== */
14 #pragma implementation "LaTeXFeatures.h"
21 #include "LaTeXFeatures.h"
22 #include "bufferparams.h"
24 #include "support/filetools.h"
25 #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.
62 quotesinglbase = false;
64 guilsinglleft = false;
65 guilsinglright = false;
66 guillemotleft = false;
67 guillemotright = false;
75 ParagraphIndent = 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") {
126 } else if (name == "natbib") {
132 string const LaTeXFeatures::getPackages() const
134 ostringstream packages;
135 LyXTextClass const & tclass =
136 textclasslist.TextClass(params.textclass);
140 packages << "\\usepackage{array}\n";
144 if (params.graphicsDriver == "default")
145 packages << "\\usepackage{color}\n";
147 packages << "\\usepackage["
148 << params.graphicsDriver
154 if (! tclass.provides(LyXTextClass::makeidx)
155 && params.language->babel() != "french") // french provides
157 // French should not be hardcoded. (Lgb)
158 packages << "\\usepackage{makeidx}\n";
159 packages << "\\makeindex\n";
163 if (graphicx && params.graphicsDriver != "none") {
164 if (params.graphicsDriver == "default")
165 packages << "\\usepackage{graphicx}\n";
167 packages << "\\usepackage["
168 << params.graphicsDriver
172 // INSET_GRAPHICS: remove this when InsetFig is thrown.
174 if (graphics && params.graphicsDriver != "none") {
175 if (params.graphicsDriver == "default")
176 packages << "\\usepackage{graphics}\n";
178 packages << "\\usepackage["
179 << params.graphicsDriver
185 packages << "\\usepackage{verbatim}\n";
188 // packages << "\\usepackage{algorithm}\n";
193 packages << "\\usepackage{lyxchess}\n";
197 if ((params.spacing.getSpace() != Spacing::Single
198 && !params.spacing.isDefault())
200 packages << "\\usepackage{setspace}\n";
202 switch (params.spacing.getSpace()) {
203 case Spacing::Default:
204 case Spacing::Single:
205 // we dont use setspace.sty so dont print anything
206 //packages += "\\singlespacing\n";
208 case Spacing::Onehalf:
209 packages << "\\onehalfspacing\n";
211 case Spacing::Double:
212 packages << "\\doublespacing\n";
215 packages << "\\setstretch{"
216 << params.spacing.getValue() << "}\n";
222 packages << "\\usepackage{longtable}\n";
226 packages << "\\usepackage{rotating}\n";
229 if (amssymb || params.use_amsmath)
230 packages << "\\usepackage{amssymb}\n";
234 packages << "\\usepackage{latexsym}\n";
238 packages << "\\usepackage{pifont}\n";
242 packages << "\\usepackage{subfigure}\n";
246 packages << "\\usepackage{floatflt}\n";
249 if (url && ! tclass.provides(LyXTextClass::url))
250 packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
251 " {\\newcommand{\\url}{\\texttt}}\n";
255 packages << "\\usepackage{varioref}\n";
259 packages << "\\usepackage{prettyref}\n";
262 // We only need float.sty if we use non builtin floats. This includes
263 // modified table and figure floats. (Lgb)
264 if (!usedFloats.empty()) {
265 bool use_float = false;
266 UsedFloats::const_iterator beg = usedFloats.begin();
267 UsedFloats::const_iterator end = usedFloats.end();
268 for (; beg != end; ++beg) {
269 Floating const & fl = floatList.getType((*beg));
270 if (!fl.type().empty() && !fl.builtin()) {
276 packages << "\\usepackage{float}\n";
281 packages << "\\usepackage[";
282 if (params.use_numerical_citations) {
283 packages << "numbers";
285 packages << "authoryear";
287 packages << "]{natbib}\n";
290 packages << externalPreambles;
292 return packages.str().c_str();
296 string const LaTeXFeatures::getMacros() const
298 ostringstream macros;
300 // always include this
302 macros << lyx_def << '\n';
305 macros << lyxline_def << '\n';
308 macros << noun_def << '\n';
312 macros << lyxarrow_def << '\n';
317 macros << quotesinglbase_def << '\n';
319 macros << quotedblbase_def << '\n';
321 macros << guilsinglleft_def << '\n';
323 macros << guilsinglright_def << '\n';
325 macros << guillemotleft_def << '\n';
327 macros << guillemotright_def << '\n';
330 if (boldsymbol && !amsstyle)
331 macros << boldsymbol_def << '\n';
332 if (binom && !amsstyle)
333 macros << binom_def << '\n';
336 if (NeedLyXMinipageIndent)
337 macros << minipageindent_def;
339 macros << paragraphindent_def;
340 if (NeedLyXFootnoteCode)
341 macros << floatingfootnote_def;
344 getFloatDefinitions(macros);
346 for (LanguageList::const_iterator cit = UsedLanguages.begin();
347 cit != UsedLanguages.end(); ++cit)
348 if (!(*cit)->latex_options().empty())
349 macros << (*cit)->latex_options() << '\n';
350 if (!params.language->latex_options().empty())
351 macros << params.language->latex_options() << '\n';
353 return macros.str().c_str();
357 string const LaTeXFeatures::getTClassPreamble() const
359 // the text class specific preamble
360 LyXTextClass const & tclass =
361 textclasslist.TextClass(params.textclass);
362 ostringstream tcpreamble;
364 tcpreamble << tclass.preamble();
366 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
368 tcpreamble << tclass[i].preamble();
372 return tcpreamble.str().c_str();
376 string const LaTeXFeatures::getIncludedFiles(string const & fname) const
378 ostringstream sgmlpreamble;
379 string const basename = OnlyPath(fname);
381 FileMap::const_iterator end = IncludedFiles.end();
382 for (FileMap::const_iterator fi = IncludedFiles.begin();
384 sgmlpreamble << "\n<!ENTITY " << fi->first
385 << (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
386 << MakeRelPath(fi->second, basename) << "\">";
388 return sgmlpreamble.str().c_str();
392 void LaTeXFeatures::showStruct() const {
393 lyxerr << "LyX needs the following commands when LaTeXing:"
394 << "\n***** Packages:" << getPackages()
395 << "\n***** Macros:" << getMacros()
396 << "\n***** Textclass stuff:" << getTClassPreamble()
397 << "\n***** done." << endl;
401 BufferParams const & LaTeXFeatures::bufferParams() const
407 void LaTeXFeatures::getFloatDefinitions(std::ostream & os) const
409 // Here we will output the code to create the needed float styles.
410 // We will try to do this as minimal as possible.
411 // \floatstyle{ruled}
412 // \newfloat{algorithm}{htbp}{loa}
413 // \floatname{algorithm}{Algorithm}
414 UsedFloats::const_iterator cit = usedFloats.begin();
415 UsedFloats::const_iterator end = usedFloats.end();
416 // ostringstream floats;
417 for (; cit != end; ++cit) {
418 Floating const & fl = floatList.getType((*cit));
420 // For builtin floats we do nothing.
421 if (fl.builtin()) continue;
423 // We have to special case "table" and "figure"
424 if (fl.type() == "tabular" || fl.type() == "figure") {
425 // Output code to modify "table" or "figure"
426 // but only if builtin == false
427 // and that have to be true at this point in the
429 string const type = fl.type();
430 string const placement = fl.placement();
431 string const style = fl.style();
432 if (!style.empty()) {
433 os << "\\floatstyle{" << style << "}\n"
434 << "\\restylefloat{" << type << "}\n";
436 if (!placement.empty()) {
437 os << "\\floatplacement{" << type << "}{"
438 << placement << "}\n";
441 // The other non builtin floats.
443 string const type = fl.type();
444 string const placement = fl.placement();
445 string const ext = fl.ext();
446 string const within = fl.within();
447 string const style = fl.style();
448 string const name = fl.name();
449 os << "\\floatstyle{" << style << "}\n"
450 << "\\newfloat{" << type << "}{" << placement
451 << "}{" << ext << "}";
453 os << "[" << within << "]";
455 << "\\floatname{" << type << "}{"
458 // What missing here is to code to minimalize the code
459 // outputted so that the same flotastyle will not be
460 // used several times. when the same style is still in