From 1da9e0dde972b556e6dfa2e42323c3dafd396643 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 19 Oct 2026 17:12:23 +0800 Subject: [PATCH] Preserve inline emphasis in preprint title runs --- README.md | 3 ++- crates/texrra-core/src/document.rs | 3 +++ crates/texrra-core/src/document_parser.rs | 7 +++++-- src/rust_typeset/pdf/layout.rs | 16 ++++++++++++---- tests/typeset.rs | 4 ++++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f9a79b3..e9a5bd3 100644 --- a/README.md +++ b/README.md @@ -323,7 +323,8 @@ boxes, footnotes, and the default paragraph indent. The article default is `10pt`, matching LaTeX. A document-level `\renewcommand{\maketitle}` replaces the engine title block. When a document loads `arxiv.sty`, the engine switches to a native preprint -title style: top/bottom title rules, small-caps title and `\undertitle`, +title style: top/bottom title rules, small-caps title with inline emphasis +preserved (e.g. the italic `arxiv` in the class example), `\undertitle`, two-column author blocks with affiliations and monospaced e-mail addresses, a long date, and `\thispagestyle{empty}` on the first page. Class and package files that replace `\maketitle` itself are still ignored, so box-level diff --git a/crates/texrra-core/src/document.rs b/crates/texrra-core/src/document.rs index ae7c9b1..35282c5 100644 --- a/crates/texrra-core/src/document.rs +++ b/crates/texrra-core/src/document.rs @@ -80,6 +80,8 @@ pub struct Footnote { #[derive(Clone)] pub struct DocumentModel { pub title: String, + /// Rich title runs, preserving inline emphases such as . + pub title_runs: Vec, pub author: String, pub date: String, /// Style selected by the document's class/package layer. @@ -107,6 +109,7 @@ impl Default for DocumentModel { fn default() -> Self { Self { title: String::new(), + title_runs: Vec::new(), author: String::new(), date: String::new(), title_style: TitleStyle::default(), diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index 3d397f0..f67b5a5 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -725,9 +725,12 @@ impl Parser { self.metadata_capture = Some((active_field, runs)); return; } - let value = runs.into_iter().map(|run| run.text).collect::(); + let value = runs.iter().map(|run| run.text.clone()).collect::(); match field { - expanded::MetadataField::Title => self.document.title = value, + expanded::MetadataField::Title => { + self.document.title = value; + self.document.title_runs = runs; + } expanded::MetadataField::Author => self.document.author = value, expanded::MetadataField::Date => self.document.date = value, } diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index 2c4079e..7a8f1ce 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -1531,9 +1531,17 @@ pub(super) fn build_positioned_pages( TitleStyle::Preprint => { let rule_width = millimeters_to_scaled(content_width_mm); let rule_height = i64::from(scaled_points(2.0).0).max(1); - let mut title_run = Run::plain(model.title.clone()); - title_run.bold = true; - title_run.small_caps = true; + let mut title_runs = if model.title_runs.is_empty() { + vec![Run::plain(model.title.clone())] + } else { + model.title_runs.clone() + }; + for run in &mut title_runs { + run.bold = true; + if !run.italic { + run.small_caps = true; + } + } push_title_rule( &mut pages, &mut deferred, @@ -1547,7 +1555,7 @@ pub(super) fn build_positioned_pages( ); cursor = cursor.saturating_add(millimeters_to_scaled(6.35)); for line in measure_positioned_lines( - &[title_run], + &title_runs, base_font_size + 7, content_width_mm, metrics, diff --git a/tests/typeset.rs b/tests/typeset.rs index 360a241..f62c4b5 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -116,6 +116,10 @@ fn arxiv_title_block_uses_rules_and_small_caps() { first_page.contains("font-size=\"4.9389\""), "small-caps title glyphs missing" ); + assert!( + first_page.contains("font-style=\"italic\">arxiv"), + "italic emph{{arxiv}} title run missing" + ); } #[test]