1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 the LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-09 23:52:04 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "LaTeXFeatures.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_sty.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "bufferparams.h"
|
|
|
|
#include "layout.h"
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-27 17:07:33 +00:00
|
|
|
LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
|
2000-04-10 21:40:13 +00:00
|
|
|
: layout(n, false), params(p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// packages
|
2000-07-17 14:31:07 +00:00
|
|
|
array = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
color = false;
|
2000-07-31 12:30:10 +00:00
|
|
|
graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
|
2000-09-14 17:53:12 +00:00
|
|
|
graphicx = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
setspace = false;
|
|
|
|
makeidx = false;
|
|
|
|
verbatim = false;
|
|
|
|
longtable = false;
|
|
|
|
algorithm = false;
|
|
|
|
rotating = false;
|
|
|
|
amssymb = false;
|
|
|
|
latexsym = false;
|
|
|
|
pifont = false;
|
|
|
|
subfigure = false;
|
|
|
|
floatflt = false;
|
|
|
|
url = false;
|
2000-05-19 16:46:01 +00:00
|
|
|
varioref = false;
|
|
|
|
prettyref = false;
|
2000-06-12 11:27:15 +00:00
|
|
|
chess = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// commands
|
|
|
|
lyx = false;
|
|
|
|
lyxline = false;
|
|
|
|
noun = false;
|
|
|
|
lyxarrow = false;
|
|
|
|
|
|
|
|
// quotes
|
|
|
|
quotesinglbase = false;
|
|
|
|
quotedblbase = false;
|
|
|
|
guilsinglleft = false;
|
|
|
|
guilsinglright = false;
|
|
|
|
guillemotleft = false;
|
|
|
|
guillemotright = false;
|
|
|
|
|
|
|
|
// Math mode
|
|
|
|
amsstyle = false;
|
|
|
|
binom = false;
|
|
|
|
boldsymbol = false;
|
|
|
|
|
|
|
|
// special features
|
|
|
|
LyXParagraphIndent = false;
|
|
|
|
NeedLyXFootnoteCode = false;
|
|
|
|
NeedLyXMinipageIndent = false;
|
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
void LaTeXFeatures::require(string const & name)
|
|
|
|
{
|
2000-07-17 14:31:07 +00:00
|
|
|
if (name == "array") {
|
|
|
|
array = true;
|
|
|
|
} else if (name == "color") {
|
2000-06-12 11:27:15 +00:00
|
|
|
color = true;
|
|
|
|
} else if (name == "graphics") {
|
|
|
|
graphicx = true;
|
2000-07-31 12:30:10 +00:00
|
|
|
graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
|
2000-06-12 11:27:15 +00:00
|
|
|
} else if (name == "setspace") {
|
|
|
|
setspace = true;
|
|
|
|
} else if (name == "makeidx") {
|
|
|
|
makeidx = true;
|
|
|
|
} else if (name == "verbatim") {
|
|
|
|
verbatim = true;
|
|
|
|
} else if (name == "longtable") {
|
|
|
|
longtable = true;
|
|
|
|
} else if (name == "algorithm") {
|
|
|
|
algorithm = true;
|
|
|
|
} else if (name == "rotating") {
|
|
|
|
rotating = true;
|
|
|
|
} else if (name == "amssymb") {
|
|
|
|
amssymb = true;
|
|
|
|
} else if (name == "latexsym") {
|
|
|
|
latexsym = true;
|
|
|
|
} else if (name == "pifont") {
|
|
|
|
pifont = true;
|
|
|
|
} else if (name == "subfigure") {
|
|
|
|
subfigure = true;
|
|
|
|
} else if (name == "floatflt") {
|
|
|
|
floatflt = true;
|
|
|
|
} else if (name == "url") {
|
|
|
|
url = true;
|
|
|
|
} else if (name == "varioref") {
|
|
|
|
varioref = true;
|
|
|
|
} else if (name == "prettyref") {
|
|
|
|
prettyref = true;
|
|
|
|
} else if (name == "chess") {
|
|
|
|
chess = true;
|
|
|
|
} else if (name == "amsstyle") {
|
|
|
|
amsstyle = true;
|
|
|
|
} else if (name == "boldsymbol") {
|
|
|
|
boldsymbol = true;
|
|
|
|
} else if (name == "binom") {
|
|
|
|
binom = true;
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
string const LaTeXFeatures::getPackages()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string packages;
|
2000-04-10 21:40:13 +00:00
|
|
|
LyXTextClass const & tclass =
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-07-17 14:31:07 +00:00
|
|
|
// array-package
|
|
|
|
if (array)
|
|
|
|
packages += "\\usepackage{array}\n";
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// color.sty
|
|
|
|
if (color) {
|
|
|
|
if (params.graphicsDriver == "default")
|
1999-11-15 12:01:38 +00:00
|
|
|
packages += "\\usepackage{color}\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
packages += "\\usepackage["
|
|
|
|
+ params.graphicsDriver + "]{color}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeidx.sty
|
|
|
|
if (makeidx) {
|
1999-11-04 01:40:20 +00:00
|
|
|
if (! tclass.provides(LyXTextClass::makeidx)
|
1999-09-27 18:44:28 +00:00
|
|
|
&& params.language != "french") // french provides
|
|
|
|
// \index !
|
|
|
|
packages += "\\usepackage{makeidx}\n";
|
|
|
|
packages += "\\makeindex\n";
|
|
|
|
}
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
// graphicx.sty
|
|
|
|
if (graphicx && params.graphicsDriver != "none") {
|
|
|
|
if (params.graphicsDriver == "default")
|
|
|
|
packages += "\\usepackage{graphicx}\n";
|
|
|
|
else
|
|
|
|
packages += "\\usepackage["
|
|
|
|
+ params.graphicsDriver + "]{graphicx}\n";
|
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
// INSET_GRAPHICS: remove this when InsetFig is thrown.
|
1999-09-27 18:44:28 +00:00
|
|
|
// graphics.sty
|
|
|
|
if (graphics && params.graphicsDriver != "none") {
|
|
|
|
if (params.graphicsDriver == "default")
|
|
|
|
packages += "\\usepackage{graphics}\n";
|
|
|
|
else
|
|
|
|
packages += "\\usepackage["
|
|
|
|
+ params.graphicsDriver + "]{graphics}\n";
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
// verbatim.sty
|
1999-09-27 18:44:28 +00:00
|
|
|
if (verbatim)
|
|
|
|
packages += "\\usepackage{verbatim}\n";
|
|
|
|
|
|
|
|
if (algorithm) {
|
|
|
|
packages += "\\usepackage{algorithm}\n";
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
// lyxchess.sty
|
|
|
|
if (chess) {
|
|
|
|
packages += "\\usepackage{lyxchess}\n";
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// setspace.sty
|
2000-04-11 22:55:29 +00:00
|
|
|
if ((params.spacing.getSpace() != Spacing::Single
|
|
|
|
&& !params.spacing.isDefault())
|
1999-09-27 18:44:28 +00:00
|
|
|
|| setspace) {
|
|
|
|
packages += "\\usepackage{setspace}\n";
|
|
|
|
}
|
|
|
|
switch (params.spacing.getSpace()) {
|
2000-04-11 22:55:29 +00:00
|
|
|
case Spacing::Default:
|
1999-09-27 18:44:28 +00:00
|
|
|
case Spacing::Single:
|
|
|
|
// we dont use setspace.sty so dont print anything
|
|
|
|
//packages += "\\singlespacing\n";
|
|
|
|
break;
|
|
|
|
case Spacing::Onehalf:
|
|
|
|
packages += "\\onehalfspacing\n";
|
|
|
|
break;
|
|
|
|
case Spacing::Double:
|
|
|
|
packages += "\\doublespacing\n";
|
|
|
|
break;
|
|
|
|
case Spacing::Other:
|
2000-04-04 00:19:15 +00:00
|
|
|
std::ostringstream value;
|
2000-03-08 01:45:25 +00:00
|
|
|
value << params.spacing.getValue(); // setw?
|
1999-10-02 16:21:10 +00:00
|
|
|
packages += string("\\setstretch{")
|
2000-03-08 01:45:25 +00:00
|
|
|
+ value.str().c_str() + "}\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//longtable.sty
|
|
|
|
if (longtable)
|
|
|
|
packages += "\\usepackage{longtable}\n";
|
|
|
|
|
|
|
|
//rotating.sty
|
|
|
|
if (rotating)
|
|
|
|
packages += "\\usepackage{rotating}\n";
|
|
|
|
|
|
|
|
// amssymb.sty
|
2000-05-05 10:17:05 +00:00
|
|
|
if (amssymb || params.use_amsmath)
|
1999-09-27 18:44:28 +00:00
|
|
|
packages += "\\usepackage{amssymb}\n";
|
|
|
|
|
|
|
|
// latexsym.sty
|
|
|
|
if (latexsym)
|
|
|
|
packages += "\\usepackage{latexsym}\n";
|
|
|
|
|
|
|
|
// pifont.sty
|
|
|
|
if (pifont)
|
|
|
|
packages += "\\usepackage{pifont}\n";
|
|
|
|
|
|
|
|
// subfigure.sty
|
|
|
|
if (subfigure)
|
|
|
|
packages += "\\usepackage{subfigure}\n";
|
|
|
|
|
|
|
|
// floatflt.sty
|
|
|
|
if (floatflt)
|
|
|
|
packages += "\\usepackage{floatflt}\n";
|
|
|
|
|
|
|
|
// url.sty
|
1999-11-04 01:40:20 +00:00
|
|
|
if (url && ! tclass.provides(LyXTextClass::url))
|
1999-09-27 18:44:28 +00:00
|
|
|
packages += "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
|
|
|
|
" {\\newcommand{\\url}{\\texttt}}\n";
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
// varioref.sty
|
|
|
|
if (varioref)
|
|
|
|
packages += "\\usepackage{varioref}\n";
|
|
|
|
|
|
|
|
// prettyref.sty
|
|
|
|
if (prettyref)
|
|
|
|
packages += "\\usepackage{prettyref}\n";
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
// float.sty
|
|
|
|
// This is not correct and needs fixing.
|
|
|
|
// We don't need float.sty if we only use unchanged
|
|
|
|
// table and figure floats. (Lgb)
|
|
|
|
if (!usedFloats.empty())
|
|
|
|
packages += "\\usepackage{float}\n";
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
packages += externalPreambles;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const LaTeXFeatures::getMacros()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string macros;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// always include this
|
|
|
|
if (true || lyx)
|
|
|
|
macros += lyx_def + '\n';
|
|
|
|
|
|
|
|
if (lyxline)
|
|
|
|
macros += lyxline_def + '\n';
|
|
|
|
|
|
|
|
if (noun) {
|
|
|
|
macros += noun_def + '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lyxarrow) {
|
|
|
|
macros += lyxarrow_def + '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// quotes.
|
|
|
|
if (quotesinglbase)
|
|
|
|
macros += quotesinglbase_def + '\n';
|
|
|
|
if (quotedblbase)
|
|
|
|
macros += quotedblbase_def + '\n';
|
|
|
|
if (guilsinglleft)
|
|
|
|
macros += guilsinglleft_def + '\n';
|
|
|
|
if (guilsinglright)
|
|
|
|
macros += guilsinglright_def + '\n';
|
|
|
|
if (guillemotleft)
|
|
|
|
macros += guillemotleft_def + '\n';
|
|
|
|
if (guillemotright)
|
|
|
|
macros += guillemotright_def + '\n';
|
|
|
|
|
|
|
|
// Math mode
|
|
|
|
if (boldsymbol && !amsstyle)
|
|
|
|
macros += boldsymbol_def + '\n';
|
|
|
|
if (binom && !amsstyle)
|
|
|
|
macros += binom_def + '\n';
|
|
|
|
|
|
|
|
// other
|
|
|
|
if (NeedLyXMinipageIndent)
|
|
|
|
macros += minipageindent_def;
|
|
|
|
if (LyXParagraphIndent)
|
|
|
|
macros += paragraphindent_def;
|
|
|
|
if (NeedLyXFootnoteCode)
|
|
|
|
macros += floatingfootnote_def;
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
// floats
|
|
|
|
// Here we will output the code to create the needed float styles.
|
|
|
|
// We will try to do this as minimal as possible.
|
|
|
|
// \floatstyle{ruled}
|
|
|
|
// \newfloat{algorithm}{htbp}{loa}
|
|
|
|
// \floatname{algorithm}{Algorithm}
|
1999-09-27 18:44:28 +00:00
|
|
|
return macros;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const LaTeXFeatures::getTClassPreamble()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// the text class specific preamble
|
2000-04-10 21:40:13 +00:00
|
|
|
LyXTextClass const & tclass =
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-11-04 01:40:20 +00:00
|
|
|
string tcpreamble = tclass.preamble();
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
for (unsigned int i = 0; i < tclass.numLayouts(); ++i) {
|
|
|
|
if (layout[i]) {
|
|
|
|
tcpreamble += tclass[i].preamble();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tcpreamble;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const LaTeXFeatures::getIncludedFiles()
|
2000-07-01 12:54:45 +00:00
|
|
|
{
|
|
|
|
string sgmlpreamble;
|
2000-08-03 21:17:52 +00:00
|
|
|
FileMap::const_iterator end = IncludedFiles.end();
|
|
|
|
for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != end; ++fi)
|
|
|
|
sgmlpreamble += "\n<!entity " + fi->first
|
|
|
|
+ " system \"" + fi->second + "\">";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
|
|
return sgmlpreamble;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
void LaTeXFeatures::showStruct() {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyX needs the following commands when LaTeXing:"
|
2000-04-10 21:40:13 +00:00
|
|
|
<< "\n***** Packages:" << getPackages()
|
|
|
|
<< "\n***** Macros:" << getMacros()
|
|
|
|
<< "\n***** Textclass stuff:" << getTClassPreamble()
|
1999-10-07 18:44:17 +00:00
|
|
|
<< "\n***** done." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
BufferParams const & LaTeXFeatures::bufferParams() const
|
|
|
|
{
|
|
|
|
return params;
|
|
|
|
}
|