On Sat, Jul 26, 2025 at 07:41:03PM +0200, Jean-Marc Lasgouttes wrote:
Le 26 juillet 2025 19:01:05 GMT+02:00, Richard Kimberly Heck
<rikih...@gmail.com> a écrit :
It seems unfortunate that I had to mess with the CPP code to add this symbol.
That means an ordinary user couldn't have done so. Without that, LyX did not
try to load the package. Couldn't we let LyX load unknown packages mentioned in
lib/symbols?
That would make sense.
The attached patch works for me. It simply scans for required packages
that not have already been accounted for and loads them at the end.
So, only packages requiring a special treatment have to be explicitly
added to the list already known to LyX and, most importantly, the patch
does not change the current behavior wrt the list of "simplefeatures".
--
Enrico
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 3670dc26d7..54d37e4d81 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -775,7 +775,11 @@ bool LaTeXFeatures::isProvided(string const & name) const
bool LaTeXFeatures::mustProvide(string const & name) const
{
- return isRequired(name) && !isProvided(name);
+ if (isRequired(name) && !isProvided(name)) {
+ features_loaded_.insert(name);
+ return true;
+ }
+ return false;
}
@@ -1305,12 +1309,6 @@ string const LaTeXFeatures::getPackages() const
{
ostringstream packages;
- // FIXME: currently, we can only load packages and macros known
- // to LyX.
- // However, with the Require tag of layouts/custom insets,
- // also unknown packages can be requested. They are silently
- // swallowed now. We should change this eventually.
-
// Simple hooks to add things before or after a given "simple"
// feature. Useful if loading order matters.
map<string, string> before_simplefeature_;
@@ -1612,6 +1610,11 @@ string const LaTeXFeatures::getPackages() const
packages << "\\usepackage{microtype}\n";
}
+ for (string const & name : features_) {
+ if (features_loaded_.find(name) == features_loaded_.end())
+ packages << "\\usepackage{" << name << "}\n";
+ }
+
return packages.str();
}
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 2d6fce25ca..2909a89e94 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -224,6 +224,8 @@ private:
Features features_;
/// Features that are provided
Features provides_;
+ /// Already accounted for features
+ mutable Features features_loaded_;
/// Static preamble bits, from external templates, or anywhere else
typedef std::list<TexString> SnippetList;
///
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel