Parenthesise eqref for non-equation labels
\eqref on a section, figure or table label rendered the bare number because the section-reference pass shared the \ref replacement. It now wraps the value in parentheses, matching amsmath's equation form; equation labels already took the parenthesised path in the equation pass. A preview test labels a section and checks "See (1)." with no warnings.
This commit is contained in:
1 parent
263fa36fb5
commit
a50023691b
4 files changed
+35
-7
No files matched your search
+29
-1
@@ -12482,7 +12482,9 @@ fn resolve_section_refs(
|
||||
for block in blocks {
|
||||
for (label, value) in labels {
|
||||
block.text = block.text.replace(&format!("\\ref{{{label}}}"), value);
|
||||
block.text = block.text.replace(&format!("\\eqref{{{label}}}"), value);
|
||||
block.text = block
|
||||
.text
|
||||
.replace(&format!("\\eqref{{{label}}}"), &format!("({value})"));
|
||||
let kind = kinds
|
||||
.iter()
|
||||
.find(|(known, _)| known == label)
|
||||
@@ -17511,6 +17513,32 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eqref_wraps_non_equation_labels() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\section{Intro\\label{sec:a}}\n\nSee \\eqref{sec: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!(
|
||||
value["warnings"].as_array().map(Vec::len),
|
||||
Some(0),
|
||||
"{}",
|
||||
value["warnings"]
|
||||
);
|
||||
let pages = value["pages"].as_array().expect("pages");
|
||||
let mut text = String::new();
|
||||
for page in pages {
|
||||
if let Some(svg) = page["svg"].as_str() {
|
||||
text.push_str(
|
||||
&svg.split('>')
|
||||
.filter_map(|piece| piece.split('<').next())
|
||||
.collect::<String>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
let text: String = text.split_whitespace().collect();
|
||||
assert!(text.contains("See(1)."), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_barrier_and_balance_are_consumed() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\nAlpha.\n\n\\FloatBarrier\n\n\\balance\n\nBeta.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user