TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. – Torbjørn T. Dec 6 '11 at 17:47
Thanks. It's nice to see that adding the backticks changes the background color of the code in question. I hope a similar sort of thing is possible in TeX. – Donkey_2009 Dec 6 '11 at 17:50
up vote 17 down vote accepted

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.

share|improve this answer
Thanks both of you: it looks beautiful now! – Donkey_2009 Dec 6 '11 at 19:31
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? – Donkey_2009 Dec 7 '11 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? – Donkey_2009 Dec 7 '11 at 18:41
@Donkey_2009: Redefining equation would be an option. – Stefan Kottwitz Dec 7 '11 at 18:49
@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 Dec 8 '11 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

share|improve this answer
Thanks both of you: it looks beautiful now! – Donkey_2009 Dec 6 '11 at 19:31
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 Jul 27 '12 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. – Torbjørn T. Jul 27 '12 at 18:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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