2

I am trying to use the hyperref package to color internal links coming from \label as green, while those coming from anchored text via \hypertarget as red. However, in both cases, the relevant text appears green? I am using revtex4-1, but I don't think that this is the problem ...

\documentclass[a4paper]{revtex4-1}
\usepackage[pdftex]{xcolor}
\usepackage[pdftex,breaklinks,colorlinks,
linkcolor=green,
anchorcolor=red]{hyperref}

\begin{document}

\begin{equation}
   \text{this is an equation} \label{theeq}
\end{equation}

This is the equation \ref{theeq} and it is green as expected.\\
\hypertarget{thelink}{This should be anchored}
\hyperlink{thelink}{ But its color is not red?}

\end{document}
2
3

Well, I suppose you report this bug to the maintainer of hyperref.

Until it is corrected you can use the following workaround:

\newcommand{\myhypertarget}[3][red]{\hypertarget{#2}{\textcolor{#1}{#3}}}%

Command \myhypertarget sets the colour red manually to the target text.

With the following MWE

\documentclass[a4paper]{revtex4-2}
\usepackage{xcolor}
\usepackage[%
  breaklinks,
  colorlinks,
  linkcolor=green,
  anchorcolor=red
]{hyperref}

\newcommand{\myhypertarget}[3][red]{\hypertarget{#2}{\textcolor{#1}{#3}}}%


\begin{document}

\begin{equation}
   \text{this is an equation} \label{theeq}
\end{equation}

This is the equation \ref{theeq} and it is green as expected.\\
\hypertarget{thelink}{This should be anchored}

And this is with \texttt{\\myhypertarget}: 
\myhypertarget{thelink1}{This should be anchored}
Text between target and link. Text between target and link. 
Text between target and link. Text between target and link. 
\hyperlink{thelink}{ But its color is not red?}

\hyperlink{thelink1}{ But its color is not red?}

\end{document}

you get the result:

resulting pdf

Please see that I deleted the driver pdftex for xcolor and hyperref. Also I used class revtex4-2, the current version of revtex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.