Cover preprint metadata spacing

This commit is contained in:
gloamxun committed 2026-10-19 18:57:57 +08:00
1 parent 6f71414d69
commit 7c4edbb1f1
2 files changed
+42 -1

No files matched your search

+41
View File
@@ -507,6 +507,47 @@ fn small_caps_uses_reduced_uppercase_glyphs() {
);
}
#[test]
fn preprint_metadata_spacing_matches_reference() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures")
.join("arxiv-template")
.join("template.tex");
let source = std::fs::read_to_string(&path).expect("read arXiv fixture");
let value = fresh_preview(&source, &path.to_string_lossy());
assert_eq!(value["status"], "ok", "{}", value["message"]);
let svg = page_svg(&value, 0);
let title = text_y(&svg, "STYLE");
let author = text_y_contains(&svg, "Hippocampus");
let date = text_y(&svg, "October");
// Measured against the XeLaTeX reference PDF (1 pt = 0.3528 mm).
assert!(
(author - title - 25.1).abs() < 1.0,
"title-to-author gap: {}",
author - title
);
assert!(
(date - author - 29.4).abs() < 1.0,
"author-to-date gap: {}",
date - author
);
}
fn text_y_contains(svg: &str, needle: &str) -> f64 {
let index = svg
.find(needle)
.unwrap_or_else(|| panic!("missing text element containing `{needle}`"));
let start = svg[..index]
.rfind("<text ")
.unwrap_or_else(|| panic!("no text element before `{needle}`"));
let tag = &svg[start..index];
tag.split("y=\"")
.nth(1)
.and_then(|rest| rest.split('\"').next())
.and_then(|value| value.parse::<f64>().ok())
.unwrap_or_else(|| panic!("text element for `{needle}` has no y coordinate"))
}
fn text_y(svg: &str, needle: &str) -> f64 {
let closing = format!("{needle}</text>");
let index = svg