# Text colour in empheq for multiline AMS environments

I use the empheq package along with the xcolor package to display equations in coloured boxes. I also wish to change the text colour of the equation. In single-line environments, such as equation, this works perfectly. With multi-line AMS environments, however, the text colour is only applied to the first line, then the equation goes on with the default colour from the second line.

The MWE goes as follows:

\documentclass{article}
\usepackage[svgnames, x11names]{xcolor}
\usepackage{amsmath}
\usepackage{empheq}
\newcommand{\HEG}[1]{\begin{empheq}[box = \colorbox{Thistle4}]{gather}{\color{Snow1}#1}\end{empheq}}
\begin{document}
\HEG{\mathcal{T}\left(a_1\left\{x_{1k}\right\} + a_2\left\{x_{2k}\right\}\right) =\\\nonumber
= a_1 \mathcal{T}\left(\left\{x_{1k}\right\}\right) + a_2 \mathcal{T}\left(\left\{x_{2k}\right\}\right)}
\end{document}


This will produce the following output:

Manually inserting colour definition at the beginning of the new line will work, ie:

\documentclass{article}
\usepackage[svgnames, x11names]{xcolor}
\usepackage{amsmath}
\usepackage{empheq}
\newcommand{\HEG}[1]{\begin{empheq}[box = \colorbox{Thistle4}]{gather}{\color{Snow1}#1}\end{empheq}}
\begin{document}
\HEG{\mathcal{T}\left(a_1\left\{x_{1k}\right\} + a_2\left\{x_{2k}\right\}\right) =\\\nonumber
\color{Snow1}= a_1 \mathcal{T}\left(\left\{x_{1k}\right\}\right) + a_2 \mathcal{T}\left(\left\{x_{2k}\right\}\right)}
\end{document}


will produce

Is there a way to configure empheq to keep the text colour across multiple lines without manual insertions of the colour definition? Your thoughts are much appreciated.

• Change color before the environment (observe the braces to group it): \newcommand{\HEG}[1]{{\color{Snow1}\begin{empheq}[box = \colorbox{Thistle4}]{gather}{#1}\end{empheq}}} Feb 18, 2020 at 14:00
• @Sigur: thank you, that works perfectly. Feb 18, 2020 at 14:05
• Unrelated: no need to load amsmath before empheq. Feb 18, 2020 at 14:09
• @Sigur, you are welcome! (+1) Feb 18, 2020 at 14:17

(works for non numbered only)

You can apply the color to the whole environment simply using \color{} before it. But, make sure that the color changes apply only to the environment, so embrace everything with braces, that is,

{\color{<color>}...}


Off topic: I would not use those \left \right.

MWE

\documentclass{article}
\usepackage[svgnames,x11names]{xcolor}
\usepackage{empheq}
\newcommand{\HEG}[1]{%
{\color{Snow1}%
\begin{empheq}[box=\colorbox{Thistle4}]{gather}{#1}\end{empheq}%
}%
}
\begin{document}
Text in normal color.
\HEG{
\mathcal{T} (a_1 \{x_{1k}\} + a_2 \{x_{2k}\}) = \\
a_1 \mathcal{T}(\{x_{1k}\}) + a_2 \mathcal{T}(\{x_{2k}\})
}
Text in normal color.
\end{document}

• Somehow this is killing the equation numbering... Feb 18, 2020 at 14:22
• @campa, it is not killing, but changing its color also.... lol Feb 18, 2020 at 14:23
• Ah, of course... silly me :-P Feb 18, 2020 at 14:24
• For me, numbering colour is all right as I use the suggestion at tex.stackexchange.com/questions/134300/… \makeatletter \def\tagform@#1{\maketag@@@{\footnotesize\fontspec{CMU Serif}\color{Grey}(\ignorespaces#1\unskip\@@italiccorr)}} \makeatother  Feb 18, 2020 at 14:56

A small variation of Sigur's answer: I define an environment instead of a macro (my idiosyncrasy: I find it better to read) and declare a new tag form which guarantees that the equation number is still printed in black.

\documentclass{article}

\usepackage[svgnames, x11names]{xcolor}
\usepackage{empheq}

% provided by mathtools, which is loaded by empheq
\newtagform{black}{\textcolor{black}\bgroup(}{)\egroup}

\newenvironment{important}[1][gather] % optional parameter defaults to gather
{%
\usetagform{black}%
\color{Snow1}%
\setkeys{EmphEqEnv}{#1}%
\setkeys{EmphEqOpt}{box=\colorbox{Thistle4}}%
\EmphEqMainEnv
}{\endEmphEqMainEnv}

\begin{document}

See
\begin{important}
\mathcal{T}(a_1\{x_{1k}\} + a_2\{x_{2k}\}) = \nonumber \\
= a_1 \mathcal{T} (\{x_{1k}\}) + a_2 \mathcal{T}(\{x_{2k}\})
\end{important}
or similarly
\begin{important}[align]
\mathcal{T}(a_1\{x_{1k}\} + a_2\{x_{2k}\}) &= \\ \nonumber
&= a_1 \mathcal{T} (\{x_{1k}\}) + a_2 \mathcal{T}(\{x_{2k}\})
\end{important}

\end{document}


• Very very nice!! Feb 18, 2020 at 14:33