# \everymath and \everydisplay changes color of tables?

I am trying to colorize equations (especially inline ones) so that they standout from the rest of the text and thus have used the \everymath{} and \everydisplay{} commands, however that also seems to affect tables. Text is not affected though. Any idea why this happening or how to get around it?

\documentclass{article}
\usepackage{xcolor}
\everymath{\color{teal}}
\everydisplay{\color{magenta}}

\begin{document}

Some text.
Some text.
Some text.
Some text.
$x=\int_{-\infty}^{\infty}\frac{\sin}{x}\mathrm{d}x=\frac{\pi}{2}$
Some text.
Some text.
Some text.
Some text.
$x=\int_{-\infty}^{\infty}\frac{\sin}{x}\mathrm{d}x=\frac{\pi}{2}$

\begin{table}[!h] % also colored?
\centering
\begin{tabular}{ll}
\hline
Animal  &   Legs \\
\hline
Dogs    &   4 \\
Human   &   1 \\
\hline
\end{tabular}
\end{table}
\end{document}


• You have discovered that tabular uses math mode. Aug 23 '21 at 21:12
• math is used in lots of non-mathematical use, for tables it is used to get vertical centering which is the default alignment Aug 23 '21 at 21:25
• As suggested in tex.stackexchange.com/questions/100263/…, adding \makeatletter \def\m@th{\mathsurround\z@\color{black}} \makeatother should do the trick. Aug 23 '21 at 22:39

\documentclass{article}
\usepackage{xcolor}
\everymath{\color{teal}}
\everydisplay{\color{magenta}}
%%%%%%%%%%%%%
\makeatletter
\def\m@th{\mathsurround\z@\color{black}}
\makeatother
%%%%%%%%%%%%%
\begin{document}

Some text.
Some text.
Some text.
Some text.
$x=\int_{-\infty}^{\infty}\frac{\sin}{x}\mathrm{d}x=\frac{\pi}{2}$
Some text.
Some text.
Some text.
Some text.
$x=\int_{-\infty}^{\infty}\frac{\sin}{x}\mathrm{d}x=\frac{\pi}{2}$

\begin{table}[!h] % also colored?
\centering
\begin{tabular}{ll}
\hline
Animal  &   Legs \\
\hline
Dogs    &   4 \\
Human   &   1 \\
\hline
\end{tabular}
\end{table}
\end{document}

• Thanks! I followed the link and if I understand correctly, this workaround works under the assumption that environments like tabular or whatever that use math mode actually use the \m@th command? If this is not true is there any package that allows styling of all mathematics throughout the document in isolation safely? Aug 24 '21 at 12:01
• @FirstUser, sorry that I am not aware of such a package.. Aug 24 '21 at 12:19