LaTeX forum ⇒ Math & Science ⇒ empheq | Coloring all Equations in an aligned System

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

empheq | Coloring all Equations in an aligned System

Suppose I'm using the empheq package with the corresponding environment and have the following code.
\begin{empheq}[box=\widefbox]{align}{\color{red}A}&=B+C\nonumber\\&=D \nonumber\\&=E+F\end{empheq}

This paints A in red. I want to color all of the equations, e.g. like this.
\begin{empheq}[box=\widefbox]{align}{\color{red}A&=B+C\nonumber\\&=D \nonumber\\&=E+F}\end{empheq}

But I get an error.

How can sort this out? I don't want to specify color command for each expression of equation line (e.g. I may have 20 equations).

Thanks

cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
This is not working because every cell in align is a group in itself (just like in a {tabular}). The error you're getting is because you open a new group with { in the first cell but don't close it there again. Similarly the color setting is forgotten in the next cell because it was limited to the scope of the first cell. An own environment might be of help:

\documentclass{article}\usepackage{amsmath,empheq,xcolor} \newcommand*\widefbox[1]{\fbox{\hspace{1em}#1\hspace{1em}}} % see the empheq documentation for examples like this one:\newenvironment{important}[2][]{%   \setkeys{EmphEqEnv}{#2}%   \setkeys{EmphEqOpt}{box=\normalcolor\widefbox,#1}%   \color{red}%   \EmphEqMainEnv}%   {\endEmphEqMainEnv} \begin{document} \begin{important}{align}  A &= B+C\nonumber\\    &= D \nonumber\\    &= E+F\end{important} \end{document}

But this will also color the equation numbers.

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm
Thanks, Clemens.

But for every coloring (suppose, next time I want to color in blue) I have to define a new environment. Isn't it? Could be there an alternative/simpler way?

cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
No, you can define an optional argument for that:

\documentclass{article}\usepackage{amsmath,empheq,xcolor} \newcommand*\widefbox[1]{\fbox{\hspace{1em}#1\hspace{1em}}} \usepackage{xparse}% flexible defining of document commands % see the empheq documentation for examples like this one:\NewDocumentEnvironment{important}{O{red}O{}m}{%   \setkeys{EmphEqEnv}{#3}%   \setkeys{EmphEqOpt}{box=\normalcolor\widefbox,#2}%   \color{#1}%   \EmphEqMainEnv}%   {\endEmphEqMainEnv} \begin{document} \begin{important}{align}  A &= B+C\nonumber\\    &= D \nonumber\\    &= E+F\end{important} \begin{important}[blue]{align}  A &= B+C\nonumber\\    &= D \nonumber\\    &= E+F\end{important} \end{document}

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am
Location: Aarhus, Denmark
Interesting! This will go into me "treasure box" of LaTeX tricks.
In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)