Skip to content

engine: hyperref colorlinks — colour \url/\href/\hyperlink text - #209

Merged
tannevaled merged 1 commit into
mainfrom
hyperref-colorlinks
Sep 3, 2026
Merged

engine: hyperref colorlinks — colour \url/\href/\hyperlink text#209
tannevaled merged 1 commit into
mainfrom
hyperref-colorlinks

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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 — a colour already flows to both drivers through each glyph — so this wires the option end to end.

What works now

  • \hypersetup{colorlinks=true, urlcolor=blue, linkcolor=…, allcolors=…} is a real primitive (hyperstyle.go) instead of a no-op stub.
  • 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/\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 own default) links keep the surrounding colour.

Latent bug fixed along the way

verbNodes never stamped the current colour, so verbatim text — \verb, \url — ignored \color (\textcolor{red}{\verb|x|} rendered black). It now stamps curColor like ordinary text, which is also what makes a coloured \url work.

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

Verification

\href/\url/\hyperlink under colorlinks render the matching colour in the SVG (fill="#…") from both option forms; colorlinks off leaves them uncoloured; a \hypertarget destination stays uncoloured. Full engine suite, the conformance ratchet (colour is orthogonal to the layout proxy), go vet and gofmt all green.

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit e717b3c into main Sep 3, 2026
18 checks passed
@tannevaled
tannevaled deleted the hyperref-colorlinks branch September 3, 2026 21:13
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