Conflicting between \everydisplay and eqnarray environment in beamer class

In my presentation, I want every math to be blue and every display math to be red. In my attempt, I have tried to compile the following MWE

\documentclass{beamer}
\everymath{\color{blue}}
\everydisplay{\color{red}}
\begin{document}
\begin{frame}
\begin{eqnarray}
a &=& b\\
c &=& d
\end{eqnarray}
$$E=mc^2$$
\end{frame}
\end{document}


I got an error say Improper \halign inside 's. \end{frame}. If I disable \everydisplay command, there is no error. However, this is not my desire! I do want every display math to be typesetted in red. How can we achieve this?

• Just avoid eqnarray in every circumstances. – egreg Aug 2 '17 at 8:58
• @egreg Could you tell us the reasons why? – Say OL Aug 2 '17 at 16:38
• – egreg Aug 2 '17 at 17:03

Use beamer's own commands to change colours.

\documentclass{beamer}
\setbeamercolor{math text inlined}{fg=blue}
\setbeamercolor{math text displayed}{fg=red}

\begin{document}
\begin{frame}
\begin{align}
a &= b\\
c &= d
\end{align}
$$E=mc^2$$
$a=b$
\end{frame}
\end{document}


Note that you will get some unfortunate effects with equation labels if you use different colours for inline and displayed mathematics.

• Great! I could actually read Beamer manual before posting this question :) – Say OL Aug 2 '17 at 9:36
• It's a long read... – Ian Thompson Aug 2 '17 at 9:46
• You are right. Sometimes it is less efficient than surfing the internet or asking in the forum! – Say OL Aug 2 '17 at 16:42