# Recoloring math in an equation in Beamer

I have a presentation with the color for math changed to blue:

\setbeamercolor{math text}{fg=black!15!blue}


Everything looks nice, until I want to recolor part of an equation:

\begin{align*}
x\ y\ z &: A  \color{red}\longleftarrow \text{Assumptions}\\
\hline
x &\in \color{red}\underbrace{[x,y,z]}_{\text{Goal}}
\end{align*}


Then it just goes bananas: half of the left arrow is printed in blue, and the brace is totally printed in blue.

Any help will be appreciated.

The entire code:

\documentclass{beamer}
\setbeamercolor{math text}{fg=black!15!blue}

\begin{document}
\begin{frame}
\begin{align*}
x\ y\ z &: A  \color{red}\longleftarrow \text{Assumptions}\\
\hline
x &\in \color{red}\underbrace{[x,y,z]}_{\text{Goal}}
\end{align*}
\end{frame}
\end{document}

• Interesting question. Workaround before the proper solution is found: \mathrel{\text{\color{red}$\longleftarrow$}} and \text{\color{red}$\underbrace{[x,y,z]}_{\text{Goal}}$}
– yo'
Mar 20, 2015 at 16:05
• Thanks yo', David, and Joseph. I like David's version better, but thanks Joseph for the nice explanation!
– Beta
Mar 21, 2015 at 17:04

\documentclass{beamer}
\setbeamercolor{math text}{fg=black!15!blue}

\newcommand\beamermathcolor[1]{\color{#1}\setbeamercolor{math text}{fg=#1}}
\begin{document}
\begin{frame}
\begin{align*}
x\ y\ z &: A  \beamermathcolor{red}\longleftarrow \text{Assumptions}\\
\hline
x &\in \beamermathcolor{red}\underbrace{[x,y,z]}_{\text{Goal}}
\end{align*}
\end{frame}
\end{document}


As an alternative to David's answer, you could reset \everymath here

\documentclass{beamer}
\setbeamercolor{math text}{fg=black!15!blue}

\begin{document}
\makeatletter
\begin{frame}
\begin{align*}
\global\everymath{}
x\ y\ z &: A \color{red}\longleftarrow \text{Assumptions}\\
\hline
x &\in \color{red}\underbrace{[x,y,z]}_{\text{Goal}}
\end{align*}
\global\everymath{\beamer@setmathcolor}
\end{frame}
\makeatother
\end{document}


The oddness happens becuase the math color is applied via \everymath, and if you trace through the code some bits of the 'text' use math mode. For example \longleftarrow is made up of various parts, some in math mode and some not.