# How would I get custom-colored equation numbers as simply as possible?

In a continuation of efforts to create a complete SAE technical paper class file, I need a little help finding the easiest way to create colored equation numbers. In my class file, I already define caption colors via the following:

\Requirepackage{color}
\definecolor{SAEblue}{rgb}{0, .62, .91}
\renewcommand\captionfont{\color{SAEblue}\small}


Similarly, in my mind, there must be a simple command I could alter, like:

\renewcommand\eqnumfont{color{SAEblue}}


However, I haven't found it on the forum. There are some more complicated examples, and also examples that define a \colorlabel property within equation or align environments, but I would like to define something within my class files that globally makes all equation labels my custom color. I'm not sure what package sets the color of equation numbers (by default).

• We need a complete minimal example as we don't know what is formatting your equation numbers by default in your class.
– cfr
Feb 12, 2016 at 2:33

Well, you can change \@eqnnum but whether this is what you want is impossible to say without more details about your class code and your desired results.

\documentclass{article}
\usepackage{xcolor,etoolbox}
\makeatletter
\patchcmd{\@eqnnum}{\normalcolor}{\color{magenta}}{\typeout{eqnnum patch: OK!}}{\typeout{eqnnum patch: Oh, dear!}}
\begin{document}
$$1 + 2 = 3\label{eq:siml}$$
\end{document}


• This is great. I just need to figure out what package is blocking me from being able to use this in my class file. It works as a MWE but not in my test document. Feb 12, 2016 at 16:30
• Ok, I determined this doesn't work because of the mhchem package I am using for making pretty looking chemical formulas in my document. Now to figure out why... Feb 12, 2016 at 17:00
• Ok I'm going to formulate this into a new question with a very simple MWE as I think that would be the appropriate way forward. Feb 12, 2016 at 17:15
• Continuing this issue in the following thread to find a solution that is compatible with amsmath. tex.stackexchange.com/questions/292583/… Feb 12, 2016 at 19:55

You can use the \newtagform and \usetagformcommands, defined by mathtools, and have different styles for tags within the same document:

\documentclass{article}

\usepackage{mathtools}
\usepackage[x11names]{xcolor}
\newtagform{blue}{\color{RoyalBlue3}(}{)}
\newtagform{redandblue}[\textcolor{RoyalBlue3}]{\color{red}(}{)}
\begin{document}
\usetagform{blue}
$$\label{blueeq} a =b + d$$
From \eqref{blueeq} we deduce:
\usetagform{redandblue}
$$\label{RandB} c = d \times e$$
But \eqref{RandB} does not imply \usetagform{blue}\eqref{blueeq}.

\usetagform{default}
$$f =g + h$$

\end{document}


If you only want the equation number coloured then redefine \theequation:

Here's the code:

\documentclass{article}
\usepackage{color}
\definecolor{SAEblue}{rgb}{0, .62, .91}
\renewcommand\theequation{{\color{SAEblue}\arabic{equation}}}
\begin{document}
$$1+1=2+\varepsilon$$
\end{document}


If you want the brackets coloured as well then @cfr has the answer:)