[LyX/master] Leaner solution for the babel prettyref woes
Juergen Spitzmueller
spitz at lyx.org
Tue Aug 15 13:51:08 UTC 2023
commit 5ebf9e3ac6916b06733bd63128445176a63b83cf
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Tue Aug 15 17:05:58 2023 +0200
Leaner solution for the babel prettyref woes
---
src/LaTeXFeatures.cpp | 46 ++++++++++++++++++++++++++--------------------
1 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 3461f97..ab2c846 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1274,35 +1274,41 @@ string const LaTeXFeatures::getPackages() const
// 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_;
+ map<string, string> after_simplefeature_;
+
+ // Babel languages with activated colon (such as French) break
+ // with prettyref. Work around that.
+ if (mustProvide("prettyref") && !runparams_.isFullUnicode()
+ && useBabel() && contains(getActiveChars(), ':')) {
+ before_simplefeature_["prettyref"] =
+ "% Make prettyref compatible with babel active colon\n"
+ "% (make ':' active in prettyref definitions)\n"
+ "\\edef\\lyxsavedcolcatcode{\\the\\catcode`\\:}\n"
+ "\\catcode`:=13\n";
+ after_simplefeature_["prettyref"] =
+ "% restore original catcode for :\n"
+ "\\catcode`\\:=\\lyxsavedcolcatcode\\relax\n";
+ }
+
// These are all the 'simple' includes. i.e
// packages which we just \usepackage{package}
+ // potentially preceded and followed by the hook code
for (char const * feature : simplefeatures) {
- if (mustProvide(feature))
+ if (mustProvide(feature)) {
+ if (before_simplefeature_.find(feature) != before_simplefeature_.end())
+ packages << before_simplefeature_[feature];
packages << "\\usepackage{" << feature << "}\n";
+ if (after_simplefeature_.find(feature) != after_simplefeature_.end())
+ packages << after_simplefeature_[feature];
+ }
}
// The rest of these packages are somewhat more complicated
// than those above.
- // Babel languages with activated colon (such as French) break
- // with prettyref. Work around that.
- if (!runparams_.isFullUnicode() && useBabel()
- && mustProvide("prettyref") && contains(getActiveChars(), ':')) {
- packages << "% Make prettyref compatible with babel active colon\n"
- "\\bgroup\n"
- "\\makeatletter\n"
- "\\catcode`:=13\n"
- "\\gdef\\prettyref#1{\\@prettyref#1:}\n"
- "\\gdef\\@prettyref#1:#2:{%\n"
- " \\expandafter\\ifx\\csname pr@#1\\endcsname\\relax\n"
- " \\PackageWarning{prettyref}{Reference format #1\\space undefined}%\n"
- " \\ref{#1:#2}%\n"
- " \\else\n"
- " \\csname pr@#1\\endcsname{#1:#2}%\n"
- " \\fi}\n"
- "\\egroup\n";
- }
-
if (mustProvide("changebar")) {
packages << "\\usepackage";
if (runparams_.flavor == Flavor::LaTeX
More information about the lyx-cvs
mailing list