Add an equation tag and script regression test
Cover the arXiv equation through the preview SVG: no literal underscore/caret text items may remain, and the equation number must sit near the right margin. This locks the script-attachment and TaggedWidth fixes. Test count is 1079.
This commit is contained in:
1 parent
8f231d5752
commit
68ec9941dc
5 files changed
+59
-6
No files matched your search
@@ -19863,6 +19863,59 @@ left & right \\
|
||||
assert_eq!(author_orcid_marker(r"\orcidlink{0000-0002} Ada"), "iD Ada");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arxiv_equation_tag_sits_at_the_right_margin() {
|
||||
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let template = std::fs::read_to_string(root.join("fixtures/arxiv-template/template.tex"))
|
||||
.expect("template");
|
||||
let sty =
|
||||
std::fs::read_to_string(root.join("fixtures/arxiv-template/arxiv.sty")).expect("sty");
|
||||
let assembled = template.replace("\\usepackage{arxiv}", &sty);
|
||||
let json = preview_json(&assembled).expect("preview");
|
||||
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
|
||||
assert_eq!(value["status"], "ok");
|
||||
let mut tag_x = None;
|
||||
let mut literal_script = false;
|
||||
for page in value["pages"].as_array().expect("pages") {
|
||||
let Some(svg) = page["svg"].as_str() else {
|
||||
continue;
|
||||
};
|
||||
for fragment in svg.split("<text ").skip(1) {
|
||||
let Some(tag) = fragment.split('>').next() else {
|
||||
continue;
|
||||
};
|
||||
let Some(text) = fragment.split('>').nth(1) else {
|
||||
continue;
|
||||
};
|
||||
let Some(text) = text.split("</text>").next() else {
|
||||
continue;
|
||||
};
|
||||
let x = tag
|
||||
.split("x=\"")
|
||||
.nth(1)
|
||||
.and_then(|rest| rest.split('"').next())
|
||||
.and_then(|value| value.parse::<f64>().ok());
|
||||
let y = tag
|
||||
.split("y=\"")
|
||||
.nth(1)
|
||||
.and_then(|rest| rest.split('"').next())
|
||||
.and_then(|value| value.parse::<f64>().ok());
|
||||
if let (Some(x), Some(y)) = (x, y)
|
||||
&& (200.0..260.0).contains(&y)
|
||||
&& x > 500.0
|
||||
{
|
||||
tag_x = Some(x);
|
||||
}
|
||||
if text == "_" || text == "^" {
|
||||
literal_script = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(!literal_script, "literal script marker in SVG");
|
||||
let tag_x = tag_x.expect("equation tag in SVG");
|
||||
assert!(tag_x > 500.0, "equation tag x={tag_x}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arxiv_template_previews_without_warnings() {
|
||||
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
Reference in new issue
Block a user