Closed Sophanatprime closed 1 year ago
It seems the \set@color
is the problem:
\makeatletter
\hyperlink{hello}{\hbox{\color@setgroup hbox hello\color@endgroup}}
\begingroup
\let\set@color\empty
\hyperlink{hello}{\hbox{\color@setgroup hbox hello\color@endgroup}}
\endgroup
\makeatother
the first one is not correct. however, the second does show the correct color.
I know what the reason is, but it is not trivial to resolve as it is a problem of the integration of l3color into LaTeX. E.g. your example would work if you don't use the colorlinks package option but \hypersetup{colorlinks}
instead (so that the color package is not loaded). But it then would break again if you load color
or xcolor
explicitly (and work again if you use a development version of xcolor
I made to test this).
You can try the following but note how it affects the second example ... (with the new xcolor it would work)
\DocumentMetadata{}
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\begin{document}
Hello.\hypertarget{hello}{}
\hypersetup{linkcolor=red}
\hyperlink{hello}{Hello} % red
\hyperlink{hello}{\XeTeXLinkBox{XeTeX Link Box Hello}} % black
\hyperlink{hello}{\color{green} \XeTeXLinkBox{XeTeX Link Box Hello}} % black
\ExplSyntaxOn\makeatletter
\AddToHook{pdfannot/link/GoTo/before}{\def\color@setgroup{\begingroup\color_ensure_current:}}
\ExplSyntaxOff\makeatother
\hyperlink{hello}{\XeTeXLinkBox{XeTeX Link Box Hello}} % black
\hyperlink{hello}{\color{green} \XeTeXLinkBox{XeTeX Link Box Hello}} % black
\end{document}
I think I get the point. For now, we cannot be mixing use l3color
and color
in the same place, or we cannot expect it will always show the right things. Until the new xcolor
package has been released.
Using
\DocumentMetadata
and\XeTeXLinkBox
, thelinkcolor
is always black, including in pdfLaTeX and LuaLaTeX.