Skip to content

engine: \href becomes a clickable /Link annotation in the PDF - #198

Merged
tannevaled merged 1 commit into
mainfrom
pdf-link-annotations
Sep 3, 2026
Merged

engine: \href becomes a clickable /Link annotation in the PDF#198
tannevaled merged 1 commit into
mainfrom
pdf-link-annotations

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

The PDF driver drew a hyperlink's text but not a clickable rectangle, because go-pdfkit had no link-annotation API — so \href/\url were live in the SVG (<a href>) but inert in the PDF.

How

go-pdfkit v0.7.0 adds Page.AddLink (go-pdfkit/pdfkit#21). pdfDraw.link now places a /Link annotation over the inner box — engine-top-down (x, baseline-height) .. (x+width, baseline+depth), flipped into PDF y-up default user space — carrying the URL as a URI action. Bumps go-pdfkit v0.6.0 → v0.7.0.

Verification

End-to-end test: a rendered \href PDF now carries /Annots·/Link·/URI with the target URL. Full engine suite, go vet, gofmt green; rebased onto #196.

Closes the "clickable PDF links" documented gap.

🤖 Generated with Claude Code

The PDF driver drew a hyperlink's text but not a clickable rectangle, because
go-pdfkit had no link-annotation API; \href/\url were live in the SVG (<a href>)
but inert in the PDF. go-pdfkit v0.7.0 adds Page.AddLink, so pdfDraw.link now
places a /Link annotation over the inner box — engine-top-down (x, baseline-height)
.. (x+width, baseline+depth), flipped into PDF y-up default user space — carrying
the URL as a URI action.

Bumps go-pdfkit v0.6.0 -> v0.7.0. Verified end-to-end: a rendered \href PDF now
carries /Annots //Link //URI with the target URL; full engine suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 891fb6e into main Sep 3, 2026
18 checks passed
@tannevaled
tannevaled deleted the pdf-link-annotations branch September 3, 2026 17:14
tannevaled added a commit that referenced this pull request Sep 3, 2026
hyperref's colorlinks option colours a link's text (rather than drawing a border
box around it); the coloured-text style is the one this engine can render, since a
colour already flows to both drivers through each glyph. So this wires the option
end to end:

  - \hypersetup{colorlinks=true, urlcolor=blue, linkcolor=..., allcolors=...} is
    now a real primitive (hyperstyle.go) instead of a no-op stub, parsing the
    keyval and recording the options that change visible output.
  - The package-option form \usepackage[colorlinks,urlcolor=blue]{hyperref} routes
    its options through the same parser (as hyperref itself does), so the common
    arXiv form works too.
  - With colorlinks on, \url and \href paint their text in urlcolor and \hyperlink
    in linkcolor (a \hypertarget destination is not coloured); values resolve
    through the colour model, so names, rgb/HTML and xcolor mixes all work. With
    colorlinks off (hyperref's default) links keep the surrounding colour.

Also fixes a latent bug this surfaced: verbNodes never stamped the current colour,
so verbatim text — \verb, \url — ignored \color entirely (\textcolor{red}{\verb|x|}
rendered black). It now stamps curColor like ordinary text.

Corrects the now-stale doc comments in hyperlink.go that claimed go-pdfkit has no
link-annotation API (PR #198 added it).

Verified: \href/\url/\hyperlink under colorlinks render the matching colour in the
SVG (fill="#…") from both the \hypersetup and package-option forms; colorlinks off
leaves them uncoloured; a \hypertarget destination stays uncoloured; full engine
suite, the conformance ratchet, go vet and gofmt all green.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant