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?


2 Answers 2


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.

  • But you're right; this does produce an error when I combine it with the IEEEeqnarray from the IEEEtrantools package. I tried redefining equation s and the \[ ... \] so that they behaved as gather s and I could get away without the \everydisplay, but that didn't work very well. What sort of thing did you have in mind when you talked about redefining basic displayed math otherwise? Commented Dec 7, 2011 at 16:01
  • Update: replacing the everydisplay with \let\originaldisplaystyle\displaystyle \renewcommand\displaystyle{\color{black}\originaldisplaystyle} stopped the errors, and everything inside align s or IEEEeqnarray s is beautiful and black (or red, if it's marked as being text); however, normal equation s now render in red rather than in black, since displaystyle is not part of the definition for equation. Is there some way of suppressing everydisplay so that it only affects the equation environment? Commented Dec 7, 2011 at 18:41
  • 1
    @Donkey_2009: Redefining equation would be an option.
    – Stefan Kottwitz
    Commented Dec 7, 2011 at 18:49
  • Thanks - I've now done that (using \let\oldeq\equation \def\equation{\oldeq\color{black}} ) but for some reason I can't do the same for the equation* environment: I keep getting errors. What is the problem here? Commented Dec 8, 2011 at 8:19
  • 1
    @Donkey_2009: This could be a news question on the site, better than in a comment - how to redefine the equation* environment of amsmath.
    – Stefan Kottwitz
    Commented Dec 8, 2011 at 8:20

If you can use xelatex or lualatex to compile the document, a combination of fontspec and unicode-math can help:

\setmainfont[Color=FF0000]{Latin Modern Roman}
\setsansfont[Color=FF0000]{Latin Modern Sans}
\setmonofont[Color=FF0000]{Latin Modern Mono}


A bunch of text, then an equation.
  f(x) = \sin (x) \text{ and } g(x) = e^x\cos(x)
Some \textsf{inline} math \( a = b \), and then an \texttt{align}
 N^2 &= -\frac{g}{\rho_0} \frac{\partial \rho}{\partial z} \\
   N &= \sqrt{-\frac{g}{\rho_0} \frac{\partial \rho}{\partial z}}

enter image description here

  • 1
    When I am trying to compile your example, but setting black for text and red for math I get funny result when most math is red, but some elements (horizontal lines in fractions and roots) are still black. Is this a bug of unicode-math?
    – Misha
    Commented Jul 27, 2012 at 18:24
  • @Misha I honestly don't know, perhaps it has to with how those lines are rendered. Edit: I would recommend asking a follow-up question about this. Commented Jul 27, 2012 at 18:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .