Featured Book

LaTeX Beginners Guide

Who is online

In total there are 15 users online :: 0 registered, 0 hidden and 15 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 15 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

empheq | Coloring all Equations in an aligned System

empheqequationsAdd tags Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).

empheq | Coloring all Equations in an aligned System

Postby hbaromega on Fri Feb 1st, 2013

Suppose I'm using the empheq package with the corresponding environment and have the following code.
Code: Select all  •  Open in writeLaTeX
\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.
Code: Select all  •  Open in writeLaTeX
\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
hbaromega
 
Posts: 47
Joined: Mon Mar 7th, 2011

Re: empheq | Coloring all Equations in an aligned System

Postby cgnieder on Fri Feb 1st, 2013

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:

Code: Select all  •  Open in writeLaTeX
\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
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1670
Joined: Sat Apr 16th, 2011
Location: Germany

Re: empheq | Coloring all Equations in an aligned System

Postby hbaromega on Fri Feb 1st, 2013

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?
hbaromega
 
Posts: 47
Joined: Mon Mar 7th, 2011

Re: empheq | Coloring all Equations in an aligned System

Postby cgnieder on Fri Feb 1st, 2013

No, you can define an optional argument for that:

Code: Select all  •  Open in writeLaTeX
\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
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1670
Joined: Sat Apr 16th, 2011
Location: Germany

Re: empheq | Coloring all Equations in an aligned System

Postby svend_tveskaeg on Sat Feb 2nd, 2013

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)
User avatar
svend_tveskaeg
 
Posts: 475
Joined: Sun Jul 12th, 2009
Location: Aarhus, Denmark


Topic Tags

empheqequations

Return to Math & Science

Who is online

Users browsing this forum: No registered users and 15 guests