From 06cc88809e6f9232a63134b212a7390b3b287083 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 01:15:02 +0800 Subject: [PATCH] Capture corresponding authors and class metadata cleanly --- crates/texrra-core/src/document.rs | 2 ++ crates/texrra-core/src/document_parser.rs | 13 ++++++++++++- crates/texrra-core/src/expanded.rs | 1 + src/rust_typeset/pdf/layout.rs | 18 ++++++++++++++---- src/rust_typeset/texlang_adapter.rs | 14 +++++++++++--- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/texrra-core/src/document.rs b/crates/texrra-core/src/document.rs index fefa999..00f00e0 100644 --- a/crates/texrra-core/src/document.rs +++ b/crates/texrra-core/src/document.rs @@ -75,6 +75,8 @@ pub struct AuthorBlock { /// One-based affiliation indices attached to this author. pub affiliations: Vec, pub email: Option, + /// Author marked with `*` (corresponding author). + pub corresponding: bool, } /// One numbered affiliation in a structured front matter. diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index 64c4d91..1a952c7 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -480,6 +480,7 @@ struct Parser { metadata_capture: Option<(expanded::MetadataField, Vec)>, author_affiliations: Vec, pending_author_email: Option, + pending_author_corresponding: bool, email_capture: Option>, affiliation_capture: Option<(usize, Vec)>, abstract_capture: Option>, @@ -598,6 +599,7 @@ impl Parser { metadata_capture: None, author_affiliations: Vec::new(), pending_author_email: None, + pending_author_corresponding: false, email_capture: None, affiliation_capture: None, abstract_capture: None, @@ -803,10 +805,12 @@ impl Parser { self.document.author = value; let affiliations = std::mem::take(&mut self.author_affiliations); let email = self.pending_author_email.take(); + let corresponding = std::mem::take(&mut self.pending_author_corresponding); self.document.authors.push(crate::document::AuthorBlock { runs, affiliations, email, + corresponding, }); } expanded::MetadataField::Date => self.document.date = value, @@ -1063,11 +1067,18 @@ impl Parser { expanded::FrontendEventKind::MetadataEmailStart => { self.email_capture = Some(Vec::new()); } + expanded::FrontendEventKind::MetadataAuthorCorresponding => { + self.pending_author_corresponding = true; + } expanded::FrontendEventKind::MetadataEmailEnd => { if let Some(mut runs) = self.email_capture.take() { trim_run_end(&mut runs); let email = runs.iter().map(|run| run.text.as_str()).collect::(); - self.pending_author_email = Some(email); + if let Some(author) = self.document.authors.last_mut() { + author.email = Some(email); + } else { + self.pending_author_email = Some(email); + } } } expanded::FrontendEventKind::AffiliationStart(index) => { diff --git a/crates/texrra-core/src/expanded.rs b/crates/texrra-core/src/expanded.rs index f8f1a97..0cbf0fa 100644 --- a/crates/texrra-core/src/expanded.rs +++ b/crates/texrra-core/src/expanded.rs @@ -292,6 +292,7 @@ pub enum FrontendEventKind { KeywordsEnd, /// Start/end of the e-mail address inside an author block. MetadataEmailStart, + MetadataAuthorCorresponding, MetadataEmailEnd, ParagraphAlignment(crate::document::ParagraphAlignment), TableOfContents, diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index 75e6ff9..feb4ce6 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -1857,12 +1857,15 @@ pub(super) fn build_positioned_pages( let mut author_emails = Vec::new(); for author in &model.authors { let mut runs = author.runs.clone(); - if !author.affiliations.is_empty() { - let marks = author + if !author.affiliations.is_empty() || author.corresponding { + let mut marks = author .affiliations .iter() .map(|index| superscript(*index)) .collect::(); + if author.corresponding { + marks.push('*'); + } runs.push(Run::plain(marks)); } for line in measure_positioned_lines( @@ -1928,8 +1931,15 @@ pub(super) fn build_positioned_pages( } if !author_emails.is_empty() { - let email_runs = - vec![Run::plain(format!("E-mail: {}", author_emails.join("; ")))]; + let corresponding = model.authors.iter().any(|author| author.corresponding); + let email_runs = vec![Run::plain(if corresponding { + format!( + "*Corresponding author(s). E-mail(s): {}", + author_emails.join("; ") + ) + } else { + format!("E-mail: {}", author_emails.join("; ")) + })]; for line in measure_positioned_lines( &email_runs, base_font_size.saturating_sub(1).max(1), diff --git a/src/rust_typeset/texlang_adapter.rs b/src/rust_typeset/texlang_adapter.rs index c94a538..455d60c 100644 --- a/src/rust_typeset/texlang_adapter.rs +++ b/src/rust_typeset/texlang_adapter.rs @@ -2224,7 +2224,9 @@ fn author_frontmatter_primitive( input: &mut vm::ExecutionInput, ) -> texlang::prelude::Result<()> { if let Some(next) = input.unexpanded().next()? { - if !matches!(next.value(), token::Value::Other('*')) { + if matches!(next.value(), token::Value::Other('*')) { + write_event(input, token, FrontendEventKind::MetadataAuthorCorresponding); + } else { input.unexpanded().back(next); } } @@ -2250,8 +2252,14 @@ fn author_frontmatter_primitive( fn skip_optional_bracket( input: &mut vm::ExecutionInput, ) -> texlang::prelude::Result<()> { - let Some(first) = input.unexpanded().next()? else { - return Ok(()); + let first = loop { + let Some(next) = input.unexpanded().next()? else { + return Ok(()); + }; + if matches!(next.value(), token::Value::Space(_)) { + continue; + } + break next; }; if !matches!(first.value(), token::Value::Other('[')) { input.unexpanded().back(first);