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


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?

Best Answer

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

text $x=0$
\[ \text{Text in math, }y= 1 \]

color in text and math

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.