Accept starred equation tags
\tag* was not parsed: the tag extraction only looked for \tag, so the starred
form stayed in the formula. Both the row pass and the block pass now try
\tag*{...} before \tag{...}, so the tag text is removed from the math and used
as the equation tag.
A preview test tags an equation with \tag*{A} and checks the glyph appears with
no warnings and no leaked command.
This commit is contained in:
1 parent
a5871774ec
commit
3b28ea6693
4 files changed
+38
-8
No files matched your search
+32
-2
@@ -7893,7 +7893,9 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
}
|
||||
if !block.equation_rows.is_empty() {
|
||||
for row in block.equation_rows.iter_mut() {
|
||||
if let Some(tag) = take_braced_argument(&mut row.text, "\\tag") {
|
||||
let tag = take_braced_argument(&mut row.text, "\\tag*")
|
||||
.or_else(|| take_braced_argument(&mut row.text, "\\tag"));
|
||||
if let Some(tag) = tag {
|
||||
row.tag = Some(tag);
|
||||
row.number = None;
|
||||
}
|
||||
@@ -7915,7 +7917,9 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(tag) = take_braced_argument(&mut block.text, "\\tag") {
|
||||
let tag = take_braced_argument(&mut block.text, "\\tag*")
|
||||
.or_else(|| take_braced_argument(&mut block.text, "\\tag"));
|
||||
if let Some(tag) = tag {
|
||||
block.equation_tag = Some(tag);
|
||||
block.equation_number = None;
|
||||
}
|
||||
@@ -17201,6 +17205,32 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starred_tags_keep_their_text() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{equation}\nx = 1 \\tag*{A}\n\\end{equation}\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>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(text.contains('A'), "{text}");
|
||||
assert!(!json.contains("tag"), "{json}");
|
||||
}
|
||||
|
||||
#[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";
|
||||
|
||||
Reference in new issue
Block a user