# Why does \everydisplay conflict with gather and multline

When gather* is used together with \everydisplay an error is produced. Is there a possibility to make these work together?

Minimal working example:

\documentclass{ctexart}
\usepackage{amsmath,color}
\everydisplay{\color{blue}}
\begin{document}
\begin{gather*}
1+\cos x
\end{gather*}
\end{document}


Instead of \everydisplay, \everymath could be used. This applies to gather as well. To avoid coloring of inline math, you could check if you are within gather or align similar to amsmath's own checks.

Complete example:

\documentclass{article}
\usepackage{amsmath,color}
\newcommand*{\eqcolor}{\color{blue}}
\makeatletter
\everymath{%
\ifingather@ \eqcolor%
\else \ifinalign@ \eqcolor
\fi
\fi
}
\makeatother
\begin{document}
\begin{gather*}
1+\cos x
\end{gather*}
\begin{align*}
1+\cos x
\end{align*}
\centering $1 + \cos x$
\end{document}


As you can see, inline math is not colored. Regarding other displayed math: instead of equation or $...$ you could use gather or gather*, respectively. This could be done in the preamble, without changes to equation environments in the text, such as

\let\equation\gather
\let\endequation\endgather


If you just say \everydisplay{\color{blue}}, then the previous content of it gets erased and you will have these kind of problems. The right way to use \everydisplay is:

\everydisplay\expandafter{\the\everydisplay \color{blue}}


Then no problem should happen.

• With gather and this definition the same error occurs (! Improper \halign inside 's.) – Stefan Kottwitz Mar 16 '11 at 12:05