latexfeatures path from Michael

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3041 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2001-11-19 15:34:11 +00:00
parent f9544ad301
commit fcc833018c
21 changed files with 318 additions and 367 deletions

View File

@ -1,21 +1,24 @@
src/buffer.C
src/bufferlist.C
src/BufferView2.C src/BufferView2.C
src/bufferview_funcs.C
src/BufferView_pimpl.C src/BufferView_pimpl.C
src/Chktex.C src/Chktex.C
src/ColorHandler.C src/ColorHandler.C
src/converter.C
src/CutAndPaste.C src/CutAndPaste.C
src/FontLoader.C
src/LColor.C
src/LaTeX.C
src/LyXAction.C
src/LyXSendto.C
src/LyXView.C
src/MenuBackend.C
src/buffer.C
src/bufferlist.C
src/bufferview_funcs.C
src/converter.C
src/debug.C src/debug.C
src/exporter.C src/exporter.C
src/ext_l10n.h
src/figure_form.C
src/figureForm.C src/figureForm.C
src/FontLoader.C src/figure_form.C
src/frontends/controllers/biblio.C
src/frontends/controllers/ButtonController.h src/frontends/controllers/ButtonController.h
src/frontends/controllers/character.C
src/frontends/controllers/ControlAboutlyx.C src/frontends/controllers/ControlAboutlyx.C
src/frontends/controllers/ControlBibtex.C src/frontends/controllers/ControlBibtex.C
src/frontends/controllers/ControlCharacter.C src/frontends/controllers/ControlCharacter.C
@ -29,6 +32,8 @@ src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlTexinfo.C src/frontends/controllers/ControlTexinfo.C
src/frontends/controllers/ControlThesaurus.C src/frontends/controllers/ControlThesaurus.C
src/frontends/controllers/ControlVCLog.C src/frontends/controllers/ControlVCLog.C
src/frontends/controllers/biblio.C
src/frontends/controllers/character.C
src/frontends/controllers/helper_funcs.C src/frontends/controllers/helper_funcs.C
src/frontends/gnome/FormCitation.C src/frontends/gnome/FormCitation.C
src/frontends/gnome/FormIndex.C src/frontends/gnome/FormIndex.C
@ -37,7 +42,6 @@ src/frontends/gnome/FormRef.C
src/frontends/gnome/FormToc.C src/frontends/gnome/FormToc.C
src/frontends/gnome/Menubar_pimpl.C src/frontends/gnome/Menubar_pimpl.C
src/frontends/qt2/FileDialog.C src/frontends/qt2/FileDialog.C
src/frontends/qt2/lengthcombo.C
src/frontends/qt2/QAbout.C src/frontends/qt2/QAbout.C
src/frontends/qt2/QBibitem.C src/frontends/qt2/QBibitem.C
src/frontends/qt2/QBibtex.C src/frontends/qt2/QBibtex.C
@ -46,8 +50,8 @@ src/frontends/qt2/QCharacter.C
src/frontends/qt2/QCitation.C src/frontends/qt2/QCitation.C
src/frontends/qt2/QCitationDialog.C src/frontends/qt2/QCitationDialog.C
src/frontends/qt2/QDocument.C src/frontends/qt2/QDocument.C
src/frontends/qt2/QError.C
src/frontends/qt2/QERT.C src/frontends/qt2/QERT.C
src/frontends/qt2/QError.C
src/frontends/qt2/QExternal.C src/frontends/qt2/QExternal.C
src/frontends/qt2/QExternalDialog.C src/frontends/qt2/QExternalDialog.C
src/frontends/qt2/QGraphics.C src/frontends/qt2/QGraphics.C
@ -69,86 +73,87 @@ src/frontends/qt2/QThesaurus.C
src/frontends/qt2/QToc.C src/frontends/qt2/QToc.C
src/frontends/qt2/QURL.C src/frontends/qt2/QURL.C
src/frontends/qt2/QVCLog.C src/frontends/qt2/QVCLog.C
src/frontends/xforms/combox.C src/frontends/qt2/lengthcombo.C
src/frontends/xforms/FileDialog.C src/frontends/xforms/FileDialog.C
src/frontends/xforms/form_aboutlyx.C
src/frontends/xforms/FormAboutlyx.C src/frontends/xforms/FormAboutlyx.C
src/frontends/xforms/form_bibitem.C
src/frontends/xforms/FormBibitem.C src/frontends/xforms/FormBibitem.C
src/frontends/xforms/form_bibtex.C
src/frontends/xforms/FormBibtex.C src/frontends/xforms/FormBibtex.C
src/frontends/xforms/form_browser.C
src/frontends/xforms/form_character.C
src/frontends/xforms/FormCharacter.C src/frontends/xforms/FormCharacter.C
src/frontends/xforms/form_citation.C
src/frontends/xforms/FormCitation.C src/frontends/xforms/FormCitation.C
src/frontends/xforms/form_document.C
src/frontends/xforms/FormDocument.C src/frontends/xforms/FormDocument.C
src/frontends/xforms/form_error.C
src/frontends/xforms/FormError.C
src/frontends/xforms/form_ert.C
src/frontends/xforms/FormERT.C src/frontends/xforms/FormERT.C
src/frontends/xforms/form_external.C src/frontends/xforms/FormError.C
src/frontends/xforms/FormExternal.C src/frontends/xforms/FormExternal.C
src/frontends/xforms/form_filedialog.C
src/frontends/xforms/FormFiledialog.C src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/form_float.C
src/frontends/xforms/FormFloat.C src/frontends/xforms/FormFloat.C
src/frontends/xforms/form_graphics.C
src/frontends/xforms/FormGraphics.C src/frontends/xforms/FormGraphics.C
src/frontends/xforms/form_include.C
src/frontends/xforms/FormInclude.C src/frontends/xforms/FormInclude.C
src/frontends/xforms/form_index.C
src/frontends/xforms/FormIndex.C src/frontends/xforms/FormIndex.C
src/frontends/xforms/FormLog.C src/frontends/xforms/FormLog.C
src/frontends/xforms/FormMathsBitmap.C src/frontends/xforms/FormMathsBitmap.C
src/frontends/xforms/form_maths_deco.C
src/frontends/xforms/FormMathsDeco.C src/frontends/xforms/FormMathsDeco.C
src/frontends/xforms/form_maths_delim.C
src/frontends/xforms/FormMathsDelim.C src/frontends/xforms/FormMathsDelim.C
src/frontends/xforms/form_maths_matrix.C
src/frontends/xforms/FormMathsMatrix.C src/frontends/xforms/FormMathsMatrix.C
src/frontends/xforms/form_maths_panel.C
src/frontends/xforms/FormMathsPanel.C src/frontends/xforms/FormMathsPanel.C
src/frontends/xforms/form_maths_space.C
src/frontends/xforms/FormMathsSpace.C src/frontends/xforms/FormMathsSpace.C
src/frontends/xforms/form_minipage.C
src/frontends/xforms/FormMinipage.C src/frontends/xforms/FormMinipage.C
src/frontends/xforms/form_paragraph.C
src/frontends/xforms/FormParagraph.C src/frontends/xforms/FormParagraph.C
src/frontends/xforms/form_preamble.C
src/frontends/xforms/FormPreamble.C src/frontends/xforms/FormPreamble.C
src/frontends/xforms/form_preferences.C
src/frontends/xforms/FormPreferences.C src/frontends/xforms/FormPreferences.C
src/frontends/xforms/form_print.C
src/frontends/xforms/FormPrint.C src/frontends/xforms/FormPrint.C
src/frontends/xforms/form_ref.C
src/frontends/xforms/FormRef.C src/frontends/xforms/FormRef.C
src/frontends/xforms/form_search.C
src/frontends/xforms/FormSearch.C src/frontends/xforms/FormSearch.C
src/frontends/xforms/form_spellchecker.C
src/frontends/xforms/FormSpellchecker.C src/frontends/xforms/FormSpellchecker.C
src/frontends/xforms/form_tabular.C
src/frontends/xforms/FormTabular.C src/frontends/xforms/FormTabular.C
src/frontends/xforms/form_tabular_create.C
src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/FormTabularCreate.C
src/frontends/xforms/form_texinfo.C
src/frontends/xforms/FormTexinfo.C src/frontends/xforms/FormTexinfo.C
src/frontends/xforms/form_thesaurus.C
src/frontends/xforms/FormThesaurus.C src/frontends/xforms/FormThesaurus.C
src/frontends/xforms/form_toc.C
src/frontends/xforms/FormToc.C src/frontends/xforms/FormToc.C
src/frontends/xforms/form_url.C
src/frontends/xforms/FormUrl.C src/frontends/xforms/FormUrl.C
src/frontends/xforms/FormVCLog.C src/frontends/xforms/FormVCLog.C
src/frontends/xforms/input_validators.C
src/frontends/xforms/Menubar_pimpl.C src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/combox.C
src/frontends/xforms/form_aboutlyx.C
src/frontends/xforms/form_bibitem.C
src/frontends/xforms/form_bibtex.C
src/frontends/xforms/form_browser.C
src/frontends/xforms/form_character.C
src/frontends/xforms/form_citation.C
src/frontends/xforms/form_document.C
src/frontends/xforms/form_error.C
src/frontends/xforms/form_ert.C
src/frontends/xforms/form_external.C
src/frontends/xforms/form_filedialog.C
src/frontends/xforms/form_float.C
src/frontends/xforms/form_graphics.C
src/frontends/xforms/form_include.C
src/frontends/xforms/form_index.C
src/frontends/xforms/form_maths_deco.C
src/frontends/xforms/form_maths_delim.C
src/frontends/xforms/form_maths_matrix.C
src/frontends/xforms/form_maths_panel.C
src/frontends/xforms/form_maths_space.C
src/frontends/xforms/form_minipage.C
src/frontends/xforms/form_paragraph.C
src/frontends/xforms/form_preamble.C
src/frontends/xforms/form_preferences.C
src/frontends/xforms/form_print.C
src/frontends/xforms/form_ref.C
src/frontends/xforms/form_search.C
src/frontends/xforms/form_spellchecker.C
src/frontends/xforms/form_tabular.C
src/frontends/xforms/form_tabular_create.C
src/frontends/xforms/form_texinfo.C
src/frontends/xforms/form_thesaurus.C
src/frontends/xforms/form_toc.C
src/frontends/xforms/form_url.C
src/frontends/xforms/input_validators.C
src/frontends/xforms/xforms_helpers.C src/frontends/xforms/xforms_helpers.C
src/gettext.h src/gettext.h
src/importer.C src/importer.C
src/insets/figinset.C src/insets/figinset.C
src/insets/insetbib.C
src/insets/inset.C src/insets/inset.C
src/insets/insetbib.C
src/insets/insetcaption.C src/insets/insetcaption.C
src/insets/inseterror.C src/insets/inseterror.C
src/insets/insetert.C src/insets/insetert.C
@ -173,25 +178,19 @@ src/insets/insettoc.C
src/insets/inseturl.C src/insets/inseturl.C
src/kbsequence.C src/kbsequence.C
src/language.C src/language.C
src/LaTeX.C
src/layout.C src/layout.C
src/LColor.C
src/LyXAction.C
src/lyx_cb.C src/lyx_cb.C
src/lyx_gui_misc.C
src/lyx_main.C
src/lyxfind.C src/lyxfind.C
src/lyxfont.C src/lyxfont.C
src/lyxfunc.C src/lyxfunc.C
src/lyx_gui_misc.C
src/lyx_main.C
src/lyxrc.C src/lyxrc.C
src/LyXSendto.C
src/lyxvc.C src/lyxvc.C
src/LyXView.C
src/mathed/formulabase.C
src/mathed/formula.C src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/formulamacro.C src/mathed/formulamacro.C
src/mathed/math_cursor.C src/mathed/math_cursor.C
src/MenuBackend.C
src/minibuffer.C src/minibuffer.C
src/paragraph.C src/paragraph.C
src/print_form.C src/print_form.C
@ -200,6 +199,6 @@ src/support/getUserName.C
src/support/path.C src/support/path.C
src/support/path.h src/support/path.h
src/tabular.C src/tabular.C
src/text2.C
src/text.C src/text.C
src/text2.C
src/ext_l10n.h src/ext_l10n.h

View File

@ -25,113 +25,91 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "FloatList.h" #include "FloatList.h"
#include "language.h" #include "language.h"
#include "encoding.h"
using std::endl; using std::endl;
using std::set;
LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n) LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
: layout(n, false), params(p) : layout(n, false), params(p)
{ {
// packages
array = false;
color = false;
graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
graphicx = false;
setspace = false;
makeidx = false;
verbatim = false;
longtable = false;
//algorithm = false;
rotating = false;
amssymb = false;
latexsym = false;
pifont = false;
subfigure = false;
floatflt = false;
url = false;
varioref = false;
prettyref = false;
chess = false;
natbib = false;
floats = false;
// 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
ParagraphIndent = false;
NeedLyXFootnoteCode = false;
NeedLyXMinipageIndent = false;
} }
void LaTeXFeatures::require(string const & name) void LaTeXFeatures::require(string const & name)
{ {
if (name == "array") { // INSET_GRAPHICS: remove this when InsetFig is thrown.
array = true; if (name == "graphics") {
} else if (name == "color") { features.push_back("graphicx");
color = true; features.push_back("graphics");
} else if (name == "graphics") { } else
graphicx = true; features.push_back(name);
graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
} 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;
} else if (name == "natbib") {
natbib = true;
} else if (name == "float") {
floats = true;
}
} }
void LaTeXFeatures::useLayout(std::vector<bool>::size_type const & idx)
{
layout[idx] = true;
}
bool LaTeXFeatures::isRequired(string const & name) const
{
FeaturesList::const_iterator i = std::find(features.begin(),
features.end(),
name);
return i!= features.end();
}
void LaTeXFeatures::addExternalPreamble(string const & pream)
{
externalPreambles += pream;
}
void LaTeXFeatures::useFloat(string const & name)
{
usedFloats.insert(name);
}
void LaTeXFeatures::useLanguage(Language const * lang)
{
UsedLanguages.insert(lang);
}
void LaTeXFeatures::includeFile(string const & key, string const & name)
{
IncludedFiles[key] = name;
}
bool LaTeXFeatures::hasLanguages()
{
return !UsedLanguages.empty();
}
string LaTeXFeatures::getLanguages() const
{
ostringstream languages;
for (LanguageList::const_iterator cit =
UsedLanguages.begin();
cit != UsedLanguages.end();
++cit)
languages << (*cit)->babel() << ',';
return languages.str().c_str();
}
set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding)
{
set<string> encodings;
for (LanguageList::const_iterator it =
UsedLanguages.begin();
it != UsedLanguages.end(); ++it)
if ((*it)->encoding()->LatexName() != doc_encoding)
encodings.insert((*it)->encoding()->LatexName());
return encodings;
}
string const LaTeXFeatures::getPackages() const string const LaTeXFeatures::getPackages() const
{ {
@ -139,12 +117,61 @@ string const LaTeXFeatures::getPackages() const
LyXTextClass const & tclass = LyXTextClass const & tclass =
textclasslist.TextClass(params.textclass); textclasslist.TextClass(params.textclass);
// array-package
if (array) /**
* These are all the 'simple' includes. i.e
* packages which we just \usepackage{package}
**/
// array-package
if (isRequired("array"))
packages << "\\usepackage{array}\n"; packages << "\\usepackage{array}\n";
// verbatim.sty
if (isRequired("verbatim"))
packages << "\\usepackage{verbatim}\n";
//longtable.sty
if (isRequired("longtable"))
packages << "\\usepackage{longtable}\n";
//rotating.sty
if (isRequired("rotating"))
packages << "\\usepackage{rotating}\n";
// latexsym.sty
if (isRequired("latexsym"))
packages << "\\usepackage{latexsym}\n";
// pifont.sty
if (isRequired("pifont"))
packages << "\\usepackage{pifont}\n";
// subfigure.sty
if (isRequired("subfigure"))
packages << "\\usepackage{subfigure}\n";
// floatflt.sty
if (isRequired("floatflt"))
packages << "\\usepackage{floatflt}\n";
// varioref.sty
if (isRequired("varioref"))
packages << "\\usepackage{varioref}\n";
// prettyref.sty
if (isRequired("prettyref"))
packages << "\\usepackage{prettyref}\n";
/**
* The rest of these packages are somewhat more complicated
* than those above.
**/
// color.sty // color.sty
if (color) { if (isRequired("color")) {
if (params.graphicsDriver == "default") if (params.graphicsDriver == "default")
packages << "\\usepackage{color}\n"; packages << "\\usepackage{color}\n";
else else
@ -154,14 +181,14 @@ string const LaTeXFeatures::getPackages() const
} }
// makeidx.sty // makeidx.sty
if (makeidx) { if (isRequired("makeidx")) {
if (! tclass.provides(LyXTextClass::makeidx)) if (! tclass.provides(LyXTextClass::makeidx))
packages << "\\usepackage{makeidx}\n"; packages << "\\usepackage{makeidx}\n";
packages << "\\makeindex\n"; packages << "\\makeindex\n";
} }
// graphicx.sty // graphicx.sty
if (graphicx && params.graphicsDriver != "none") { if (isRequired("graphicx") && params.graphicsDriver != "none") {
if (params.graphicsDriver == "default") if (params.graphicsDriver == "default")
packages << "\\usepackage{graphicx}\n"; packages << "\\usepackage{graphicx}\n";
else else
@ -172,7 +199,7 @@ string const LaTeXFeatures::getPackages() const
// INSET_GRAPHICS: remove this when InsetFig is thrown. // INSET_GRAPHICS: remove this when InsetFig is thrown.
// graphics.sty // graphics.sty
if (graphics && params.graphicsDriver != "none") { if (isRequired("graphics") && params.graphicsDriver != "none") {
if (params.graphicsDriver == "default") if (params.graphicsDriver == "default")
packages << "\\usepackage{graphics}\n"; packages << "\\usepackage{graphics}\n";
else else
@ -181,23 +208,19 @@ string const LaTeXFeatures::getPackages() const
<< "]{graphics}\n"; << "]{graphics}\n";
} }
// verbatim.sty
if (verbatim)
packages << "\\usepackage{verbatim}\n";
//if (algorithm) { //if (algorithm) {
// packages << "\\usepackage{algorithm}\n"; // packages << "\\usepackage{algorithm}\n";
//} //}
// lyxskak.sty --- newer chess support based on skak.sty // lyxskak.sty --- newer chess support based on skak.sty
if (chess) { if (isRequired("chess")) {
packages << "\\usepackage[ps,mover]{lyxskak}\n"; packages << "\\usepackage[ps,mover]{lyxskak}\n";
} }
// setspace.sty // setspace.sty
if ((params.spacing.getSpace() != Spacing::Single if ((params.spacing.getSpace() != Spacing::Single
&& !params.spacing.isDefault()) && !params.spacing.isDefault())
|| setspace) { || isRequired("setspace")) {
packages << "\\usepackage{setspace}\n"; packages << "\\usepackage{setspace}\n";
} }
switch (params.spacing.getSpace()) { switch (params.spacing.getSpace()) {
@ -218,47 +241,14 @@ string const LaTeXFeatures::getPackages() const
break; break;
} }
//longtable.sty
if (longtable)
packages << "\\usepackage{longtable}\n";
//rotating.sty
if (rotating)
packages << "\\usepackage{rotating}\n";
// amssymb.sty // amssymb.sty
if (amssymb || params.use_amsmath) if (isRequired("amssymb") || params.use_amsmath)
packages << "\\usepackage{amssymb}\n"; 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 // url.sty
if (url && ! tclass.provides(LyXTextClass::url)) if (isRequired("url") && ! tclass.provides(LyXTextClass::url))
packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n" packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n"
" {\\newcommand{\\url}{\\texttt}}\n"; " {\\newcommand{\\url}{\\texttt}}\n";
// varioref.sty
if (varioref)
packages << "\\usepackage{varioref}\n";
// prettyref.sty
if (prettyref)
packages << "\\usepackage{prettyref}\n";
// float.sty // float.sty
// We only need float.sty if we use non builtin floats, or if we // We only need float.sty if we use non builtin floats, or if we
// use the "H" modifier. This includes modified table and // use the "H" modifier. This includes modified table and
@ -269,17 +259,17 @@ string const LaTeXFeatures::getPackages() const
for (; beg != end; ++beg) { for (; beg != end; ++beg) {
Floating const & fl = floatList.getType((*beg)); Floating const & fl = floatList.getType((*beg));
if (!fl.type().empty() && !fl.builtin()) { if (!fl.type().empty() && !fl.builtin()) {
const_cast<LaTeXFeatures *>(this)->floats = true; const_cast<LaTeXFeatures *>(this)->require("floats");
break; break;
} }
} }
} }
if (floats) { if (isRequired("floats")) {
packages << "\\usepackage{float}\n"; packages << "\\usepackage{float}\n";
} }
// natbib.sty // natbib.sty
if (natbib) { if (isRequired("natbib")) {
packages << "\\usepackage["; packages << "\\usepackage[";
if (params.use_numerical_citations) { if (params.use_numerical_citations) {
packages << "numbers"; packages << "numbers";
@ -292,6 +282,7 @@ string const LaTeXFeatures::getPackages() const
packages << externalPreambles; packages << externalPreambles;
return packages.str().c_str(); return packages.str().c_str();
} }
@ -300,46 +291,46 @@ string const LaTeXFeatures::getMacros() const
ostringstream macros; ostringstream macros;
// always include this // always include this
if (true || lyx) if (true || isRequired("lyx"))
macros << lyx_def << '\n'; macros << lyx_def << '\n';
if (lyxline) if (isRequired("lyxline"))
macros << lyxline_def << '\n'; macros << lyxline_def << '\n';
if (noun) { if (isRequired("noun")) {
macros << noun_def << '\n'; macros << noun_def << '\n';
} }
if (lyxarrow) { if (isRequired("lyxarrow")) {
macros << lyxarrow_def << '\n'; macros << lyxarrow_def << '\n';
} }
// quotes. // quotes.
if (quotesinglbase) if (isRequired("quotesinglbase"))
macros << quotesinglbase_def << '\n'; macros << quotesinglbase_def << '\n';
if (quotedblbase) if (isRequired("quotedblbase"))
macros << quotedblbase_def << '\n'; macros << quotedblbase_def << '\n';
if (guilsinglleft) if (isRequired("guilsinglleft"))
macros << guilsinglleft_def << '\n'; macros << guilsinglleft_def << '\n';
if (guilsinglright) if (isRequired("guilsinglright"))
macros << guilsinglright_def << '\n'; macros << guilsinglright_def << '\n';
if (guillemotleft) if (isRequired("guillemotleft"))
macros << guillemotleft_def << '\n'; macros << guillemotleft_def << '\n';
if (guillemotright) if (isRequired("guillemotright"))
macros << guillemotright_def << '\n'; macros << guillemotright_def << '\n';
// Math mode // Math mode
if (boldsymbol && !amsstyle) if (isRequired("boldsymbol") && !isRequired("amsstyle"))
macros << boldsymbol_def << '\n'; macros << boldsymbol_def << '\n';
if (binom && !amsstyle) if (isRequired("binom") && !isRequired("amsstyle"))
macros << binom_def << '\n'; macros << binom_def << '\n';
// other // other
if (NeedLyXMinipageIndent) if (isRequired("NeedLyXMinipageIndent"))
macros << minipageindent_def; macros << minipageindent_def;
if (ParagraphIndent) if (isRequired("ParagraphIndent"))
macros << paragraphindent_def; macros << paragraphindent_def;
if (NeedLyXFootnoteCode) if (isRequired("NeedLyXFootnoteCode"))
macros << floatingfootnote_def; macros << floatingfootnote_def;
// floats // floats
@ -365,9 +356,9 @@ string const LaTeXFeatures::getTClassPreamble() const
tcpreamble << tclass.preamble(); tcpreamble << tclass.preamble();
for (unsigned int i = 0; i < tclass.numLayouts(); ++i) { for (LyXTextClass::size_type i = 0; i < tclass.numLayouts(); ++i) {
if (layout[i]) { if (layout[i]) {
tcpreamble << tclass[i].preamble(); tcpreamble << tclass[i].preamble();
} }
} }
@ -380,7 +371,7 @@ string const LaTeXFeatures::getLyXSGMLEntities() const
// Definition of entities used in the document that are LyX related. // Definition of entities used in the document that are LyX related.
ostringstream entities; ostringstream entities;
if (lyxarrow) { if (isRequired("lyxarrow")) {
entities << "<!ENTITY lyxarrow \"-&gt;\">" entities << "<!ENTITY lyxarrow \"-&gt;\">"
<< '\n'; << '\n';
} }
@ -419,7 +410,6 @@ BufferParams const & LaTeXFeatures::bufferParams() const
return params; return params;
} }
void LaTeXFeatures::getFloatDefinitions(std::ostream & os) const void LaTeXFeatures::getFloatDefinitions(std::ostream & os) const
{ {
// Here we will output the code to create the needed float styles. // Here we will output the code to create the needed float styles.

View File

@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <list>
#include "LString.h" #include "LString.h"
#include "layout.h" #include "layout.h"
@ -26,13 +27,22 @@
class BufferParams; class BufferParams;
struct Language; struct Language;
/** The packages and commands that a buffer needs. This struct /** The packages and commands that a buffer needs. This class
contains an entry for each of the latex packages and contains a list<string>. Each of the LaTeX packages that a buffer needs
commands that a buffer might need. This struct is supposed to be should be added with void require(string const & name).
extended as the need arises. Remember to update the validate function
in buffer.C and paragraph.C when you do so. i.e require("amssymb")
To add support you should only need to require() the package name as
packages which don't have special requirements are handled automatically.
If your new package does need special consideration you'll need to alter
string const getPackages() const;
Remember to update the validate function in buffer.C and paragraph.C
when you do so.
*/ */
struct LaTeXFeatures { class LaTeXFeatures {
public:
/// ///
LaTeXFeatures(BufferParams const &, LyXTextClass::size_type n) ; LaTeXFeatures(BufferParams const &, LyXTextClass::size_type n) ;
/// The packages needed by the document /// The packages needed by the document
@ -43,100 +53,48 @@ struct LaTeXFeatures {
string const getTClassPreamble() const; string const getTClassPreamble() const;
/// The sgml definitions needed by the document (dobook/linuxdoc) /// The sgml definitions needed by the document (dobook/linuxdoc)
string const getLyXSGMLEntities() const; string const getLyXSGMLEntities() const;
/// /// The SGML Required to include the files added with includeFile();
string const getIncludedFiles(string const & fname) const; string const getIncludedFiles(string const & fname) const;
/// /// Include a file for use with the SGML entities
void includeFile(string const & key, string const & name);
/// The float definitions.
void getFloatDefinitions(std::ostream & os) const; void getFloatDefinitions(std::ostream & os) const;
/// Print requirements to lyxerr
///
void showStruct() const; void showStruct() const;
///
void addExternalPreamble(string const &);
/// Provide a string name-space to the requirements /// Provide a string name-space to the requirements
void require(string const & name); void require(string const & name);
/// Is the package required?
bool isRequired(string const & name) const;
///
void useFloat(string const & name);
///
void useLanguage(Language const *);
///
bool hasLanguages();
///
string getLanguages() const;
///
std::set<string> getEncodingSet(string const & doc_encoding);
///
///
void useLayout(std::vector<bool>::size_type const & idx);
///
BufferParams const & bufferParams() const;
///
/// Static preamble bits from the external material insets private:
string externalPreambles; string externalPreambles;
///
bool array;
///
bool color; // color.sty
///
bool graphicx; // graphicx.sty
///
bool graphics; // graphics.sty
///
bool setspace; // setspace.sty
///
bool makeidx; // makeind.sty
///
bool verbatim; // verbatim.sty
///
bool longtable; // longtable.sty
///
//bool algorithm; // algorithm.sty
///
bool rotating; // rotating.sty
///
bool amssymb; // amssymb.sty
///
bool latexsym; // latexsym.sty
///
bool pifont; // pifont.sty
///
bool subfigure; // subfigure.sty
///
bool floatflt; // floatflt.sty
///
bool url; // url.sty
///
bool varioref; // varioref.sty
///
bool prettyref; // prettyref.sty
///
bool chess; // skak.sty (new chess support)
///
bool natbib; // natbib.sty
///
bool floats; // float.sty
///
bool lyx;
///
bool lyxline;
/// \noun
bool noun;
/// \lyxarrow
bool lyxarrow;
///
bool quotesinglbase;
///
bool quotedblbase;
///
bool guilsinglleft;
///
bool guilsinglright;
///
bool guillemotleft;
///
bool guillemotright;
///
bool amsstyle;
///
bool boldsymbol;
///
bool binom;
std::vector<bool> layout; std::vector<bool> layout;
/// Static preamble bits from the external material insets
typedef std::list<string> FeaturesList;
/// ///
bool ParagraphIndent; FeaturesList features;
///
bool NeedLyXFootnoteCode;
///
bool NeedLyXMinipageIndent;
/// ///
typedef std::set<Language const *> LanguageList; typedef std::set<Language const *> LanguageList;
/// ///
@ -150,8 +108,6 @@ struct LaTeXFeatures {
/// ///
FileMap IncludedFiles; FileMap IncludedFiles;
/// ///
BufferParams const & bufferParams() const;
private:
/// ///
BufferParams const & params; BufferParams const & params;
}; };

View File

@ -2057,16 +2057,13 @@ void Buffer::makeLaTeXFile(string const & fname,
if (params.language->babel() == "hebrew" if (params.language->babel() == "hebrew"
&& default_language->babel() != "hebrew") && default_language->babel() != "hebrew")
// This seems necessary // This seems necessary
features.UsedLanguages.insert(default_language); features.useLanguage(default_language);
if (lyxrc.language_use_babel || if (lyxrc.language_use_babel ||
params.language->lang() != lyxrc.default_language || params.language->lang() != lyxrc.default_language ||
!features.UsedLanguages.empty()) { !features.hasLanguages()) {
use_babel = true; use_babel = true;
for (LaTeXFeatures::LanguageList::const_iterator cit = language_options << features.getLanguages();
features.UsedLanguages.begin();
cit != features.UsedLanguages.end(); ++cit)
language_options << (*cit)->babel() << ',';
language_options << params.language->babel(); language_options << params.language->babel();
if (lyxrc.language_global_options) if (lyxrc.language_global_options)
options << language_options.str() << ','; options << language_options.str() << ',';
@ -2113,12 +2110,7 @@ void Buffer::makeLaTeXFile(string const & fname,
// Create a list with all the input encodings used // Create a list with all the input encodings used
// in the document // in the document
set<string> encodings; set<string> encodings = features.getEncodingSet(doc_encoding);
for (LaTeXFeatures::LanguageList::const_iterator it =
features.UsedLanguages.begin();
it != features.UsedLanguages.end(); ++it)
if ((*it)->encoding()->LatexName() != doc_encoding)
encodings.insert((*it)->encoding()->LatexName());
ofs << "\\usepackage["; ofs << "\\usepackage[";
std::copy(encodings.begin(), encodings.end(), std::copy(encodings.begin(), encodings.end(),
@ -2234,12 +2226,13 @@ void Buffer::makeLaTeXFile(string const & fname,
ofs << "}\n"; ofs << "}\n";
texrow.newline(); texrow.newline();
} }
if (features.amsstyle
&& !tclass.provides(LyXTextClass::amsmath)) { if (features.isRequired("amsstyle")
&& !tclass.provides(LyXTextClass::amsmath)) {
ofs << "\\usepackage{amsmath}\n"; ofs << "\\usepackage{amsmath}\n";
texrow.newline(); texrow.newline();
} }
if (tokenPos(tclass.opt_pagestyle(), if (tokenPos(tclass.opt_pagestyle(),
'|', params.pagestyle) >= 0) { '|', params.pagestyle) >= 0) {
if (params.pagestyle == "fancy") { if (params.pagestyle == "fancy") {
@ -3388,8 +3381,8 @@ void Buffer::validate(LaTeXFeatures & features) const
textclasslist.TextClass(params.textclass); textclasslist.TextClass(params.textclass);
// AMS Style is at document level // AMS Style is at document level
features.amsstyle = (params.use_amsmath || if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
tclass.provides(LyXTextClass::amsmath)); features.require("amsstyle");
while (par) { while (par) {
// We don't use "lyxerr.debug" because of speed. (Asger) // We don't use "lyxerr.debug" because of speed. (Asger)
@ -3418,12 +3411,12 @@ void Buffer::validate(LaTeXFeatures & features) const
|| c == 25 || c == 25
|| c == 26 || c == 26
|| c == 31) { || c == 31) {
features.latexsym = true; features.require("latexsym");
} }
} else if (font == 1) { } else if (font == 1) {
features.amssymb = true; features.require("amssymb");
} else if ((font >= 2 && font <= 5)) { } else if ((font >= 2 && font <= 5)) {
features.pifont = true; features.require("pifont");
} }
} }
} }

View File

@ -1,3 +1,7 @@
2001-11-11 Michael A. Koziarski <michael@koziarski.org>
* various: updated to use the new LaTeXFeatures
2001-11-14 José Matos <jamatos@fep.up.pt> 2001-11-14 José Matos <jamatos@fep.up.pt>
* insetspecialchar.C (linuxdoc): * insetspecialchar.C (linuxdoc):

View File

@ -1194,8 +1194,9 @@ int InsetFig::docbook(Buffer const *, ostream & os) const
void InsetFig::validate(LaTeXFeatures & features) const void InsetFig::validate(LaTeXFeatures & features) const
{ {
features.graphics = true; features.require("graphics");
if (subfigure) features.subfigure = true; if (subfigure)
features.require("subfigure");
} }

View File

@ -106,5 +106,5 @@ int InsetCitation::latex(Buffer const * buffer, std::ostream & os,
void InsetCitation::validate(LaTeXFeatures & features) const void InsetCitation::validate(LaTeXFeatures & features) const
{ {
if (features.bufferParams().use_natbib) if (features.bufferParams().use_natbib)
features.natbib = true; features.require("natbib");
} }

View File

@ -185,7 +185,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const
features.require(cit->second.requirement); features.require(cit->second.requirement);
} }
if (!cit->second.preamble.empty()) { if (!cit->second.preamble.empty()) {
features.externalPreambles += cit->second.preamble + "\n"; features.addExternalPreamble(cit->second.preamble + "\n");
} }
} }

View File

@ -185,10 +185,10 @@ void InsetFloat::read(Buffer const * buf, LyXLex & lex)
void InsetFloat::validate(LaTeXFeatures & features) const void InsetFloat::validate(LaTeXFeatures & features) const
{ {
if (contains(placement(), "H")) { if (contains(placement(), "H")) {
features.floats = true; features.require("floats");
} }
features.usedFloats.insert(floatType_); features.useFloat(floatType_);
InsetCollapsable::validate(features); InsetCollapsable::validate(features);
} }

View File

@ -784,10 +784,10 @@ void InsetGraphics::validate(LaTeXFeatures & features) const
if (params.filename.empty()) if (params.filename.empty())
return ; return ;
features.graphicx = true; features.require("graphicx");
if (params.subcaption) if (params.subcaption)
features.subfigure = true; features.require("subfigure");
} }

View File

@ -394,10 +394,10 @@ void InsetInclude::validate(LaTeXFeatures & features) const
if (IsLyXFilename(getFileName())) if (IsLyXFilename(getFileName()))
writefile = ChangeExtension(writefile, ".sgml"); writefile = ChangeExtension(writefile, ".sgml");
features.IncludedFiles[include_label] = writefile; features.includeFile(include_label, writefile);
if (isVerbatim()) if (isVerbatim())
features.verbatim = true; features.require("verbatim");
// Here we must do the fun stuff... // Here we must do the fun stuff...
// Load the file in the include if it needs // Load the file in the include if it needs

View File

@ -62,7 +62,7 @@ string const InsetPrintIndex::getScreenLabel(Buffer const *) const
void InsetPrintIndex::validate(LaTeXFeatures & features) const void InsetPrintIndex::validate(LaTeXFeatures & features) const
{ {
features.makeidx = true; features.require("makeidx");
} }

View File

@ -343,16 +343,16 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
&& lyxrc.fontenc != "T1") { && lyxrc.fontenc != "T1") {
if (times_ == SingleQ) if (times_ == SingleQ)
switch (type) { switch (type) {
case ',': features.quotesinglbase = true; break; case ',': features.require("quotesinglbase"); break;
case '<': features.guilsinglleft = true; break; case '<': features.require("guilsinglleft"); break;
case '>': features.guilsinglright = true; break; case '>': features.require("guilsinglright"); break;
default: break; default: break;
} }
else else
switch (type) { switch (type) {
case ',': features.quotedblbase = true; break; case ',': features.require("quotedblbase"); break;
case '<': features.guillemotleft = true; break; case '<': features.require("guillemotleft"); break;
case '>': features.guillemotright = true; break; case '>': features.require("guillemotright"); break;
default: break; default: break;
} }
} }

View File

@ -101,9 +101,9 @@ int InsetRef::docbook(Buffer const *, ostream & os) const
void InsetRef::validate(LaTeXFeatures & features) const void InsetRef::validate(LaTeXFeatures & features) const
{ {
if (getCmdName() == "vref" || getCmdName() == "vpageref") if (getCmdName() == "vref" || getCmdName() == "vpageref")
features.varioref = true; features.require("varioref");
else if (getCmdName() == "prettyref") else if (getCmdName() == "prettyref")
features.prettyref = true; features.require("prettyref");
} }
InsetRef::type_info InsetRef::types[] = { InsetRef::type_info InsetRef::types[] = {

View File

@ -318,7 +318,7 @@ Inset * InsetSpecialChar::clone(Buffer const &, bool) const
void InsetSpecialChar::validate(LaTeXFeatures & features) const void InsetSpecialChar::validate(LaTeXFeatures & features) const
{ {
if (kind_ == MENU_SEPARATOR) { if (kind_ == MENU_SEPARATOR) {
features.lyxarrow = true; features.require("lyxarrow");
} }
} }

View File

@ -91,5 +91,5 @@ int InsetUrl::DocBook(Buffer const *, ostream & os) const
void InsetUrl::validate(LaTeXFeatures & features) const void InsetUrl::validate(LaTeXFeatures & features) const
{ {
features.url = true; features.require("url");
} }

View File

@ -1,3 +1,8 @@
2001-11-11 Michael A. Koziarski <michael@koziarski.org>
* math_macro.C
* math_hullinset.C: Fixes to use the new LaTeXFeatures
correctly.
2001-11-07 André Pönitz <poenitz@gmx.net> 2001-11-07 André Pönitz <poenitz@gmx.net>

View File

@ -252,14 +252,17 @@ bool MathHullInset::numberedType() const
void MathHullInset::validate(LaTeXFeatures & features) const void MathHullInset::validate(LaTeXFeatures & features) const
{ {
features.amsstyle = ams();
if (ams())
features.require("amsstyle");
// Validation is necessary only if not using AMS math. // Validation is necessary only if not using AMS math.
// To be safe, we will always run mathedvalidate. // To be safe, we will always run mathedvalidate.
//if (features.amsstyle) //if (features.amsstyle)
// return; // return;
features.boldsymbol = true; features.require("boldsymbol");
//features.binom = true; //features.binom = true;
MathNestInset::validate(features); MathNestInset::validate(features);

View File

@ -189,7 +189,7 @@ bool MathMacro::idxRight(idx_type &, pos_type &) const
void MathMacro::validate(LaTeXFeatures & features) const void MathMacro::validate(LaTeXFeatures & features) const
{ {
if (name() == "binom") if (name() == "binom")
features.binom = true; features.require("binom");
//MathInset::validate(features); //MathInset::validate(features);
} }

View File

@ -329,12 +329,12 @@ void Paragraph::validate(LaTeXFeatures & features) const
// check the params. // check the params.
if (params().lineTop() || params().lineBottom()) if (params().lineTop() || params().lineBottom())
features.lyxline = true; features.require("lyxline");
if (!params().spacing().isDefault()) if (!params().spacing().isDefault())
features.setspace = true; features.require("setspace");
// then the layouts // then the layouts
features.layout[getLayout()] = true; features.useLayout(getLayout());
// then the fonts // then the fonts
Language const * doc_language = bparams.language; Language const * doc_language = bparams.language;
@ -345,7 +345,7 @@ void Paragraph::validate(LaTeXFeatures & features) const
lyxerr[Debug::LATEX] << "font.noun: " lyxerr[Debug::LATEX] << "font.noun: "
<< cit->font().noun() << cit->font().noun()
<< endl; << endl;
features.noun = true; features.require("noun");
lyxerr[Debug::LATEX] << "Noun enabled. Font: " lyxerr[Debug::LATEX] << "Noun enabled. Font: "
<< cit->font().stateText(0) << cit->font().stateText(0)
<< endl; << endl;
@ -360,7 +360,7 @@ void Paragraph::validate(LaTeXFeatures & features) const
case LColor::note: case LColor::note:
break; break;
default: default:
features.color = true; features.require("color");
lyxerr[Debug::LATEX] << "Color enabled. Font: " lyxerr[Debug::LATEX] << "Color enabled. Font: "
<< cit->font().stateText(0) << cit->font().stateText(0)
<< endl; << endl;
@ -374,7 +374,7 @@ void Paragraph::validate(LaTeXFeatures & features) const
#endif #endif
language != latex_language) language != latex_language)
{ {
features.UsedLanguages.insert(language); features.useLanguage(language);
lyxerr[Debug::LATEX] << "Found language " lyxerr[Debug::LATEX] << "Found language "
<< language->babel() << endl; << language->babel() << endl;
} }
@ -391,7 +391,7 @@ void Paragraph::validate(LaTeXFeatures & features) const
cit->inset->validate(features); cit->inset->validate(features);
if (layout.needprotect && if (layout.needprotect &&
cit->inset->lyxCode() == Inset::FOOT_CODE) cit->inset->lyxCode() == Inset::FOOT_CODE)
features.NeedLyXFootnoteCode = true; features.require("NeedLyXFootnoteCode");
} }
} }
} }

View File

@ -2620,12 +2620,12 @@ InsetText * LyXTabular::GetCellInset(int row, int column) const
void LyXTabular::Validate(LaTeXFeatures & features) const void LyXTabular::Validate(LaTeXFeatures & features) const
{ {
if (IsLongTabular()) if (IsLongTabular())
features.longtable = true; features.require("longtable");
if (NeedRotating()) if (NeedRotating())
features.rotating = true; features.require("rotating");
for (int cell = 0; !features.array && (cell < numberofcells); ++cell) { for (int cell = 0; !features.isRequired("array") && (cell < numberofcells); ++cell) {
if (GetVAlignment(cell) != LYX_VALIGN_TOP) if (GetVAlignment(cell) != LYX_VALIGN_TOP)
features.array = true; features.require("array");
GetCellInset(cell)->validate(features); GetCellInset(cell)->validate(features);
} }
} }