I'd like to change the color of all math in my document. I understand that several packages and some engines provide support for changing the color of all math, and I understand that something like


almost works, but also ends up coloring things like URLs and captions, while failing to color displayed equations.

Is there a reliable way to change the color of just math, in pdflatex, without relying on special packages or classes?

  • easy-peasy with xelatex or lualatex ... Mar 15, 2012 at 22:32
  • 1
    This needs a Minimal non-Working Example that shows the mal-colored captions, URLs and display math. Btw, it's strongly discouraged to use $$...$$, better switch to \[...\].
    – yo'
    Mar 15, 2012 at 22:39
  • @tohecz : What is the difference between the two? I am an ignorant who just doesn't know and I wonder. I must say I use the cash's all the time so I guess it's good I ask Mar 15, 2012 at 22:59
  • 2
    The $ ... $ for inline and $$ ... $$ for displayed come from TeX and are not recommended for LaTeX. They do work 'most' of the time. However the do interfere with several packages (and worse the error is ofter very hard to spot. e.g. they conflict with fleqn from amsmath. I teach my students to use ( ..) and [ ...] respectively, and I get fewer LaTeX questions the night before something is due. Mar 16, 2012 at 0:15
  • 2
    For more details see tex.stackexchange.com/questions/503/why-is-preferable-to Mar 16, 2012 at 0:22

1 Answer 1


will get you most of the way there, although you are still likely to need some special fixup for individual commands here and there that use math internally without using the \m@th command which I redefine above to reset the color. Most "internal" uses of math for vertical centering tables or superscripting footnote marks etc, use that macro but that convention (from Plain TeX originally) is not enforced anywhere, and also redefining it might not be safe in all contexts (\edef for example) so some uses may need more explicit redefinitions to reset the colour.

  • What if I just want the references to my equations to be written in green without automatically changing the color of my glossary or my figure references?
    – Wallflower
    Apr 16, 2023 at 11:49
  • @Wallflower this post is unrelated to references. post a new question if you have a question Apr 16, 2023 at 11:51
  • I did yesterday tex.stackexchange.com/questions/683022/… but had no return...
    – Wallflower
    Apr 16, 2023 at 19:38

You must log in to answer this question.

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