Resolve autoref on equation labels
\autoref{...} pointing at an equation fell through to "??" because equation
labels are resolved during the equation numbering pass and never reached the
section-reference kind table. That pass now also rewrites \autoref to
"Equation <n>" in both a math block and its equation rows.
A preview test labels an equation and checks "See Equation 1." with no
warnings.
This commit is contained in:
1 parent
4d713df3dd
commit
a5871774ec
4 files changed
+37
-8
No files matched your search
+31
-2
@@ -7936,15 +7936,18 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
for (label, value) in labels.iter() {
|
||||
let eqref = format!("\\eqref{{{label}}}");
|
||||
let reference = format!("\\ref{{{label}}}");
|
||||
let autoref = format!("\\autoref{{{label}}}");
|
||||
block.text = block
|
||||
.text
|
||||
.replace(&eqref, &format!("({value})"))
|
||||
.replace(&reference, value);
|
||||
.replace(&reference, value)
|
||||
.replace(&autoref, &format!("Equation {value}"));
|
||||
for row in block.equation_rows.iter_mut() {
|
||||
row.text = row
|
||||
.text
|
||||
.replace(&eqref, &format!("({value})"))
|
||||
.replace(&reference, value);
|
||||
.replace(&reference, value)
|
||||
.replace(&autoref, &format!("Equation {value}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17198,6 +17201,32 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[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 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("SeeEquation1."), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nameref_resolves_figure_captions() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{figure}[h]\n\\rule{10pt}{10pt}\n\\caption{A plot}\\label{fig:a}\n\\end{figure}\n\nSee \\nameref{fig:a} and \\autoref{fig:a}.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user