From 2076da8f21a4932c29674bccf1b84dc62250a0d9 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 19 Oct 2026 21:37:17 +0800 Subject: [PATCH] Annotate ORCID author badges with their profile links --- README.md | 2 +- crates/texrra-core/src/document.rs | 2 ++ crates/texrra-core/src/document_parser.rs | 3 +++ docs/STATUS.md | 14 +++++++------- src/rust_typeset/pdf.rs | 16 +++++++++++++++- src/rust_typeset/pdf/layout.rs | 1 + src/rust_typeset/pdf/preview.rs | 2 +- tests/typeset.rs | 22 ++++++++++++++++++++++ 8 files changed, 52 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 25fd964..b830ff1 100644 --- a/README.md +++ b/README.md @@ -528,7 +528,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`, | Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure `[htbp]` placement (deferred top floats, bottom/page/here), table `[t]`/`[b]`/`[p]` placement | table float-page queues, `\textfraction` | | Contents | `\tableofcontents`, `\listoffigures`, `\listoftables` generated from numbered headings and captions, dotted leaders, page numbers resolved after pagination | per-chapter book/report contents | | Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak`, plain/fancy page styles, `\thispagestyle`, fancyhdr L/C/R headers and footers | — | -| Links | `\href`, `\url`, hyperref-green link text, `\orcidlink{id}` green `iD` badge | PDF `/Annots` URI annotations | +| Links | `\href`, `\url`, hyperref-green link text, `\orcidlink{id}` green `iD` badge, clickable PDF `/Annots` URI annotations for visible URLs, `\href` labels, and ORCID author badges | — | | Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt, chapter headings and numbering, chapter page breaks, document-level custom `\maketitle`, native arxiv-style preprint title blocks (rules, `\undertitle`, author columns, long date) | class-specific formatting beyond chapter breaks | | Live preview | incremental paragraph cache, page-hash diffing, SVG refresh | — | diff --git a/crates/texrra-core/src/document.rs b/crates/texrra-core/src/document.rs index 660fff2..c6c6e61 100644 --- a/crates/texrra-core/src/document.rs +++ b/crates/texrra-core/src/document.rs @@ -101,6 +101,7 @@ pub struct DocumentModel { pub citation_metadata: HashMap, /// Display text -> hyperlink URL for `\href` annotations. pub link_targets: HashMap, + pub orcid_urls: Vec, /// Bibliography keys in the order their metadata was declared. Needed to /// assign natbib-style year suffixes (2014a, 2014b, ...) deterministically. pub bibliography_order: Vec, @@ -131,6 +132,7 @@ impl Default for DocumentModel { citations: HashMap::new(), citation_metadata: HashMap::new(), link_targets: HashMap::new(), + orcid_urls: Vec::new(), bibliography_order: Vec::new(), author_year_citations: false, footnotes: Vec::new(), diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index f6283ce..18e09d8 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -1156,6 +1156,9 @@ impl Parser { self.link_depth = self.link_depth.saturating_add(1); } expanded::FrontendEventKind::LinkTarget { text, url } => { + if url.contains("orcid.org") { + self.document.orcid_urls.push(url.clone()); + } self.document.link_targets.insert(text.clone(), url.clone()); } expanded::FrontendEventKind::LinkEnd => { diff --git a/docs/STATUS.md b/docs/STATUS.md index dc40ce8..3f8984d 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -111,9 +111,9 @@ See `docs/ROADMAP.md` for concrete implementation plans. badge (rounded ORCID-green polygon with a white iD, drawn natively in PDF and SVG) before the author name; the original bitmap ORCID logo is not embedded. - Hyperlinks use hyperref's green text colour; visible `\url` text emits a - PDF `/Link` URI annotation (`/Annots`). `\href`/ORCID-name labels still - carry only colour, because their target URL is not yet stored on the run. + Hyperlinks use hyperref's green text colour; visible `\url` text, + `\href` display labels, and ORCID author badges emit PDF `/Link` URI + annotations (`/Annots`). Metadata baselines match the reference within 0.3 pt and page 1 keeps the same closing section-2 line as the reference. `printpdf 0.3.4` has no annotation API, so the link is added by reopening the finished PDF with @@ -128,7 +128,7 @@ See `docs/ROADMAP.md` for concrete implementation plans. 3.6 MB and `pdffonts` reports only embedded CID TrueType faces); this avoids viewer-dependent glyph substitution. Tables use natural column widths and centered rules; preview and PDF share the same table line coordinates. -- `cargo fmt --check` passes; `cargo test --offline` (54 tests: 50 compiler +- `cargo fmt --check` passes; `cargo test --offline` (56 tests: 52 compiler integration tests + 4 server tests) covers the three examples, the arXiv fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output, project API, static frontend assets, path traversal, the legacy @@ -137,7 +137,7 @@ See `docs/ROADMAP.md` for concrete implementation plans. ## Verification snapshot -- Compiler integration tests: 50; server tests: 4; total 54. +- Compiler integration tests: 52; server tests: 4; total 56. - `cargo fmt --check` passes. - arXiv fixture: 3 Letter pages, ~3.6 MB, embedded Liberation faces only. - Title/author/date/Introduction baselines within 0.3 pt of the XeLaTeX @@ -145,5 +145,5 @@ See `docs/ROADMAP.md` for concrete implementation plans. - Table 61.1 mm wide (reference 61.2 mm) with `\multicolumn` spans and partial `\cmidrule` rules; table rules in the SVG preview use absolute page coordinates, matching the PDF. -- Remaining blocker: PDF link annotations (`/Annots`); printpdf 0.3.4 has - no annotation API, so clickable `\href`/`\url` need a writer extension. +- PDF link annotations are added by reopening the finished PDF with lopdf, + since printpdf 0.3.4 has no annotation API. diff --git a/src/rust_typeset/pdf.rs b/src/rust_typeset/pdf.rs index 3f6a796..a7a20ba 100644 --- a/src/rust_typeset/pdf.rs +++ b/src/rust_typeset/pdf.rs @@ -361,6 +361,7 @@ enum PositionedPageItem { Badge { x: i64, y: i64, + url: Option, }, FramedBox { anchor: PageAnchor, @@ -580,6 +581,19 @@ impl PositionedPages { link_targets, ); } + PositionedPageItem::Badge { + x, + y, + url: Some(url), + } => { + let left = scaled_units_to_mm(*x); + let bottom = page_height_mm - (scaled_units_to_mm(*y) + 4.0); + annotations.push(LinkAnnotation { + page: index as u32 + 1, + rect: [left, bottom, left + 4.0, bottom + 4.0], + url: url.clone(), + }); + } PositionedPageItem::Centered { element, y, .. } => { let font_size = 11; let em = f64::from(font_size) * 25.4 / 72.27; @@ -791,7 +805,7 @@ impl Element for PositionedPages { y, ) } - PositionedPageItem::Badge { x, y } => { + PositionedPageItem::Badge { x, y, .. } => { let x = scaled_units_to_mm(*x); let y = scaled_units_to_mm(*y); let mut badge_area = body_area.clone(); diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index c1b85b3..6cbb894 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -2023,6 +2023,7 @@ pub(super) fn build_positioned_pages( .push(PositionedPageItem::Badge { x: millimeters_to_scaled(line_x), y: badge_y, + url: model.orcid_urls.get(column).cloned(), }); } } diff --git a/src/rust_typeset/pdf/preview.rs b/src/rust_typeset/pdf/preview.rs index 18bf309..3b0d428 100644 --- a/src/rust_typeset/pdf/preview.rs +++ b/src/rust_typeset/pdf/preview.rs @@ -137,7 +137,7 @@ fn page_svg( monospace_family, sans_family, ), - PositionedPageItem::Badge { x, y } => write_badge(&mut output, *x, *y), + PositionedPageItem::Badge { x, y, .. } => write_badge(&mut output, *x, *y), PositionedPageItem::Image { element, y, .. } => write_figure( &mut output, element, diff --git a/tests/typeset.rs b/tests/typeset.rs index fcef876..65275b4 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -88,6 +88,28 @@ fn hello_compiles_to_pdf() { #[test] +fn arxiv_author_orcid_links_have_pdf_annotations() { + let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join("arxiv-template") + .join("template.tex"); + let source = std::fs::read_to_string(&path).expect("read arXiv fixture"); + let file_name = path.to_string_lossy().to_string(); + let pdf = CompilerSession::default() + .compile(&source, &file_name) + .expect("arXiv PDF"); + let text = String::from_utf8_lossy(&pdf); + assert!( + text.contains("/Subtype/Link"), + "ORCID links should be annotations" + ); + assert!( + text.contains("orcid.org/0000-0000-0000-0000"), + "annotation should carry the ORCID URL" + ); +} + +#[test] fn arxiv_fixture_is_three_letter_pages() { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("fixtures")