[Tex/LaTex] Numbering color in align environment

aligncolorequationslabelsnumbering

I have a long series of equations in an align environment and I want to highlight only the last one (final result) using \color{red}. However, the label number stays black (unlike to what happen in the equation environment). How do I change also the color of the number?

MWE

\documentclass[11pt,a4paper]{report}

\usepackage{amsmath, amssymb}
\usepackage{color}

\newcommand{\colorlabel}[1]{%
  \refstepcounter{equation}%
  \tag{\textcolor{#1}{\theequation}}}

\begin{document}

\begin{equation}
\label{eq:equation}
\color{red} a = b + c
\end{equation}

\begin{align}
\label{eq:align}
a &= b + c \nonumber
\\
& \colorlabel{red}\color{red} = e + f
\end{align}
Eq~\eqref{eq:equation} shows that referencing using the equation environment gives black text.
Eq~\eqref{eq:align} shows that referencing using the align environment gives colored numbers with black brackets.

\end{document}

enter image description here

UPDATE

Building on jarauh's solution, I am currently using

\newcommand{\colorlabel}[1]{%
  \refstepcounter{equation}%
  \tag{\color{#1}{\theequation}}}

which, however, keeps the brackets black. Also, when references, the number is colored but not the brackets. This behavior is different from the one shown using equation (everything is black when referenced). I would like to have a consistent behavior between them (it would be great to have one single command, without manually modifying the color before/after the equation).

Best Answer

I checked the AMS LaTeX documentation amsmath.pdf to see how labels are treated, and I found a way to colour the equation number next to the equation red, while the colour of any reference is unchanged. All other parts of the align environment have to be made red separately. One thing to note: If you use \color{red} within the environment align, its effect only reaches until the next & or \\. Apparently, all cells in the environment are within different groups.

\makeatletter
\definecolor{johnnywalker}{rgb}{1,0,0}
\newcommand{\redlabel}{%
  \refstepcounter{equation}%
  \global\tag@true%
  \nonumber%
  \gdef\df@tag{\maketag@@@{{\color{johnnywalker}(\theequation)}}\def\@currentlabel{\theequation}}}
\makeatother

Then you can use this as follows:

\begin{align}
  a &  = b + c
  \\
  \redlabel
  &  = e + f
\end{align}

Now, \ref and \eqref should behave as expected.

Explanation

The commands \tag and \label do not create the tag and label immediately. Instead, everything is deferred until all of the line has been read. Only then is the tag typeset and the label created.

The code above does the following:

  1. Step the counter manually (since we cannot rely on the automatic tag generation)
  2. Tell AMSTeX that the tag has been set manually.
  3. Tell AMSTeX to not generate an equation number automatically
  4. Initialize the command \df@tag with content that generates the tag and the label

    1. and 3. I copied from the definition of \tag@in@align (the version of \tag that is active in align environments). 4. comes from the definition of \make@df@tag@@@ (the command that is responsible for saving the information about the tag and the label).
Related Question