Jürgen Spitzmüller wrote:
Richard Heck wrote:
This is a hack, and I haven't tested it, or even compiled it, since I
can't compile here at the moment. Just an idea in lieu of more
sophisticated packaging stuff.

Note that we are also requiering macros, such as "LyX", "noun" or "ct-xcolor-soul". All these would need to be considered as well.

Ick. OK, then, we can do that.

rh

Index: LaTeXFeatures.cpp
===================================================================
--- LaTeXFeatures.cpp	(revision 22419)
+++ LaTeXFeatures.cpp	(working copy)
@@ -494,6 +494,8 @@
 
 namespace {
 
+//  These are all the 'simple' includes.  i.e
+//  packages which we just \usepackage{package}
 char const * simplefeatures[] = {
 // note that the package order here will be the same in the LaTeX-output
 	"array",
@@ -539,28 +541,79 @@
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
 
+//other features handled in getPackages() that require more complicated
+//output
+char const * complexfeatures[] = {
+	"amsmath",
+	"wasysym",
+	"color",
+	"makeidx",
+	"graphicx",
+	"lyxskak",
+	"setspace",
+	"amssymb",
+	"esint",
+	"natbib",
+	"jurabib",
+	"bibtopic",
+	"xy",
+	"nomencl"
 }
 
 
+int const nb_complexfeatures = sizeof(complexfeatures) / sizeof(char const *);
+
+
+//macros recognized by getMacros()
+char const * macrofeatures[] = {
+	"LyX", 
+	"lyxline",
+	"noun",
+	"lyxarrow",
+	"textgreek",
+	"textcyr",
+	"quotesinglbase",
+	"quotedblbase",
+	"guilsinglleft",
+	"guilsinglright",
+	"guillemotleft",
+	"guillemotright",
+	"boldsymbol",
+	"binom",
+	"mathcircumflex",
+	"newlyxcommand",
+	"ParagraphLeftIndent",
+	"NeedLyXFootnoteCode",
+	"NeedTabularnewline",
+	"lyxgreyedout",
+	"lyxdot",
+	"ct-dvipost",
+	"ct-xcolor-soul",
+	"ct-none"
+}
+
+
+int const nb_macrofeatures = sizeof(macrofeatures) / sizeof(char const *);
+
+void eraseFeature(FeaturesList & f, string n)
+{
+	f.erase(f.find(n));
+}
+
+} // end anonymous namespace
+
+
 string const LaTeXFeatures::getPackages() const
 {
 	ostringstream packages;
 	TextClass const & tclass = params_.getTextClass();
+	FeatureList unknownFeatures = features_;
 
-	// FIXME: currently, we can only load packages and macros known
-	// to LyX.
-	// However, with the Require tag of layouts/custom insets,
-	// also inknown packages can be requested. They are silently
-	// swallowed now. We should change this eventually.
-
-	//
-	//  These are all the 'simple' includes.  i.e
-	//  packages which we just \usepackage{package}
-	//
 	for (int i = 0; i < nb_simplefeatures; ++i) {
-		if (mustProvide(simplefeatures[i]))
-			packages << "\\usepackage{"
-				 << simplefeatures[i] << "}\n";
+		string const & pkg = simplefeatures[i];
+		if (mustProvide(pkg))
+			packages << "\\usepackage{" << pkg << "}\n";
+		eraseFeature(unknownFeatures, pkg); //LyX has handled this one
 	}
 
 	//
@@ -707,7 +760,24 @@
 
 	if (mustProvide("listings"))
 		packages << "\\usepackage{listings}\n";
+	
+	//delete all the complex features from the list...
+	for (int i = 0; i < nb_complexfeatures; ++i) {
+		string const & pkg = complexfeatures[i];
+		eraseFeatures(unknownFeatures, pkg); //LyX handled it
+	}
+	//...and the macros
+	for (int i = 0; i < nb_macrofeatures; ++i) {
+		string const & pkg = macrofeatures[i];
+		eraseFeatures(unknownFeatures, pkg); //LyX handled it
+	}
 
+	//usepackage all the remaining requires
+	FeatureList::const_iterator it = unknownFeatures.begin();
+	FeatureList::const_iterator end = unknownFeatures.end();
+	for (; it != end; ++it) 
+		packages << "\\usepackage{" + *it + "}\n";
+
 	return packages.str();
 }
 

Reply via email to