From b8c2be883718b331581e2d48ba8e09e8f1d3ad63 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 02:05:40 +0800 Subject: [PATCH] Format numeric bibliography authors with initials --- README.md | 3 +++ docs/STATUS.md | 2 ++ src/rust_typeset.rs | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6927900..336099f 100644 --- a/README.md +++ b/README.md @@ -548,3 +548,6 @@ commands, break advisories, and document metadata; see the sections above. PDF-only figures are rendered as placeholders sized from the source PDF page aspect ratio (until native PDF page embedding lands). + + +Numeric bibliographies render authors as Surname, I. rather than full given names. diff --git a/docs/STATUS.md b/docs/STATUS.md index d24b403..6dcf402 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -153,3 +153,5 @@ See `docs/ROADMAP.md` for concrete implementation plans. - New-template compatibility: the SIVP class file loads fully and `sn-article.tex` previews and exports a 17-page PDF (PDF figures render as placeholders). Its journal title block captures title, author/affiliation, corresponding-author stars, both e-mails, abstract, and keywords; class declaration option leakage is consumed. The Huawei E fragment compiles to 16 A4 pages. Generic support added for TeX `\if`/`\ifx`, `\newcount`, `\newdimen`, `\char`, `tabular*`/`tabularx`, math accents/operators/arrows, a 64-bit dimension scanner, and `geometry` `text={width,height}` blocks. Both fixtures are regression tests (`sivp_project_previews_and_exports_a_pdf`, `e_fixture_compiles`). - Lines whose justification ratio exceeds 3 fall back to natural spacing instead of stretching inter-word gaps across the measure. + +- Numeric bibliographies format author names as Surname, I. for standard journal styles. diff --git a/src/rust_typeset.rs b/src/rust_typeset.rs index bbebc18..0dc0ac5 100644 --- a/src/rust_typeset.rs +++ b/src/rust_typeset.rs @@ -910,6 +910,38 @@ fn source_directory(file_name: &str) -> &Path { .unwrap_or_else(|| Path::new(".")) } +fn numeric_author_list(author: &str) -> String { + author + .split(" and ") + .map(|name| { + let name = name.trim(); + if name.eq_ignore_ascii_case("others") { + return "et al.".to_string(); + } + let (last, given) = match name.split_once(',') { + Some((last, given)) => (last.trim(), given.trim()), + None => { + let mut words = name.split_whitespace().collect::>(); + let last = words.pop().unwrap_or(""); + (last, "") + } + }; + let initials = given + .split_whitespace() + .filter_map(|word| word.chars().find(|ch| ch.is_alphabetic())) + .map(|ch| format!("{ch}.")) + .collect::>() + .join(" "); + if initials.is_empty() { + last.to_string() + } else { + format!("{last}, {initials}") + } + }) + .collect::>() + .join(", ") +} + fn natbib_author_list(author: &str) -> String { let names = author .split(" and ") @@ -944,7 +976,12 @@ impl BibEntry { let mut parts = Vec::new(); let author = field("author"); if !author.is_empty() { - parts.push(format!("{author}.")); + let authors = numeric_author_list(author); + if authors.ends_with('.') { + parts.push(authors); + } else { + parts.push(format!("{authors}.")); + } } else if !field("editor").is_empty() { parts.push(format!("{} (ed.).", field("editor"))); }