2

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}
2

2 Answers 2

3

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}

enter image description here

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
0

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.

2
  • 2
    With gather and this definition the same error occurs (! Improper \halign inside $$'s.)
    – Stefan Kottwitz
    Mar 16, 2011 at 12:05
  • 1
    Also doesn't work with align
    – xotix
    Jul 14, 2021 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .