commit 441d67a28809e0c2198e2924de19ad34b22abe62 Author: Juergen Spitzmueller <sp...@lyx.org> Date: Wed Aug 27 09:18:38 2025 +0200
Support "alg" in refstyle This is already supported in all other xref packages (even prettyref) --- lib/lyx2lyx/lyx_2_5.py | 8 ++++---- src/LaTeXFeatures.cpp | 28 ++++++++++++++++++++++++++++ src/insets/InsetRef.cpp | 10 ++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py index 862e1bb57b..358d932888 100644 --- a/lib/lyx2lyx/lyx_2_5.py +++ b/lib/lyx2lyx/lyx_2_5.py @@ -3182,8 +3182,8 @@ def revert_prettyref_l7n(document): if i != -1: document.header[i] = "\\crossref_package prettyref" -def convert_refstyle_enu(document): - """Convert refstyle enu: formatted refs to simple ref""" +def convert_refstyle_unsupported(document): + """Convert previously unsupported refstyle refs (enu: and alg:) to simple ref""" if find_token(document.header, "\\crossref_package refstyle", 0) == -1: return @@ -3204,7 +3204,7 @@ def convert_refstyle_enu(document): continue label = get_quoted_value(document.body, "reference", i, j) - if label.startswith("enu:"): + if label.startswith("enu:") or label.startswith("alg:"): document.body[k] = "LatexCommand ref" i += 1 @@ -3291,7 +3291,7 @@ convert = [ [640, []], [641, [convert_justification_pref]], [642, []], - [643, [convert_refstyle_enu]] + [643, [convert_refstyle_unsupported]] ] diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 522d794095..4b2e776d71 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -1814,6 +1814,8 @@ TexString LaTeXFeatures::getMacros() const // floats getFloatDefinitions(macros); + // extra xref definitions + // FIXME: longterm, provide layout tags if (mustProvide("refstyle:charef")) { // this is not provided by the package, but we use the prefix // copy the definition is a copy of chapref @@ -1861,6 +1863,22 @@ TexString LaTeXFeatures::getMacros() const << '\n'; } + if (mustProvide("refstyle:algref")) { + // this is not provided by the package, but we use the prefix + macros << "\\RS@ifundefined{algref}{\n" + << " \\newref{alg}{\n" + << " name = \\RSalgtxt,\n" + << " names = \\RSalgstxt,\n" + << " Name = \\RSAlgtxt,\n" + << " Names = \\RSAlgstxt,\n" + << " rngtxt = \\RSrngtxt,\n" + << " lsttwotxt = \\RSlsttwotxt,\n" + << " lsttxt = \\RSlsttxt\n" + << " }\n" + << "}{}\n" + << '\n'; + } + if (mustProvide("cleveref:cpagereffix")) { macros << "% Fix for pending cleveref bug: https://tex.stackexchange.com/a/620066/105447\n" << "\\newcommand*{\\@setcpagerefrange}[3]{\\@@setcpagerefrange{#1}{#2}{cref}{#3}}\n" @@ -2356,6 +2374,16 @@ docstring const LaTeXFeatures::getXRefI18nDefs(Layout const & lay) const ods << "\\newrefformat{enu}{_(Item[[enumerate]])~\\ref{#1}}\n"; if (!ods.str().empty()) return ods.str(); + } else if (params_.xref_package == "refstyle" && isRequired("refstyle:algref")) { + docstring const tn = from_ascii("Algorithm"); + docstring const tnp = from_ascii("Algorithms"); + odocstringstream ods; + docstring const prfxname = from_ascii("alg"); + ods << "\\def\\RS" << prfxname << "txt{_(" << lowercase(tn) << ")~}\n" + << "\\def\\RS" << prfxname << "stxt{_(" << lowercase(tnp) << ")~}\n" + << "\\def\\RS" << capitalize(prfxname) << "txt{_(" << tn << ")~}\n" + << "\\def\\RS" << capitalize(prfxname) << "stxt{_(" << tnp << ")~}\n"; + return ods.str(); } else if (params_.xref_package == "refstyle" && isRequired("refstyle:enuref")) { docstring const tn = from_ascii("Item[[enumerate]]"); docstring const tnp = from_ascii("Items[[enumerate]]"); diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 32c47b73d3..a96b7b58da 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -356,7 +356,7 @@ bool InsetRef::isRefStyleSupported(docstring & pr) const return true; // These are additionally supported by LyX - if (pr == "cha" || pr == "enu" || pr == "subsec") + if (pr == "alg" || pr == "cha" || pr == "enu" || pr == "subsec") return true; // Theorems are all supported by LyX @@ -1010,12 +1010,14 @@ void InsetRef::validate(LaTeXFeatures & features) const getFormattedCmd(data, label, prefix, buffer().masterParams().xref_package, use_caps, useRange()); if (buffer().masterParams().xref_package == "refstyle") { features.require("refstyle"); - if (prefix == "cha" || prefix == "Cha") + if (prefix == "alg" || prefix == "Alg") + features.require("refstyle:algref"); + else if (prefix == "cha" || prefix == "Cha") features.require("refstyle:charef"); - else if (prefix == "subsec" || prefix == "Subsec") - features.require("refstyle:subsecref"); else if (prefix == "enu" || prefix == "Enu") features.require("refstyle:enuref"); + else if (prefix == "subsec" || prefix == "Subsec") + features.require("refstyle:subsecref"); else if (!prefix.empty() && !isRefStyleSupported(prefix)) { // fallback command for unsupported prefixes docstring lcmd = "\\AtBeginDocument{\\providecommand" + -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs