Parenthesise tag text like LaTeX
\tag{B} stored the bare text and the renderer painted "B", while LaTeX draws
"(B)"; \tag* is the bare form. Tag extraction now wraps the non-starred argument
in parentheses and leaves the starred form alone, for both equation rows and
whole equations.
The existing tag tests expect "(B)"/"(C)", and a new preview test checks the
parentheses glyphs around "A" with no warnings.
This commit is contained in:
1 parent
3b28ea6693
commit
c3aa4e9dad
4 files changed
+34
-12
No files matched your search
+28
-6
@@ -7893,8 +7893,12 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
}
|
||||
if !block.equation_rows.is_empty() {
|
||||
for row in block.equation_rows.iter_mut() {
|
||||
let tag = take_braced_argument(&mut row.text, "\\tag*")
|
||||
.or_else(|| take_braced_argument(&mut row.text, "\\tag"));
|
||||
let tag = match take_braced_argument(&mut row.text, "\\tag*") {
|
||||
Some(tag) => Some(tag),
|
||||
None => {
|
||||
take_braced_argument(&mut row.text, "\\tag").map(|tag| format!("({tag})"))
|
||||
}
|
||||
};
|
||||
if let Some(tag) = tag {
|
||||
row.tag = Some(tag);
|
||||
row.number = None;
|
||||
@@ -7917,8 +7921,10 @@ fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let tag = take_braced_argument(&mut block.text, "\\tag*")
|
||||
.or_else(|| take_braced_argument(&mut block.text, "\\tag"));
|
||||
let tag = match take_braced_argument(&mut block.text, "\\tag*") {
|
||||
Some(tag) => Some(tag),
|
||||
None => take_braced_argument(&mut block.text, "\\tag").map(|tag| format!("({tag})")),
|
||||
};
|
||||
if let Some(tag) = tag {
|
||||
block.equation_tag = Some(tag);
|
||||
block.equation_number = None;
|
||||
@@ -17205,6 +17211,22 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tagged_equations_add_parentheses() {
|
||||
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"]
|
||||
);
|
||||
assert!(json.contains(">(</text>"), "{json}");
|
||||
assert!(json.contains(">A</text>"), "{json}");
|
||||
assert!(json.contains(">)</text>"), "{json}");
|
||||
}
|
||||
|
||||
#[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";
|
||||
@@ -20149,7 +20171,7 @@ d
|
||||
tags,
|
||||
vec![
|
||||
(Some(1), None),
|
||||
(None, Some("B".to_string())),
|
||||
(None, Some("(B)".to_string())),
|
||||
(None, None),
|
||||
(Some(2), None)
|
||||
]
|
||||
@@ -20176,7 +20198,7 @@ g &= h
|
||||
assert_eq!(rows.len(), 4);
|
||||
let numbers: Vec<Option<u32>> = rows.iter().map(|row| row.number).collect();
|
||||
assert_eq!(numbers, vec![Some(1), None, None, Some(2)]);
|
||||
assert_eq!(rows[1].tag.as_deref(), Some("C"));
|
||||
assert_eq!(rows[1].tag.as_deref(), Some("(C)"));
|
||||
assert!(rows[0].text.contains('&'), "cells keep their separator");
|
||||
assert!(
|
||||
rows.iter()
|
||||
|
||||
Reference in new issue
Block a user