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() const
132 ostringstream packages;
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
152 if (! tclass.provides(LyXTextClass::makeidx)
153 && params.language->babel() != "french") // french provides
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;
324 if (LyXParagraphIndent)
325 macros << paragraphindent_def;
326 if (NeedLyXFootnoteCode)
327 macros << floatingfootnote_def;
330 getFloatDefinitions(macros);
333 // Here we will output the code to create the needed float styles.
334 // We will try to do this as minimal as possible.
335 // \floatstyle{ruled}
336 // \newfloat{algorithm}{htbp}{loa}
337 // \floatname{algorithm}{Algorithm}
338 UsedFloats::const_iterator cit = usedFloats.begin();
339 UsedFloats::const_iterator end = usedFloats.end();
340 ostringstream floats;
341 for (; cit != end; ++cit) {
342 Floating const & fl = floatList.getType((*cit));
344 // For builtin floats we do nothing.
345 if (fl.builtin()) continue;
347 // We have to special case "table" and "figure"
348 if (fl.type() == "tabular" || fl.type() == "figure") {
349 // Output code to modify "table" or "figure"
350 // but only if builtin == false
352 // The other non builtin floats.
354 string type = fl.type();
355 string placement = fl.placement();
356 string ext = fl.ext();
357 string within = fl.within();
358 string style = fl.style();
359 string name = fl.name();
360 floats << "\\floatstyle{" << style << "}\n"
361 << "\\newfloat{" << type << "}{" << placement
362 << "}{" << ext << "}";
364 floats << "[" << within << "]";
366 << "\\floatname{" << type << "}{"
369 // What missing here is to code to minimalize the code
370 // outputted so that the same flotastyle will not be
371 // used several times. when the same style is still in
375 macros += floats.str().c_str();
378 for (LanguageList::const_iterator cit = UsedLanguages.begin();
379 cit != UsedLanguages.end(); ++cit)
380 if (!(*cit)->latex_options().empty())
381 macros << (*cit)->latex_options() << '\n';
382 if (!params.language->latex_options().empty())
383 macros << params.language->latex_options() << '\n';
385 return macros.str().c_str();
389 string const LaTeXFeatures::getTClassPreamble() const
391 // the text class specific preamble
392 LyXTextClass const & tclass =
393 textclasslist.TextClass(params.textclass);
394 ostringstream tcpreamble;
396 tcpreamble << tclass.preamble();
398 for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
400 tcpreamble << tclass[i].preamble();
404 return tcpreamble.str().c_str();
408 string const LaTeXFeatures::getIncludedFiles(string const & fname) const
410 ostringstream sgmlpreamble;
411 string const basename = OnlyPath(fname);
413 FileMap::const_iterator end = IncludedFiles.end();
414 for (FileMap::const_iterator fi = IncludedFiles.begin();
416 sgmlpreamble << "\n<!ENTITY " << fi->first
417 << (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
418 << MakeRelPath(fi->second,basename) << "\">";
420 return sgmlpreamble.str().c_str();
424 void LaTeXFeatures::showStruct() const{
425 lyxerr << "LyX needs the following commands when LaTeXing:"
426 << "\n***** Packages:" << getPackages()
427 << "\n***** Macros:" << getMacros()
428 << "\n***** Textclass stuff:" << getTClassPreamble()
429 << "\n***** done." << endl;
433 BufferParams const & LaTeXFeatures::bufferParams() const
439 void LaTeXFeatures::getFloatDefinitions(ostream & os) const
441 // Here we will output the code to create the needed float styles.
442 // We will try to do this as minimal as possible.
443 // \floatstyle{ruled}
444 // \newfloat{algorithm}{htbp}{loa}
445 // \floatname{algorithm}{Algorithm}
446 UsedFloats::const_iterator cit = usedFloats.begin();
447 UsedFloats::const_iterator end = usedFloats.end();
448 // ostringstream floats;
449 for (; cit != end; ++cit) {
450 Floating const & fl = floatList.getType((*cit));
452 // For builtin floats we do nothing.
453 if (fl.builtin()) continue;
455 // We have to special case "table" and "figure"
456 if (fl.type() == "tabular" || fl.type() == "figure") {
457 // Output code to modify "table" or "figure"
458 // but only if builtin == false
459 // and that have to be true at this point in the
461 string const type = fl.type();
462 string const placement = fl.placement();
463 string const style = fl.style();
464 if (!style.empty()) {
465 os << "\\floatstyle{" << style << "}\n"
466 << "\\restylefloat{" << type << "}\n";
468 if (!placement.empty()) {
469 os << "\\floatplacement{" << type << "}{"
470 << placement << "}\n";
473 // The other non builtin floats.
475 string const type = fl.type();
476 string const placement = fl.placement();
477 string const ext = fl.ext();
478 string const within = fl.within();
479 string const style = fl.style();
480 string const name = fl.name();
481 os << "\\floatstyle{" << style << "}\n"
482 << "\\newfloat{" << type << "}{" << placement
483 << "}{" << ext << "}";
485 os << "[" << within << "]";
487 << "\\floatname{" << type << "}{"
490 // What missing here is to code to minimalize the code
491 // outputted so that the same flotastyle will not be
492 // used several times. when the same style is still in