Странное поведение с оповещением в математическом режиме

Странное поведение с оповещением в математическом режиме

Я получил это неожиданное поведение, когда я изменил цвет на alerted textв mathmode. В частности, alerted text.fgкажется, меняется только когда \alertвызывается снова. Изменение с \colorletвлияет только на цвет внутри mathmode.

Вот пример

\documentclass{beamer}
\begin{document}    
\begin{frame}{Title}
    $\begingroup\setbeamercolor{alerted text}{fg=blue}\alert{blue}\endgroup+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}
    
    $\begingroup\setbeamercolor{alerted text}{fg=blue}\alert{blue}\endgroup\setbeamercolor{alerted text}{fg=red}+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}
    
    $\begingroup\setbeamercolor{alerted text}{fg=blue}\alert{blue}\endgroup\setbeamercolor{alerted text}{fg=red}\colorlet{alerted text.fg}{red}+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}
    
    $\begingroup\setbeamercolor{alerted text}{fg=blue}\alert{blue}\endgroup\setbeamercolor{alerted text}{fg=red}\alert{}+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}
\end{frame}

\end{document}

решение1

\setbeamercolor{}{}сам по себе еще не создает цвета .fgи .bg, они создаются только при использовании цвета проектора.

Но вместо того, чтобы менять цвет оповещения туда-сюда, вы можете создать больше макросов, похожих на оповещения, с любым цветом, который вам нравится, или просто использовать \structure, который по умолчанию синий.

\documentclass{beamer}

\setbeamercolor{foo}{fg=green}

\newenvironment<>{fooenv}{\begin{altenv}#1%
    {\usebeamercolor[fg]{foo}\usebeamerfont{foo}\usebeamertemplate{foo text begin}}
    {\usebeamertemplate{foo text end}}{\color{.}}{}\ignorespaces}{\ifhmode\unskip\fi\end{altenv}}

\newcommand<>{\foo}[1]{\begin{fooenv}#2\relax#1\end{fooenv}}


\begin{document}    
\begin{frame}{Title}
    $\structure{blue}+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}
    
    $\foo{green}+\textcolor{alerted text.fg}{red}$  These should be \textcolor{alerted text.fg}{red}, \alert{red} and \textcolor{alerted text.fg}{red}    

\end{frame}

\end{document}

введите описание изображения здесь

Связанный контент