[Tex/LaTex] Specific colour in equation links

colorhyperref

In hyperref package, is it possible to specify a specific color for equation links different than other link colors ?

Following are present color specifications that I am using for hyperref package

colorlinks=true,       % false: boxed links; true: colored links
linkcolor=red,          % color of internal links
citecolor=blue,        % color of links to bibliography
filecolor=magenta,      % color of file links
urlcolor=cyan   

(Is it possible to do it with \cref ?)

Thanks.

Best Answer

You can define your own link command for equations and change the (border) color for links locally.

LaTeX with \ref

\documentclass[a5paper]{article}

\usepackage{xcolor}
\colorlet{linkequation}{blue}
\usepackage[colorlinks]{hyperref}

\newcommand*{\refeq}[1]{%
  \begingroup
    \hypersetup{
      linkcolor=linkequation,
      linkbordercolor=linkequation,
    }%
    \ref{#1}%
  \endgroup
}

\begin{document}
\tableofcontents
\section{Example}\label{sec:example}
\begin{equation}
\label{eq:einstein}
E=mc^2
\end{equation}
See section \ref{sec:example} and equation \refeq{eq:einstein}.
\end{document}

Result \refeq

Package amsmath and \eqref

And an example for the redefinition of \eqref from package amsmath:

\documentclass[a5paper]{article}

\usepackage{amsmath}

\usepackage{xcolor}
\colorlet{linkequation}{blue}
\usepackage[colorlinks]{hyperref}

\newcommand*{\SavedEqref}{}
\let\SavedEqref\eqref
\renewcommand*{\eqref}[1]{%
  \begingroup
    \hypersetup{
      linkcolor=linkequation,
      linkbordercolor=linkequation,
    }%
    \SavedEqref{#1}%
  \endgroup
}

\begin{document}
\tableofcontents
\section{Example}\label{sec:example}
\begin{equation}
\label{eq:einstein}
E=mc^2
\end{equation}
See section \ref{sec:example} and equation \eqref{eq:einstein}.
\end{document}

Result \eqref

Package cleveref and \cref

\documentclass[a5paper]{article}

\usepackage{xcolor}
\colorlet{linkequation}{blue}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}

\makeatletter
\creflabelformat{equation}{%
  \textup{%
    \hypersetup{
      linkcolor=linkequation,
      linkbordercolor=linkequation,
    }%
    (#2#1#3)%
  }%
}
\makeatother

\begin{document}
\tableofcontents
\section{Example}\label{sec:example}
\begin{equation}
\label{eq:einstein}
E=mc^2
\end{equation}
See section \ref{sec:example} and \cref{eq:einstein}.
\end{document}

Result \cref

Related Question