# Color for math applies to \text{} and \intertext{} as well

I have a LaTeX beamer presentation where I use \setbeamercolor{math text} for enhanced readability and it works great. Unfortunately, all \text{} and \intertext{} is colored as well and that doesn't look nice. Is there any remedy?

MWE:

\documentclass{beamer}
\usepackage{xcolor}
\usepackage{amsmath}
\setbeamercolor{math text}{fg=blue}

\begin{document}
\begin{frame}
This is a term in math mode: $a^2 + b^2 = c^2$.

This is color inside of \texttt{align*}, but the text is colored as well:
\begin{align*}
a^2 + b^2 = c^2 && \text{(Pythagoras)}. \\
\intertext{Even worse, the intertext is colored as well:}
a^1 + b^1 = c^1 && \text{(me)}.
\end{align*}
\end{frame}
\end{document}


And it produces this output:

Update: @Mico has provided a nice solution that works well, even for inline-math in \intertext, but it colors tables as well! Can that be avoided?

Plus, \text does switch back to black, but math in \text then stays black. Have a look at the \text with $x$ in \underbrace.

Here is an updated MWE:

\documentclass{beamer}

%\setbeamercolor{math text}{fg=blue}
%\newcommand\blackintertext[1]{\intertext{\textcolor{black}{#1}}}

\everymath=\expandafter{\the\everymath\color{blue}}
\let\origtext\text
\renewcommand\text[1]{\origtext{\textcolor{black}{#1}}}

\begin{document}
\begin{frame}
This is a term in inline-math mode: $1+1=2$.

Displayed equations are colored as well \dots
\begin{align*}
\underbrace{a^2 + b^2}_{\text{magic $x$}} &= c^2 \tag{Pythagoras} \\
\intertext{\dots\ but, happily, intertext material is no longer colored. Even $\pi \approx 3.14$ is colored.}
e^{i\pi} + 1 &= 0 \tag{Euler}
\end{align*}
\begin{tabular}{l|l}
\hline
a    & table?
\end{tabular}
\end{frame}
\end{document}


This is what it looks like:

• just define a command say \newcommand\blackintertext[1]{\intertext{\textcolor{black}{#1}} and use that instead of \intertext – David Carlisle Sep 3 '19 at 13:57
• @DavidCarlisle: simple solution, but then math in \intertext is no longer colored! – cxxl Sep 4 '19 at 12:57
• I don't see why not, the nested math should trigger your \everymath setting to make the nested math blue – David Carlisle Sep 4 '19 at 13:00
• @DavidCarlisle If you use the MWE and toggle the comment chars on the \blackintertext instead of the \everymath you can verify it. Plus, the tags are in blue as well. But the table is OK :) – cxxl Sep 4 '19 at 14:33

I suggest you replace

\setbeamercolor{math text}{fg=blue}


with

\everymath=\expandafter{\the\everymath\color{blue}}


Moreover, to typeset equation "tags", use the \tag macro.

To "fix" the behavior of the \text macro, i.e., to make it output its argument in black, I suggest you add the following two instructions to the preamble:

\let\origtext\text
\renewcommand\text[1]{\origtext{\textcolor{black}{#1}}}


Here's the code that generates the screenshot shown above:

\documentclass{beamer}

%\setbeamercolor{math text}{fg=blue}
\everymath=\expandafter{\the\everymath\color{blue}}

\begin{document}
\begin{frame}
This is a term in inline-math mode: $1+1=2$.

Displayed equations are colored as well \dots
\begin{gather*}
a^2 + b^2 = c^2 \tag{Pythagoras} \\
\intertext{\dots\ but, happily, intertext material is no longer colored.}
e^{i\pi} + 1 = 0 \tag{Euler}
\end{gather*}
\end{frame}
\end{document}

• That is a nice solution, but now tabular environments are colored as well. See above for a new MWE. – cxxl Sep 4 '19 at 12:56
• @cxxl use \begin{tabular}[t]{lll} the [t] should avoid math mode – David Carlisle Sep 4 '19 at 13:02
• @DavidCarlisle Unfortunately, it doesn't. The table is still blue. – cxxl Sep 4 '19 at 14:19
• @cxxl probably beamer doing something weird:-) sorry can't test at present – David Carlisle Sep 4 '19 at 15:09
• @DavidCarlisle - I just checked if the tabular color anomaly happens in the article document class as well (in addition to the beamer class) -- and it does. :-( It happens both with \everymath=\expandafter{\the\everymath\color{blue}} (as practiced above) and with \everymath{\color{blue}}. I have no idea what might be going on. – Mico Sep 4 '19 at 16:54