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.
61 quotesinglbase = false;
63 guilsinglleft = false;
64 guilsinglright = false;
65 guillemotleft = false;
66 guillemotright = false;
74 ParagraphIndent = 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() const
131 ostringstream packages;
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
151 if (! tclass.provides(LyXTextClass::makeidx)
152 && params.language->babel() != "french") // french provides
154 // French should not be hardcoded. (Lgb)
155 packages << "\\usepackage{makeidx}\n";
156 packages << "\\makeindex\n";
160 if (graphicx && params.graphicsDriver != "none") {
161 if (params.graphicsDriver == "default")
162 packages << "\\usepackage{graphicx}\n";
164 packages << "\\usepackage["
165 << params.graphicsDriver
169 // INSET_GRAPHICS: remove this when InsetFig is thrown.
171 if (graphics && params.graphicsDriver != "none") {
172 if (params.graphicsDriver == "default")
173 packages << "\\usepackage{graphics}\n";
175 packages << "\\usepackage["
176 << params.graphicsDriver
182 packages << "\\usepackage{verbatim}\n";
185 // packages << "\\usepackage{algorithm}\n";
190 packages << "\\usepackage{lyxchess}\n";
194 if ((params.spacing.getSpace() != Spacing::Single
195 && !params.spacing.isDefault())
197 packages << "\\usepackage{setspace}\n";
199 switch (params.spacing.getSpace()) {
200 case Spacing::Default:
201 case Spacing::Single:
202 // we dont use setspace.sty so dont print anything
203 //packages += "\\singlespacing\n";
205 case Spacing::Onehalf:
206 packages << "\\onehalfspacing\n";
208 case Spacing::Double:
209 packages << "\\doublespacing\n";
212 packages << "\\setstretch{"
213 << params.spacing.getValue() << "}\n";
219 packages << "\\usepackage{longtable}\n";
223 packages << "\\usepackage{rotating}\n";
226 if (amssymb || params.use_amsmath)
227 packages << "\\usepackage{amssymb}\n";
231 packages << "\\usepackage{latexsym}\n";
235 packages << "\\usepackage{pifont}\n";
239 packages << "\\usepackage{subfigure}\n";
243 packages << "\\usepackage{floatflt}\n";
246 if (url && ! tclass.provides(LyXTextClass::url))
247 packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
248 " {\\newcommand{\\url}{\\texttt}}\n";
252 packages << "\\usepackage{varioref}\n";
256 packages << "\\usepackage{prettyref}\n";
259 // We only need float.sty if we use non builtin floats. This includes
260 // modified table and figure floats. (Lgb)
261 if (!usedFloats.empty()) {
262 bool use_float = false;
263 UsedFloats::const_iterator beg = usedFloats.begin();
264 UsedFloats::const_iterator end = usedFloats.end();
265 for (; beg != end; ++beg) {
266 Floating const & fl = floatList.getType((*beg));
267 if (!fl.type().empty() && !fl.builtin()) {
273 packages << "\\usepackage{float}\n";
276 packages << externalPreambles;
278 return packages.str().c_str();
282 string const LaTeXFeatures::getMacros() const
284 ostringstream macros;
286 // always include this
288 macros << lyx_def << '\n';
291 macros << lyxline_def << '\n';
294 macros << noun_def << '\n';
298 macros << lyxarrow_def << '\n';
303 macros << quotesinglbase_def << '\n';
305 macros << quotedblbase_def << '\n';
307 macros << guilsinglleft_def << '\n';
309 macros << guilsinglright_def << '\n';
311 macros << guillemotleft_def << '\n';
313 macros << guillemotright_def << '\n';
316 if (boldsymbol && !amsstyle)
317 macros << boldsymbol_def << '\n';
318 if (binom && !amsstyle)
319 macros << binom_def << '\n';
322 if (NeedLyXMinipageIndent)
323 macros << minipageindent_def;
325 macros << paragraphindent_def;
326 if (NeedLyXFootnoteCode)
327 macros << floatingfootnote_def;
330 getFloatDefinitions(macros);
332 for (LanguageList::const_iterator cit = UsedLanguages.begin();
333 cit != UsedLanguages.end(); ++cit)
334 if (!(*cit)->latex_options().empty())
335 macros << (*cit)->latex_options() << '\n';
336 if (!params.language->latex_options().empty())
337 macros << params.language->latex_options() << '\n';
339 return macros.str().c_str();
343 string const LaTeXFeatures::getTClassPreamble() const
345 // the text class specific preamble
346 LyXTextClass const & tclass =
347 textclasslist.TextClass(params.textclass);
348 ostringstream tcpreamble;
350 tcpreamble << tclass.preamble();
352 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
354 tcpreamble << tclass[i].preamble();
358 return tcpreamble.str().c_str();
362 string const LaTeXFeatures::getIncludedFiles(string const & fname) const
364 ostringstream sgmlpreamble;
365 string const basename = OnlyPath(fname);
367 FileMap::const_iterator end = IncludedFiles.end();
368 for (FileMap::const_iterator fi = IncludedFiles.begin();
370 sgmlpreamble << "\n<!ENTITY " << fi->first
371 << (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
372 << MakeRelPath(fi->second, basename) << "\">";
374 return sgmlpreamble.str().c_str();
378 void LaTeXFeatures::showStruct() const {
379 lyxerr << "LyX needs the following commands when LaTeXing:"
380 << "\n***** Packages:" << getPackages()
381 << "\n***** Macros:" << getMacros()
382 << "\n***** Textclass stuff:" << getTClassPreamble()
383 << "\n***** done." << endl;
387 BufferParams const & LaTeXFeatures::bufferParams() const
393 void LaTeXFeatures::getFloatDefinitions(std::ostream & os) const
395 // Here we will output the code to create the needed float styles.
396 // We will try to do this as minimal as possible.
397 // \floatstyle{ruled}
398 // \newfloat{algorithm}{htbp}{loa}
399 // \floatname{algorithm}{Algorithm}
400 UsedFloats::const_iterator cit = usedFloats.begin();
401 UsedFloats::const_iterator end = usedFloats.end();
402 // ostringstream floats;
403 for (; cit != end; ++cit) {
404 Floating const & fl = floatList.getType((*cit));
406 // For builtin floats we do nothing.
407 if (fl.builtin()) continue;
409 // We have to special case "table" and "figure"
410 if (fl.type() == "tabular" || fl.type() == "figure") {
411 // Output code to modify "table" or "figure"
412 // but only if builtin == false
413 // and that have to be true at this point in the
415 string const type = fl.type();
416 string const placement = fl.placement();
417 string const style = fl.style();
418 if (!style.empty()) {
419 os << "\\floatstyle{" << style << "}\n"
420 << "\\restylefloat{" << type << "}\n";
422 if (!placement.empty()) {
423 os << "\\floatplacement{" << type << "}{"
424 << placement << "}\n";
427 // The other non builtin floats.
429 string const type = fl.type();
430 string const placement = fl.placement();
431 string const ext = fl.ext();
432 string const within = fl.within();
433 string const style = fl.style();
434 string const name = fl.name();
435 os << "\\floatstyle{" << style << "}\n"
436 << "\\newfloat{" << type << "}{" << placement
437 << "}{" << ext << "}";
439 os << "[" << within << "]";
441 << "\\floatname{" << type << "}{"
444 // What missing here is to code to minimalize the code
445 // outputted so that the same flotastyle will not be
446 // used several times. when the same style is still in