[Tex/LaTex] Coloured equation number (without changing colour of reference using hyperref)

colorequationshyperref

I am working on a file where I am using the package hyperref so that the references to equations are linked and coloured. Here is a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{colorlinks=true}

\begin{document}

\begin{equation}
1=\beta\left[ \frac{ 1+\left( 1-\tau_{t+1}\right) r_{t} }{\Pi_{t+1}} \right]\label{Fisher}
\end{equation}

Make reference to \eqref{Fisher}.

\end{document}

This gives me the reference at the end red, which is great. Now I want to have the equation number in blue (not the reference to the equation, but the equation number itself). I achieve that by adding

\renewcommand\theequation{{\color{blue}\arabic{equation}}}

to the preamble, before of after hyperref (the result seems to be the same). On first compile, great, I get the exact result I want: the equation number is blue, and the reference to the equation is in red:

enter image description here

but a second compile will turn both the equation number and the reference to the equation blue!

How can I avoid that, and have my equation number in blue not interfere with the equation reference colour from hyperref?

Best Answer

You can adapt this answer by Andrew Stacey

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\let\reftagform@=\tagform@
\def\tagform@#1{\maketag@@@{(\ignorespaces\textcolor{blue}{#1}\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\reftagform@{\ref{#1}}}}
\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true}

\begin{document}

\begin{equation}
1=\beta\left[ \frac{ 1+\left( 1-\tau_{t+1}\right) r_{t} }{\Pi_{t+1}} \right]\label{Fisher}
\end{equation}

Make reference to \eqref{Fisher}.

\end{document}
Related Question