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}
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 thealign
environment have to be made red separately. One thing to note: If you use\color{red}
within the environmentalign
, its effect only reaches until the next&
or\\
. Apparently, all cells in the environment are within different groups.Then you can use this as follows:
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:
Initialize the command
\df@tag
with content that generates the tag and the label\tag@in@align
(the version of\tag
that is active inalign
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).