5

For the background to this, see my previous question

I've been trying to make changes in my LaTeX document so that math displays in black and text in red. Thanks to Stefan Kottwitz and Torbjørn T. I've been able to go some way towards doing this. At the moment I have

\usepackage{amsmath}
\usepackage{color}
\usepackage{everysel}
\EverySelectfont{\color{red}}
\everymath{\color{black}}

\let\originaldisplaystyle\displaystyle
\renewcommand\displaystyle{\color{black}\originaldisplaystyle}

\let\oldeq\equation
\def\equation{\oldeq\color{black}}

This changes the text color to red, and then changes the colors for inline math, align environment and equation environment to black. This all works fine. However, when I try to make similar changes to the equation* environment:

\let\oldeq*\equation*
\def\equation*{\oldeq*\color{black}}

I get errors. My guess is that the compiler is reading \equation* as \equation followed by a text asterisk: if I type

\newenvironment{oldeq*}{\equation*}{\endequation*}
\renewenvironment{equation*}{\begin{oldeq*}}{\end{oldeq*}}

then the document compiles, but the \equation* environment now renders as the \equation environment (i.e. with numbering) but with an asterisk placed before the equation. This is the only thing that I have managed to get to compile so far. What am I doing wrong?

1 Answers1

4

Here's a redefinition based on the original amsmath definition together with the color command:

\makeatletter
\renewenvironment{equation*}{%
  \mathdisplay@push
  \st@rredtrue \global\@eqnswfalse
  \color{black}
  \mathdisplay{equation*}%
}{%
  \endmathdisplay{equation*}%
  \mathdisplay@pop
  \ignorespacesafterend
}
\makeatother

A simpler solution, which also doesn't need to know amsmath's internals, is possible with the etoolbox package:

\usepackage{etoolbox}
\AtBeginEnvironment{equation*}{\color{black}}
Stefan Kottwitz
  • 231,401
  • 1
    Thanks SO much: everything's running really well now. I had tried copying in the amsmath definition, but I missed out the \makeatletter and \makeatother so it didn't work. – John Gowers Dec 08 '11 at 12:22
  • This is very helpful. Writing a small document where my math is a unique color for visibility, I combined this an \everymath\expandafter{\the\everymath\color{mathBlue}} to ensure my math is all blue WITHOUT breaking my equation* environments. Only downside is I need to do this for all math envs to avoid issues seen here, and here, and also here. This is perfect for my hacked together small use-case! – TimeTravelPenguin Apr 04 '22 at 02:57