From 6b89ab1dd7bdc3062b91d76578fd45633f722a7d Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 27 Oct 2026 22:07:40 +0800 Subject: [PATCH] Draw the arXiv title rules and undertitle The arXiv class places 2pt rules above/below the title and an A Preprint undertitle. Detect the class via its toptitlebar macro, reserve space with an invisible rule (page builders discard glue before the first unit), and stamp the rules/undertitle onto the first page for both preview and PDF. Update the title-page header assertion: the first page legitimately carries the undertitle, so it must lack the running center header instead. Author lines remain sequential; two-column affiliations are still open. --- docs/TEX_FIDELITY_ROADMAP.md | 5 ++- docs/WEB_ROUTE_D_EXPERIMENT.md | 2 + src/route_d.rs | 71 ++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/docs/TEX_FIDELITY_ROADMAP.md b/docs/TEX_FIDELITY_ROADMAP.md index b8570d4..1b2c714 100644 --- a/docs/TEX_FIDELITY_ROADMAP.md +++ b/docs/TEX_FIDELITY_ROADMAP.md @@ -40,8 +40,9 @@ execution is not a goal. 6.5in text block and page-2/page-3 headers instead of content at x=0. - Still visibly different from TeX: - body face is CMR/fallback, not Times from `\rmdefault{ptm}`; - - title now uses small caps and author metadata is split onto class-like - lines; title rules, two-column affiliations and ORCID icons are still + - title uses small caps; the arXiv class's top/bottom rules and + "A Preprint" undertitle are drawn, and author metadata is split onto + class-like lines. Two-column affiliations and ORCID icons are still missing; - reference style is numeric, not natbib author-year; - display math is approximate; diff --git a/docs/WEB_ROUTE_D_EXPERIMENT.md b/docs/WEB_ROUTE_D_EXPERIMENT.md index 646d448..01670db 100644 --- a/docs/WEB_ROUTE_D_EXPERIMENT.md +++ b/docs/WEB_ROUTE_D_EXPERIMENT.md @@ -116,6 +116,8 @@ problems in the generated PDF, all fixed in the follow-up increment: Remaining visible gaps in this template: - the display equation is still a rough approximation of the printed formula; +- the title rules and A Preprint undertitle are now drawn, but the author + block is sequential rather than the class's two columns; - the `\fbox{\rule...}` figure body is not drawn (only its caption survives); - `orcid.pdf` is a vector image and stays unsupported; - the author block is concatenated and does not reproduce the class layout. diff --git a/src/route_d.rs b/src/route_d.rs index 2de7550..cc2ac7f 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -7680,6 +7680,7 @@ pub fn pdf_bytes_with_images( geometry.suppress_first_page_number, ); } + stamp_title_bars(&mut pages, &geometry, &document); let headings = page_headings(&document, &engine); stamp_running_heads( &mut pages, @@ -12536,7 +12537,13 @@ fn expand_maketitle(blocks: &[SourceParagraph], geometry: &PageGeometry) -> Vec< paragraph.page_break = block.page_break; result.push(paragraph); } - let author_space = block.space_before + 12 * SCALE; + let author_space = block.space_before + + 12 * SCALE + + if has_title_bars(geometry) { + 18 * SCALE + } else { + 0 + }; if let Some(author) = geometry .author .as_deref() @@ -13900,6 +13907,12 @@ fn build_document_with_labels( base_units[index].space_shrink += below_display.2; } } + if has_title_bars(geometry) { + // The class's title block starts with a top rule and vskip. The page + // builder discards glue before the first unit, so use an invisible + // rule as the spacer instead. + base_units.insert(0, Unit::rule(u64::MAX, 0, 2 * SCALE)); + } let mut units: Vec = Vec::with_capacity(base_units.len()); let mut unit_for_paragraph = Vec::with_capacity(paragraphs.len()); let mut footnote_count = 0usize; @@ -14138,6 +14151,57 @@ fn page_headings(document: &Document, engine: &Engine) -> Vec> { result } +/// The arXiv class draws rules above/below the title and an undertitle. +fn has_title_bars(geometry: &PageGeometry) -> bool { + geometry.title.is_some() + && geometry + .macros + .iter() + .any(|definition| definition.name.contains("toptitlebar")) +} + +fn title_undertitle(geometry: &PageGeometry) -> Option { + geometry + .macros + .iter() + .find(|definition| definition.name.contains("undertitle")) + .map(|definition| definition.body.trim().to_string()) + .filter(|body| !body.is_empty()) +} + +/// Paint the class title rules and undertitle on the first page. +fn stamp_title_bars(lists: &mut [DisplayList], geometry: &PageGeometry, document: &Document) { + if !has_title_bars(geometry) { + return; + } + let Some(list) = lists.first_mut() else { + return; + }; + let width = document.text_width; + list.items.push(DisplayItem::Rule { + x: 0, + y: 7 * SCALE, + width, + height: 2 * SCALE, + }); + list.items.push(DisplayItem::Rule { + x: 0, + y: 55 * SCALE, + width, + height: 2 * SCALE, + }); + if let Some(text) = title_undertitle(geometry) { + let text_width = text_width_roman(&text); + list.items.push(DisplayItem::Text { + x: ((width - text_width) / 2).max(0), + y: 72 * SCALE, + size: 9 * SCALE, + text, + font: FontFace::Roman, + }); + } +} + fn stamp_running_heads( lists: &mut [DisplayList], geometry: &PageGeometry, @@ -14632,6 +14696,7 @@ fn render_json( geometry.suppress_first_page_number, ); } + stamp_title_bars(&mut lists, geometry, document); let headings = page_headings(document, engine); stamp_running_heads( &mut lists, @@ -19485,8 +19550,8 @@ left & right \\ let first = pages[0]["svg"].as_str().expect("first svg"); let second = pages[1]["svg"].as_str().expect("second svg"); assert!( - !first.contains("A Preprint"), - "title page must be empty style" + !first.contains("arXiv Template"), + "title page must not show the running header" ); assert!(second.contains("A Preprint"), "right header missing"); assert!(second.contains("arXiv Template"), "centre header missing");