commit 8e80ffd684a26752c0d754d27f63977ebae733b2
Author: Juergen Spitzmueller <[email protected]>
Date: Mon Apr 28 10:53:08 2025 +0200
Support \[z]cpageref in InsetMathRef
---
lib/lyx2lyx/lyx_2_5.py | 23 +++++++++++++++++++++++
src/mathed/InsetMathRef.cpp | 18 ++++++++++++++++++
src/mathed/MathParser.cpp | 2 +-
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 3d9a54e6fa..f5b64e9761 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -2835,6 +2835,29 @@ def revert_reflists(document):
document.body[i : j + 1] = put_cmd_in_ert([cmd])
i += 1
+ # check math refs
+ if package == "zref" or package == "cleveref":
+ regexp = re.compile(r".*(\\cpageref{).*")
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset Formula", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i)
+ if j == -1:
+ document.warning("Can't find end of inset at line %d of body!"
% i)
+ i += 1
+ continue
+ k = find_re(document.body, regexp, i, j)
+ if k != -1:
+ if package == "zref":
+ need_zref_clever = True
+ document.body[k] = document.body[k].replace("\\cpageref",
"\\zcpageref")
+ else:
+ need_cleveref = True
+ break
+ i = j
+
# preamble
if need_zref_clever:
add_to_preamble(
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index c9fa1004e6..7ae5c8f858 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -225,6 +225,11 @@ void InsetMathRef::validate(LaTeXFeatures & features) const
features.require("zref-clever");
else
features.require("prettyref");
+ } else if (commandname() == "cpageref") {
+ if (buffer_ && buffer().masterParams().xref_package ==
"cleveref")
+ features.require("cleveref");
+ else if (buffer_ && buffer().masterParams().xref_package ==
"zref")
+ features.require("zref-clever");
}
// if eqref is used with refstyle, we do our own output
else if (commandname() == "eqref" && use_refstyle)
@@ -313,6 +318,7 @@ void InsetMathRef::write(TeXMathStream & os) const
bool special_case = cmd == "formatted" ||
cmd == "vref" ||
cmd == "vpageref" ||
+ cmd == "cpageref" ||
cmd == "labelonly" ||
(cmd == "eqref" && use_refstyle);
// we need to translate 'formatted' to prettyref or refstyle-type
@@ -330,6 +336,17 @@ void InsetMathRef::write(TeXMathStream & os) const
os << "z";
os << cmd << "{" << cell(0) << from_ascii("}");
}
+ else if (cmd == "cpageref") {
+ os << from_ascii("\\");
+ if (buffer_ && buffer().params().xref_package == "zref")
+ os << "z";
+ if (buffer_ && (buffer().params().xref_package == "cleveref"
+ || buffer().params().xref_package == "zref"))
+ os << cmd;
+ else
+ os << "pageref";
+ os << "{" << cell(0) << from_ascii("}");
+ }
else if (use_refstyle && cmd == "eqref") {
// we advertise this as printing "(n)", so we'll do that, at
least
// for refstyle, since refstlye's own \eqref prints, by default,
@@ -404,6 +421,7 @@ InsetMathRef::ref_type_info InsetMathRef::types[] = {
{ from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")),
from_ascii(N_("Ref: "))},
{ from_ascii("eqref"), from_ascii(N_("Equation")),
from_ascii(N_("EqRef: "))},
{ from_ascii("pageref"), from_ascii(N_("Page Number")),
from_ascii(N_("Page: "))},
+ { from_ascii("cpageref"), from_ascii(N_("Prefixed Page Number")),
from_ascii(N_("PrefPage: "))},
{ from_ascii("vpageref"), from_ascii(N_("Textual Page Number")),
from_ascii(N_("TextPage: "))},
{ from_ascii("vref"), from_ascii(N_("Standard+Textual Page")),
from_ascii(N_("Ref+Text: "))},
{ from_ascii("formatted"), from_ascii(N_("PrettyRef")),
from_ascii(N_("FormatRef: "))},
diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index c546b0a9d3..98d3839c11 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -1548,7 +1548,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
}
else if (t.cs() == "ref" || t.cs() == "eqref" || t.cs() ==
"prettyref"
- || t.cs() == "nameref" || t.cs() == "pageref"
+ || t.cs() == "nameref" || t.cs() == "pageref" ||
t.cs() == "cpageref"
|| t.cs() == "vpageref" || t.cs() == "vref"
|| t.cs() == "formatted" || t.cs() == "labelonly") {
cell->push_back(MathAtom(new InsetMathRef(buf,
t.cs())));
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs