I'm having some trouble changing the colors of parts of an equation in Beamer, with "math text" being set. The following MWE demonstrates the example:
\documentclass{beamer}
\usepackage{color}
\setbeamercolor{math text}{fg=blue}
\begin{document}
\begin{frame}{Frame}
$x \alert{\cong} y \alert{=} z$ \\
$x \textcolor{green}{\cong} y \textcolor{green}{=} z$ \\
$x {\setbeamercolor{math text}{fg=green}{\cong}} y {\setbeamercolor{math text}{fg=green}{=}} z$
\end{frame}
\end{document}
I would expect both symbols in the first and second line to get colored. However, for some reason, \cong is not colored, but = is. Is there some way to make coloring work reliably with all math symbols?
I found another Stackexchange question (Changed all math text to red in beamer, now I can't make some math text black) where people suggested the code I used in the third line - which, confusingly, works for \cong, but not for =.
For now, I replaced \cong by \stackrel{\sim}{=}, but really that's just a work-around, and if this ever happens with a symbol I cannot reconstruct otherwise, I'll be in trouble.
\textcolorinside math, it messes up the spacing, see e.g. http://tex.stackexchange.com/a/261480/36296 for an alternative. However this also has your problem with\cong. – samcarter_is_at_topanswers.xyz Aug 30 '15 at 18:49alert. I'd also need to figure out the actual color beamer is using here. Is there a macro to fetch that? – Ralf Jung Aug 30 '15 at 23:07\newcommand<>\mathalert[1]{{\only#2{\usebeamercolor{alerted text}\color{fg}\setbeamercolor{math text}{fg=fg}}#1}}%. Thanks! – Ralf Jung Aug 30 '15 at 23:20