12

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

\everymath{\color{green}}

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?

7
  • easy-peasy with xelatex or lualatex ... Mar 15 '12 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 '12 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 '12 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 '12 at 0:15
  • 2
    For more details see tex.stackexchange.com/questions/503/why-is-preferable-to Mar 16 '12 at 0:22
15
\everymath{\color{green}}
\everydisplay{\color{green}}
\def\m@th{\normalcolor\mathsurround\z@}

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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