Format numeric bibliography authors with initials

This commit is contained in:
gloamxun committed 2026-10-20 02:05:40 +08:00
1 parent 261f0ea278
commit b8c2be8837
3 files changed
+43 -1

No files matched your search

+3
View File
@@ -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.
+2
View File
@@ -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.
+38 -1
View File
@@ -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::<Vec<_>>();
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::<Vec<_>>()
.join(" ");
if initials.is_empty() {
last.to_string()
} else {
format!("{last}, {initials}")
}
})
.collect::<Vec<_>>()
.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")));
}