rgheck wrote: > Yes, it would. OK. I'll do this before I commit anything.
> Something like this will work. Just a couple thoughts. > > First, I don't think we want to tie this too tightly to LaTeXFeatures, > so that we have to hardcode what packages can be Required. This will > make maintenance difficult---you didn't list endnotes.sty---and anyway done now. The first patch was just a proof of concept. > users ought to be able to Require packages in their custom layouts. So > I'd suggest we have a more flexible mechanism for keeping track of what > packages have been Required---just a vector we build---one that could be > integrated at the last minute with LaTeXFeatures. but then we lose all our possiblilities of package checking. > Secondly, it seems like we ought for the same reason to have a Requires > tag in the TextClass itself. done. Patch attached. I think we can get rid of the ugly optional argument of DeclareLyXModule now. Jürgen
Index: lib/layouts/endnotes.module =================================================================== --- lib/layouts/endnotes.module (Revision 22411) +++ lib/layouts/endnotes.module (Arbeitskopie) @@ -1,4 +1,4 @@ -#\DeclareLyXModule[endnotes.sty]{Adds an endnote command, in addition to footnotes. You will need to add \theendnotes in ERT where you want the endnotes to appear.}{Endnote} +#\DeclareLyXModule{Adds an endnote command, in addition to footnotes. You will need to add \theendnotes in ERT where you want the endnotes to appear.}{Endnote} Format 5 @@ -11,7 +11,5 @@ Size Small EndFont LabelString endnote - Preamble - \usepackage{endnotes} - EndPreamble + Requires endnotes End Index: lib/layouts/foottoend.module =================================================================== --- lib/layouts/foottoend.module (Revision 22411) +++ lib/layouts/foottoend.module (Arbeitskopie) @@ -1,8 +1,9 @@ -#\DeclareLyXModule[endnotes.sty]{Sets all footnotes as endnotes. You will need to add \theendnotes in ERT where you want the endnotes to appear.}{Foot to End} +#\DeclareLyXModule{Sets all footnotes as endnotes. You will need to add \theendnotes in ERT where you want the endnotes to appear.}{Foot to End} Format 5 +Requires endnotes + Preamble - \usepackage{endnotes} \let\footnote=\endnote EndPreamble Index: lib/layouts/linguistics.module =================================================================== --- lib/layouts/linguistics.module (Revision 22411) +++ lib/layouts/linguistics.module (Arbeitskopie) @@ -1,4 +1,4 @@ -#\DeclareLyXModule[covington.sty]{Defines some special environments useful for linguistics (numbered examples, glosses, semantic markup).}{Linguistics} +#\DeclareLyXModule{Defines some special environments useful for linguistics (numbered examples, glosses, semantic markup).}{Linguistics} # Author: Jürgen Spitzmüller <[EMAIL PROTECTED]> @@ -24,9 +24,7 @@ Shape Italic Color Blue EndFont - Preamble - \usepackage{covington} - EndPreamble + Requires covington End @@ -49,9 +47,8 @@ LatexName subexample LeftMargin XSubexample: LabelString "Subexample:" + Requires covington,enumitem Preamble - \usepackage{covington} - \usepackage{enumitem} \newenvironment{subexample}{% \begin{example}\begin{enumerate}[leftmargin=1.7em] \renewcommand\theenumi{\alph{enumi}} @@ -76,8 +73,8 @@ MultiPar true PassThru true FreeSpacing true + Requires covington Preamble - \usepackage{covington} [EMAIL PROTECTED] \newenvironment{linggloss}[1]{% \gll #1} @@ -100,8 +97,8 @@ MultiPar true PassThru true FreeSpacing true + Requires covington Preamble - \usepackage{covington} [EMAIL PROTECTED] \newenvironment{lingglosss}[1]{% \glll #1} @@ -143,8 +140,8 @@ LabelString meaning LatexType command LatexName lingmeaning + Requires csquotes Preamble - \usepackage{csquotes} \newcommand{\lingmeaning}[1]{\enquote*{#1}} EndPreamble End Index: lib/layouts/theorems-ams.module =================================================================== --- lib/layouts/theorems-ams.module (Revision 22411) +++ lib/layouts/theorems-ams.module (Arbeitskopie) @@ -4,10 +4,12 @@ # Adapted from amsdefs.inc and amsmaths.inc Format 5 + +Requires amsmath + Preamble - \usepackage{amsmath} \theoremstyle{plain} - \newtheorem{thm}{Theorem}[section] + \newtheorem{thm}{Theorem}[section] EndPreamble Index: lib/layouts/theorems-ams-withinsec.module =================================================================== --- lib/layouts/theorems-ams-withinsec.module (Revision 22411) +++ lib/layouts/theorems-ams-withinsec.module (Arbeitskopie) @@ -4,10 +4,12 @@ # Adapted from amsdefs.inc and amsmaths.inc Format 5 + +Requires amsmath + Preamble - \usepackage{amsmath} \theoremstyle{plain} - \newtheorem{thm}{Theorem}[section] + \newtheorem{thm}{Theorem}[section] EndPreamble Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (Revision 22411) +++ src/TextClass.cpp (Arbeitskopie) @@ -150,6 +150,7 @@ TC_CLASSOPTIONS, TC_PREAMBLE, TC_PROVIDES, + TC_REQUIRES, TC_LEFTMARGIN, TC_RIGHTMARGIN, TC_FLOAT, @@ -188,6 +189,7 @@ { "pagestyle", TC_PAGESTYLE }, { "preamble", TC_PREAMBLE }, { "provides", TC_PROVIDES }, + { "requires", TC_REQUIRES }, { "rightmargin", TC_RIGHTMARGIN }, { "secnumdepth", TC_SECNUMDEPTH }, { "sides", TC_SIDES }, @@ -203,7 +205,7 @@ break; case MERGE: LYXERR(Debug::TCLASS, "Reading input file "); - break; + break; case MODULE: LYXERR(Debug::TCLASS, "Reading module file "); break; @@ -391,6 +393,13 @@ break; } + case TC_REQUIRES: { + lexrc.eatLine(); + string const packages = lexrc.getString(); + requires_ = getVectorFromString(packages); + break; + } + case TC_LEFTMARGIN: // left margin type if (lexrc.next()) leftmargin_ = lexrc.getDocString(); @@ -609,6 +618,7 @@ IL_NEEDPROTECT, IL_PASSTHRU, IL_PREAMBLE, + IL_REQUIRES, IL_END }; @@ -632,7 +642,8 @@ { "multipar", IL_MULTIPAR }, { "needprotect", IL_NEEDPROTECT }, { "passthru", IL_PASSTHRU }, - { "preamble", IL_PREAMBLE } + { "preamble", IL_PREAMBLE }, + { "requires", IL_REQUIRES } }; lexrc.pushTable(elementTags, IL_END); @@ -647,6 +658,7 @@ FontInfo labelfont = inherit_font; ColorCode bgcolor(Color_background); string preamble; + vector<string> requires; bool multipar = false; bool passthru = false; bool needprotect = false; @@ -659,7 +671,7 @@ int le = lexrc.lex(); switch (le) { case Lexer::LEX_UNDEF: - lexrc.printError("Unknown ClassOption tag `$$Token'"); + lexrc.printError("Unknown InsetLayout tag `$$Token'"); continue; default: break; } @@ -729,6 +741,12 @@ case IL_PREAMBLE: preamble = lexrc.getLongString("EndPreamble"); break; + case IL_REQUIRES: { + lexrc.eatLine(); + string const packages = lexrc.getString(); + requires = getVectorFromString(packages); + break; + } case IL_END: getout = true; break; @@ -756,8 +774,9 @@ // any realization against a given context. labelfont.realize(sane_font); il.labelfont = labelfont; - il.bgcolor = bgcolor; + il.bgcolor = bgcolor; il.preamble = preamble; + il.requires = requires; insetlayoutlist_[name] = il; } @@ -809,7 +828,7 @@ int le = lexrc.lex(); switch (le) { case Lexer::LEX_UNDEF: - lexrc.printError("Unknown ClassOption tag `$$Token'"); + lexrc.printError("Unknown float tag `$$Token'"); continue; default: break; } @@ -909,7 +928,7 @@ int le = lexrc.lex(); switch (le) { case Lexer::LEX_UNDEF: - lexrc.printError("Unknown ClassOption tag `$$Token'"); + lexrc.printError("Unknown counter tag `$$Token'"); continue; default: break; } Index: src/Layout.h =================================================================== --- src/Layout.h (Revision 22411) +++ src/Layout.h (Arbeitskopie) @@ -19,6 +19,9 @@ #include "Spacing.h" #include "support/docstring.h" +#include <vector> +#include <string> + namespace lyx { class Lexer; @@ -81,6 +84,8 @@ /// docstring const & preamble() const { return preamble_; } /// + std::vector<std::string> const & requires() const { return requires_; } + /// std::string const & latexparam() const { return latexparam_; } /// std::string const & innertag() const { return innertag_; } @@ -250,6 +255,8 @@ std::string itemtag_; /// Macro definitions needed for this layout docstring preamble_; + /// Packages needed for this layout + std::vector<std::string> requires_; }; } // namespace lyx Index: src/insets/InsetFlex.cpp =================================================================== --- src/insets/InsetFlex.cpp (Revision 22411) +++ src/insets/InsetFlex.cpp (Arbeitskopie) @@ -22,6 +22,7 @@ #include "FuncStatus.h" #include "Cursor.h" #include "support/gettext.h" +#include "LaTeXFeatures.h" #include "Lexer.h" #include "Text.h" #include "MetricsInfo.h" @@ -46,6 +47,8 @@ : InsetCollapsable(bp, Collapsed, &il) { name_ = il.name; + packages_ = il.requires; + preamble_ = il.preamble; } @@ -136,4 +139,17 @@ os << paragraphs().begin()->asString(buf, true); } + +void InsetFlex::validate(LaTeXFeatures & features) const +{ + if (!preamble_.empty()) + features.addPreambleSnippet(preamble_); + if (packages_.empty()) + return; + for (vector<string>::const_iterator it = packages_.begin(); + it != packages_.end(); ++it) { + features.require(*it); + } +} + } // namespace lyx Index: src/insets/InsetLayout.h =================================================================== --- src/insets/InsetLayout.h (Revision 22411) +++ src/insets/InsetLayout.h (Arbeitskopie) @@ -15,6 +15,9 @@ #include "support/docstring.h" +#include <vector> +#include <string> + namespace lyx { /// @@ -31,6 +34,7 @@ FontInfo labelfont; ColorCode bgcolor; std::string preamble; + std::vector<std::string> requires; bool multipar; bool passthru; bool needprotect; Index: src/insets/InsetFlex.h =================================================================== --- src/insets/InsetFlex.h (Revision 22411) +++ src/insets/InsetFlex.h (Arbeitskopie) @@ -51,6 +51,8 @@ OutputParams const &) const; /// the string that is passed to the TOC virtual void textString(Buffer const &, odocstream &) const; + /// + void validate(LaTeXFeatures &) const; /// should paragraph indendation be ommitted in any case? bool neverIndent(Buffer const &) const { return true; } @@ -63,6 +65,10 @@ /// std::string name_; + /// + std::vector<std::string> packages_; + /// + std::string preamble_; }; Index: src/TextClass.h =================================================================== --- src/TextClass.h (Revision 22411) +++ src/TextClass.h (Arbeitskopie) @@ -137,6 +137,8 @@ /// is this feature already provided by the class? bool provides(std::string const & p) const; + /// features required by the class? + std::vector<std::string> requires() const { return requires_; } /// unsigned int columns() const; @@ -202,6 +204,8 @@ docstring preamble_; /// latex packages loaded by document class. std::set<std::string> provides_; + /// latex packages requested by document class. + std::vector<std::string> requires_; /// unsigned int columns_; /// Index: src/Paragraph.cpp =================================================================== --- src/Paragraph.cpp (Revision 22411) +++ src/Paragraph.cpp (Arbeitskopie) @@ -999,6 +999,13 @@ // then the layouts features.useLayout(layout.name()); + if (!layout.requires().empty()) { + vector<string> req = layout.requires(); + for (vector<string>::const_iterator it = req.begin(); + it != req.end(); ++it) { + features.require(*it); + } + } // then the fonts fontlist_.validate(features); Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (Revision 22411) +++ src/LaTeXFeatures.cpp (Arbeitskopie) @@ -530,6 +530,10 @@ "mathrsfs", "ascii", "url", + "covington", + "csquotes", + "enumitem", + "endnotes" }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); @@ -832,15 +836,6 @@ tcpreamble << tclass[*cit]->preamble(); } - InsetLayouts const & insetlayouts = tclass.insetlayouts(); - InsetLayouts::const_iterator cit2 = insetlayouts.begin(); - InsetLayouts::const_iterator end2 = insetlayouts.end(); - for (; cit2 != end2; ++cit2) { - if (isRequired(to_utf8(cit2->first))) { - tcpreamble << from_utf8(cit2->second.preamble); - } - } - return tcpreamble.str(); } Index: src/Layout.cpp =================================================================== --- src/Layout.cpp (Revision 22411) +++ src/Layout.cpp (Arbeitskopie) @@ -82,6 +82,7 @@ LT_PARSKIP, //LT_PLAIN, LT_PREAMBLE, + LT_REQUIRES, LT_RIGHTMARGIN, LT_SPACING, LT_TOPSEP, @@ -179,6 +180,7 @@ { "parskip", LT_PARSKIP }, { "passthru", LT_PASS_THRU }, { "preamble", LT_PREAMBLE }, + { "requires", LT_REQUIRES }, { "rightmargin", LT_RIGHTMARGIN }, { "spacing", LT_SPACING }, { "textfont", LT_TEXTFONT }, @@ -484,6 +486,12 @@ case LT_SPACING: // setspace.sty readSpacing(lexrc); break; + + case LT_REQUIRES: + if (lexrc.eatLine()) + requires_ = getVectorFromString(lexrc.getString()); + break; + } } lexrc.popTable(); Index: src/BufferParams.cpp =================================================================== --- src/BufferParams.cpp (Revision 22411) +++ src/BufferParams.cpp (Arbeitskopie) @@ -810,6 +810,14 @@ void BufferParams::validate(LaTeXFeatures & features) const { + if (!getTextClass().requires().empty()) { + vector<string> req = getTextClass().requires(); + for (vector<string>::const_iterator it = req.begin(); + it != req.end(); ++it) { + features.require(*it); + } + } + if (outputChanges) { bool dvipost = LaTeXFeatures::isAvailable("dvipost"); bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&