Resolve cref on equation labels
cleveref on an equation label still leaked: equation labels are resolved before
the section reference pass, so \cref/\Cref never saw them. The equation pass now
also rewrites both forms to "Equation <n>" in blocks and equation rows, matching
the existing \autoref handling.
The equation autoref test now also renders \cref{eq:a} and expects both
references.
This commit is contained in:
1 parent
a451df620c
commit
58c35c85b9
2 files changed
+11
-5
No files matched your search
+10
-4
@@ -8064,17 +8064,23 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
let eqref = format!("\\eqref{{{label}}}");
|
||||
let reference = format!("\\ref{{{label}}}");
|
||||
let autoref = format!("\\autoref{{{label}}}");
|
||||
let cref = format!("\\cref{{{label}}}");
|
||||
let cref_upper = format!("\\Cref{{{label}}}");
|
||||
block.text = block
|
||||
.text
|
||||
.replace(&eqref, &format!("({value})"))
|
||||
.replace(&reference, value)
|
||||
.replace(&autoref, &format!("Equation {value}"));
|
||||
.replace(&autoref, &format!("Equation {value}"))
|
||||
.replace(&cref, &format!("Equation {value}"))
|
||||
.replace(&cref_upper, &format!("Equation {value}"));
|
||||
for row in block.equation_rows.iter_mut() {
|
||||
row.text = row
|
||||
.text
|
||||
.replace(&eqref, &format!("({value})"))
|
||||
.replace(&reference, value)
|
||||
.replace(&autoref, &format!("Equation {value}"));
|
||||
.replace(&autoref, &format!("Equation {value}"))
|
||||
.replace(&cref, &format!("Equation {value}"))
|
||||
.replace(&cref_upper, &format!("Equation {value}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17527,7 +17533,7 @@ A definition.
|
||||
|
||||
#[test]
|
||||
fn autoref_resolves_equation_labels() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{equation}\nx = 1 \\label{eq:a}\n\\end{equation}\n\nSee \\autoref{eq:a}.\n\n\\end{document}\n";
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{equation}\nx = 1 \\label{eq:a}\n\\end{equation}\n\nSee \\autoref{eq:a} and \\cref{eq:a}.\n\n\\end{document}\n";
|
||||
let json = preview_json(source).expect("preview");
|
||||
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
|
||||
assert_eq!(
|
||||
@@ -17548,7 +17554,7 @@ A definition.
|
||||
}
|
||||
}
|
||||
let text: String = text.split_whitespace().collect();
|
||||
assert!(text.contains("SeeEquation1."), "{text}");
|
||||
assert!(text.contains("SeeEquation1andEquation1."), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user