LaTeX forum ⇒ Math & Scienceempheq | 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

Postby hbaromega » Fri Feb 01, 2013 2:10 pm

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

This paints A in red. I want to color all of the equations, e.g. like this.
  1. \begin{empheq}[box=\widefbox]{align}
  2. {\color{red}
  3. A
  4. &=B+C\nonumber\\
  5. &=D \nonumber\\
  6. &=E+F
  7. }
  8. \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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Fri Feb 01, 2013 3:57 pm

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:

  1. \documentclass{article}
  2. \usepackage{amsmath,empheq,xcolor}
  3.  
  4. \newcommand*\widefbox[1]{\fbox{\hspace{1em}#1\hspace{1em}}}
  5.  
  6. % see the empheq documentation for examples like this one:
  7. \newenvironment{important}[2][]{%
  8. \setkeys{EmphEqEnv}{#2}%
  9. \setkeys{EmphEqOpt}{box=\normalcolor\widefbox,#1}%
  10. \color{red}%
  11. \EmphEqMainEnv}%
  12. {\endEmphEqMainEnv}
  13.  
  14. \begin{document}
  15.  
  16. \begin{important}{align}
  17. A &= B+C\nonumber\\
  18. &= D \nonumber\\
  19. &= E+F
  20. \end{important}
  21.  
  22. \end{document}


But this will also color the equation numbers.

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

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Postby hbaromega » Fri Feb 01, 2013 4:49 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?

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Fri Feb 01, 2013 4:58 pm

No, you can define an optional argument for that:

  1. \documentclass{article}
  2. \usepackage{amsmath,empheq,xcolor}
  3.  
  4. \newcommand*\widefbox[1]{\fbox{\hspace{1em}#1\hspace{1em}}}
  5.  
  6. \usepackage{xparse}% flexible defining of document commands
  7.  
  8. % see the empheq documentation for examples like this one:
  9. \NewDocumentEnvironment{important}{O{red}O{}m}{%
  10. \setkeys{EmphEqEnv}{#3}%
  11. \setkeys{EmphEqOpt}{box=\normalcolor\widefbox,#2}%
  12. \color{#1}%
  13. \EmphEqMainEnv}%
  14. {\endEmphEqMainEnv}
  15.  
  16. \begin{document}
  17.  
  18. \begin{important}{align}
  19. A &= B+C\nonumber\\
  20. &= D \nonumber\\
  21. &= E+F
  22. \end{important}
  23.  
  24. \begin{important}[blue]{align}
  25. A &= B+C\nonumber\\
  26. &= D \nonumber\\
  27. &= E+F
  28. \end{important}
  29.  
  30. \end{document}


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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am
Location: Aarhus, Denmark

Postby svend_tveskaeg » Sat Feb 02, 2013 2:06 pm

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)

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Math & Science”

Who is online

Users browsing this forum: Google [Bot] and 2 guests