# [Tex/LaTex] How to get different colors for math and for text

colormath-mode

I want to include something in my LaTeX article that will make all mathematical formulae appear in black, while all text (including everything inside \text{}s in the middle of mathematical formulae) appear in red. Ideally I would like this to be something I could include in the preamble or in a .cls file or something like that. What would be the quickest way to do that?

A quick way is using \everymath, \everydisplay and the everysel package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{color}
\usepackage{everysel}
\EverySelectfont{\color{red}}
\everymath{\color{black}}
\everydisplay{\color{black}}
\begin{document}
text $x=0$
$\text{Text in math, }y= 1$
\end{document}


However, with more complicated amsmath environments such as align there could could be problems with \everydisplay, see: Modifying \everydisplay causes the align environment to stop working. If you would like to go this way, perhaps omit \everydisplay as align uses inline math internally, and redefine basic displayed math otherwise for using the desired color.