From 7c4edbb1f1a73f7f35422c4da406f20655497833 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 19 Oct 2026 18:57:57 +0800 Subject: [PATCH] Cover preprint metadata spacing --- docs/STATUS.md | 2 +- tests/typeset.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/STATUS.md b/docs/STATUS.md index 8f3dcc7..32050e6 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -119,7 +119,7 @@ See `docs/ROADMAP.md` for concrete implementation plans. - ASCII-only documents use non-embedded Base-14 Times/Courier (arXiv PDF is about 0.7 MB); documents with accented/non-WinAnsi text embed Liberation faces. Tables use natural column widths and centered rules. -- `cargo fmt --check` passes; `cargo test --offline` (51 tests: 47 compiler +- `cargo fmt --check` passes; `cargo test --offline` (52 tests: 48 compiler integration tests + 4 server tests) covers the three examples, the arXiv fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output, project API, static frontend assets, path traversal, the legacy diff --git a/tests/typeset.rs b/tests/typeset.rs index d0942e6..112eeee 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -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("().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}"); let index = svg