7

I'm having the following article:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  d(x, y) &= d(y, x) \tag{symmetry} \\
          &\leq d(y, z) + d(z,x) \tag{triangle}
\end{align*}

\end{document}

I'd now like to change the colour of all the tags - brackets included - in my document (in this case (symmetry) and (triangle)) to gray, instead of the standard black. How can I do that?

1

2 Answers 2

5

It's easy to define ‘tag styles’ with the \newtagform command from the mathtools package :

\documentclass{article}

\usepackage{mathtools}
\usepackage[x11names]{xcolor}
\newtagform{blue}{\color{SteelBlue3}(}{)}
\newtagform{redandblue}[\textcolor{SteelBlue3}]{\color{red}(}{)}
\begin{document}
\usetagform{blue}
\begin{align*}
  d(x, y) &= d(y, x) \tag{symmetry} \\
          &\leq d(y, z) + d(z,x) \tag{triangle}
\end{align*}

\usetagform{redandblue}
\begin{align*}
  d(x, y) &= d(y, x) \tag{symmetry} \\
          &\leq d(y, z) + d(z,x) \tag{triangle}
\end{align*}

\end{document} 

enter image description here

1
  • It would be good to have a version with different colors in each of the two tags/labels. It seems that the tag form/style cannot be changed like this within a multi-line equation. Nov 22, 2020 at 21:20
6

It's easy enough to redefine \maketag@@@:

enter image description here

\documentclass{article}

\usepackage{amsmath,xcolor}
\makeatletter
\def\maketag@@@#1{\hbox{\m@th\normalfont\color{black!50}#1}}
\makeatother

\begin{document}

\begin{align*}
  d(x, y) &= d(y, x) \tag{symmetry} \\
          &\leq d(y, z) + d(z,x) \tag{triangle}
\end{align*}

\end{document}

Note that the above would also modify the formatting of the equation numbers.


If you wish to avoid colouring references as well, then use the following:

enter image description here

\documentclass{article}

\usepackage{amsmath,xcolor}
\newif\ifeqref
\makeatletter
\renewcommand{\eqref}[1]{\textup{\eqreftrue\tagform@{\ref{#1}}}}
\def\maketag@@@#1{\hbox{\ifeqref\global\eqreffalse\else\color{black!50}\fi\m@th\normalfont#1}}
\makeatother

\begin{document}

\begin{align}
  d(x, y) &= d(y, x) \label{abc}\\
          &\leq d(y, z) + d(z,x) \tag{triangle}\label{def}
\end{align}
See~\eqref{abc} and~\eqref{def}.

\end{document}
5
  • Displaying both tags and equation numbers in gray adds some more consistency to my document, so that's perfect for me. Thank you!
    – Jeroen
    Nov 26, 2014 at 0:25
  • This affects also \eqref.
    – egreg
    Nov 26, 2014 at 0:32
  • @egreg: Thanks... I've updated the answer to condition on being using in \eqref or not.
    – Werner
    Nov 26, 2014 at 0:44
  • @Jeroen: I've updated the answer to provide a choice between having a coloured reference or not.
    – Werner
    Nov 26, 2014 at 15:10
  • Thank you for your work: it works nicely and I've upvoted your answer. I prefer Bernard's solution, though, because I'm already using mathtools and I find his code more readable. However, I'm sure yours will help a lot of people too. :)
    – Jeroen
    Nov 27, 2014 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .