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.

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,46 @@
 
 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 *);
 
+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,6 +727,17 @@
 
 	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
+	}
+	//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