1

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}

enter image description here

3
  • 4
    You have discovered that tabular uses math mode.
    – egreg
    Aug 23 '21 at 21:12
  • 3
    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
  • 1
    As suggested in tex.stackexchange.com/questions/100263/…, adding \makeatletter \def\m@th{\mathsurround\z@\color{black}} \makeatother should do the trick.
    – citsahcots
    Aug 23 '21 at 22:39
5

enter image description here

\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}
2
  • 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?
    – First User
    Aug 24 '21 at 12:01
  • 1
    @FirstUser, sorry that I am not aware of such a package..
    – citsahcots
    Aug 24 '21 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.