From d9befd4d87161ccec5fbe64287514f2c7b4182d5 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 19 Oct 2026 19:01:12 +0800 Subject: [PATCH] Render ORCID author links as green badges --- docs/STATUS.md | 9 +++++---- src/rust_typeset/frontend.rs | 3 ++- src/rust_typeset/pdf/layout.rs | 24 ++++++++++++++++++------ src/rust_typeset/texlang_adapter.rs | 12 +++++++++--- tests/typeset.rs | 4 ++++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/STATUS.md b/docs/STATUS.md index 32050e6..49923a5 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -107,10 +107,11 @@ See `docs/ROADMAP.md` for concrete implementation plans. the next page. - Contents: chapter headings are listed with chapter-prefixed section numbers, but contents are not split per chapter. -- Preprint title blocks: ORCID icons embedded in `\author` are dropped because - metadata does not carry images. Hyperlinks use hyperref's green text colour; - PDF link annotations are not emitted. Title-block vertical spacing is tighter - than the reference class. +- Preprint title blocks: ORCID links in `\author` render as a green `iD` + badge before the author name; the bitmap ORCID icon itself is not embedded. + Hyperlinks use hyperref's green text colour; PDF link annotations are not + emitted. Metadata baselines match the reference within 0.3 pt, but page 1 + can lose one body line compared with the reference. ## Verification diff --git a/src/rust_typeset/frontend.rs b/src/rust_typeset/frontend.rs index 08fe0d4..db3216d 100644 --- a/src/rust_typeset/frontend.rs +++ b/src/rust_typeset/frontend.rs @@ -74,7 +74,8 @@ const PRELUDE: &str = r#" \def\nocite#1{} \def\newblock{ } \def\caption#1{\texrracaptionstart#1\texrracaptionend} -\def\href#1#2{\texrrahref{#2}} +\def\href#1#2{\texrrahref{#1}{#2}} +\def\texrraorcibadge{iD\ } \def\hline{\texrratablerule} \def\toprule{\texrratablerule} \def\midrule{\texrratablerule} diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index ea41cbf..811b697 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -1901,15 +1901,27 @@ pub(super) fn build_positioned_pages( for lines in &blocks { let mut measured_lines = Vec::with_capacity(lines.len()); for (index, text) in lines.iter().enumerate() { - let mut run = Run::plain(text.clone()); - if index == 0 { - run.bold = true; + let mut runs = Vec::new(); + let mut rest = text.as_str(); + if let Some(after_badge) = text.strip_prefix("iD ") { + let mut badge = Run::plain("iD ".to_string()); + badge.bold = true; + badge.link = true; + runs.push(badge); + rest = after_badge; } - if text.contains('@') && !text.contains(' ') { - run.monospace = true; + if !rest.is_empty() { + let mut run = Run::plain(rest.to_string()); + if index == 0 { + run.bold = true; + } + if rest.contains('@') && !rest.contains(' ') { + run.monospace = true; + } + runs.push(run); } if let Some(line) = measure_positioned_lines( - &[run], + &runs, base_font_size, column_width - 2.0, metrics, diff --git a/src/rust_typeset/texlang_adapter.rs b/src/rust_typeset/texlang_adapter.rs index f6f3e3c..3e9f83b 100644 --- a/src/rust_typeset/texlang_adapter.rs +++ b/src/rust_typeset/texlang_adapter.rs @@ -3661,13 +3661,19 @@ fn href_primitive( token: token::Token, input: &mut vm::ExecutionInput, ) -> texlang::prelude::Result<()> { - // The prelude macro consumes the URL argument; this primitive only sees the - // visible link text, which is wrapped in a link span for hyperref colour. + let url = read_unexpanded_argument(input, token, "expects a link URL")?; let content = read_unexpanded_argument(input, token, "expects link text")?; let inner = strip_braced_tokens(&content).to_vec(); write_event(input, token, FrontendEventKind::LinkStart); let trace_key = token.trace_key(); - let mut expansion = inner; + let mut expansion = Vec::new(); + if simple_token_text(&url) + .to_ascii_lowercase() + .contains("orcid.org") + { + expansion.push(control_sequence_token(input, "texrraorcibadge", trace_key)); + } + expansion.extend(inner); expansion.push(control_sequence_token(input, "texrralinkend", trace_key)); input .as_mut() diff --git a/tests/typeset.rs b/tests/typeset.rs index 112eeee..c8ae950 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -133,6 +133,10 @@ fn arxiv_title_block_uses_rules_and_small_caps() { first_page.contains("font-style=\"italic\">arxiv"), "italic emph{{arxiv}} title run missing" ); + assert!( + first_page.contains("fill=\"#008000\">iD"), + "ORCID link badge missing" + ); } #[test]