Jürgen Spitzmüller wrote: > A "Requires" tag, as a counterpart of the "Provides" tag.
patch attached. I guess this needs a layout format increment, right? Jürgen
Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (Revision 22411) +++ src/TextClass.cpp (Arbeitskopie) @@ -203,7 +203,7 @@ break; case MERGE: LYXERR(Debug::TCLASS, "Reading input file "); - break; + break; case MODULE: LYXERR(Debug::TCLASS, "Reading module file "); break; @@ -609,6 +609,7 @@ IL_NEEDPROTECT, IL_PASSTHRU, IL_PREAMBLE, + IL_REQUIRES, IL_END }; @@ -632,7 +633,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 +649,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 +662,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 +732,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 +765,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 +819,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 +919,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/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,9 @@ "mathrsfs", "ascii", "url", + "covington", + "csquotes", + "enumitem", }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); @@ -832,15 +835,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();