[Tex/LaTex] change the color of an align environment

aligncolor

regarding this documentation

ftp://tug.org/tex-archive/info/math/voss/mathCol/mathCol.pdf

it should be easy to change the color of an align environment like this:

\documentclass{article}
\usepackage{color,amsmath}
\begin{document}
\begin{align}\color{red}
x &= 1\\
y &= 2
\end{align}
\end{document}

But all that changes to red is the first entry, i.e. the x.
I use MiKTeX 2.8 on Windows XP.

Any ideas?

Best Answer

Each cell within the align environment forms a group, localizing the extent of the colour change. If you wrap the colour change around the outside of align, it spans across the internal cells:

enter image description here

\documentclass{article}
\usepackage{xcolor,amsmath}% http://ctan.org/pkg/{xcolor,amsmath}
\begin{document}
{\color{red}\begin{align}
x &= 1\\
y &= 2
\end{align}}
\end{document}

You'll notice that this sets even the equation numbers in \color{red}. This is easily fixed by adding the following to your preamble:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\math@cr@@@align}% <cmd>
  {\place@tag}% <search>
  {\bgroup\color{black}\place@tag\egroup}% <replace>
  {}{}% <success><failure>
\makeatother

The above etoolbox-patch inserts a black colour-change around the number-printing mechanism \place@tag:

enter image description here

For individual colour modifications to each cell/component of the line, insert \color{<colour>} in the respective cells you want to use colour <colour>.