Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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}
share|improve this answer
    
Great, that works. I just wish I could do those things myself. Are the \let, \tagform@, etc commands part of LaTeX or are they TeX? Also, is the problem related to amsmath rather than hyperref as the link you provided seems to suggest? –  Vivi Apr 3 '12 at 1:01
    
@Vivi \let is a primitive TeX command: we save a copy of \tagform@ (an internal of amsmath) before redefining it. As I commented there, it's a weakness of amsmath that uses the same command for two different purposes. –  egreg Apr 3 '12 at 8:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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