4

I am trying to change the link color made with \eqref to be different from the other \ref links. I have this

\makeatletter
\let\reftagform@=\tagform@
\def\tagform@#1{\maketag@@@{(\ignorespaces\textcolor{blue}
{#1}\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\reftagform@{\ref{#1}}}}
\makeatother

But it only changes the color of the number in the equation. Could you help me with this?

Thank you!

Natalia
  • 49
  • 1
    Welcome to TeX.se. Instead of posting code fragments, please put your fragment into a complete, compilable document that starts with \documentclass{...} and ends with \end{document} that shows the problem. – Alan Munn Nov 13 '17 at 02:35
  • 1
    I’ve not tested it, but I’d say that your code snippet changes the color of all equation numbers, not only when they appear as a reference. – GuM Nov 13 '17 at 02:54
  • I forgot: Welcome to TeX.SX! – GuM Nov 13 '17 at 03:01
  • have you tried applying the color to only the redefinition of \eqref? – barbara beeton Nov 13 '17 at 03:10
  • how do I do that @barbarabeeton ? – Natalia Nov 13 '17 at 04:10

2 Answers2

7

If all parts of a reference should appear in a specific color, the command \color in a group in conjunction with \hypersetup for linkbordercolor comes into action.

Store the definition of \eqref first in, say, \@msm@th@ref, then use

\begingroup\leavevmode\color{violet}...
\@msm@th@eqref
\endgroup

in a redefined \eqref macro.

This will use violet as color for parentheses, reference value and link.

Another option is to use mathtools and \newtagform, this will change the number of the equation in place however. (This option is not shown here)

(About the usage of \leavevmode see the comment by egreg below. Thanks to him to point to this possible issue).

\documentclass{article}

\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{hyperref}


\makeatletter
\let\@msm@th@eqref\eqref
\renewcommand{\eqref}[1]{%
  \begingroup
  \leavevmode
  \color{violet}%
  \hypersetup{linkbordercolor=[named]{violet}}%
  \@msm@th@eqref{#1}%
  \endgroup
}
\makeatother


\begin{document}

\section{Foo} \label{section::foo}
\begin{equation}
a \equiv a\label{eq::foo}
\end{equation}


See the important \eqref{eq::foo} but look also at \ref{section::foo}
\end{document} 

enter image description here

  • 1
    Just for safety, there should be \leavevmode before \color{violet}. – egreg Nov 13 '17 at 12:56
  • @egreg: Hm, I missed this feature so far. Doesn't \color work in \vmode? –  Nov 13 '17 at 12:57
  • It can be issued in vertical mode, but when it's used for typesetting a specific piece of text, it's safer when a paragraph has already begun. – egreg Nov 13 '17 at 13:00
  • @egreg: Thanks, I added it with a reference to your explanation –  Nov 13 '17 at 13:02
  • Neither of these options worked for me, looking at the error that I got: Undefined control sequence. ...r[]{page}\glsnumberformat@nil I think It must have something to do with the \gls command in the glossaries package \usepackage{glossaries} – Natalia Nov 14 '17 at 00:07
  • @Natalia: Your comment isn't useful, since your question does not say anything about glossaries –  Nov 14 '17 at 02:46
  • This only changed the parentheses around the equation number to violet, but the number remains black :'( – user1271772 May 23 '18 at 04:04
  • Can I force the color (instead of violet) to take from hyperref link color? – hola Dec 18 '18 at 02:05
  • @pushpen.paul: I don't know ... I can take a look, but I stopped my support for TeX.SE basically... –  Dec 19 '18 at 19:06
  • @ChristianHupfer Sorry to hear that! Hope, you'll be back soon... – hola Dec 20 '18 at 12:11
1

You just redefine the \eqref command as mentioned below and insert the color as you want.

\documentclass{article}

\usepackage{amsmath}
\usepackage{color}

\def\eqref#1{\textcolor{blue}{(\ref{#1})}}

\begin{document}

\begin{equation}
\label{eq1}
\end{equation}


This is a text \eqref{eq1}
\end{document} 
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
Saravanan
  • 1,475
  • 3
    11 months, 44 answers. Congratulations. Unfortunately, you still have no clue how to mark up code and rely on others :-( – Johannes_B Nov 13 '17 at 06:15
  • Solution matters, formatting doesn't. :) – Saravanan Nov 13 '17 at 06:17
  • 5
    Wrong. Both matter. That is why we are using LaTeX (& Co.). – AlexG Nov 13 '17 at 08:12
  • 1
    Actually that only changes the color of the parenthesis, while leaving the color of the text inside the same of the other links – Natalia Nov 13 '17 at 08:20
  • @Natalia This answer answers the question you asked perfectly fine. What you did not mention, was the use of hyperref along with the colorlinks option. I was thinking that you might be speaking about this specifically, but it was not clear. Hence, i just left an upvote to this answer. – Johannes_B Nov 13 '17 at 17:28
  • @Johannes_B indeed I was not very clear. Yes I use the hyperrref with the colorlinks option on as in here: \usepackage[pagebackref]{hyperref} \hypersetup{colorlinks,linkcolor=DarkBlue,anchorcolor=red,pdfdisplaydoctitle=true,pdfpagemode=UseOutlines,% bookmarksnumbered=true,bookmarksopen=true} – Natalia Nov 14 '17 at 00:10