数学颜色也适用于 \text{} 和 \intertext{}

数学颜色也适用于 \text{} 和 \intertext{}

我有一个 LaTeX 投影仪演示文稿,我用它\setbeamercolor{math text}来增强可读性,效果很好。不幸的是,所有\text{}内容\intertext{}都是彩色的,看起来不太好看。有什么补救措施吗?

梅威瑟:

\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}

它产生以下输出:

在此处输入图片描述

更新:@Mico 提供了一个很好的解决方案,效果很好,甚至适用于 inline-math \intertext,但它也会为表格着色!可以避免吗?

另外,\text确实切换回黑色,但数学\text保持黑色。看看\text里面$x$\underbrace

以下是更新的 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}
What & about \\
\hline
a    & table?
\end{tabular}
\end{frame}
\end{document}

它看起来是这样的:在此处输入图片描述

答案1

我建议你更换

\setbeamercolor{math text}{fg=blue}

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

此外,要排版方程式“标签”,请使用\tag宏。

在此处输入图片描述

为了“修复”宏的行为\text,即使它以黑色输出其参数,我建议您在序言中添加以下两个指令:

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

以下是生成如上所示截图的代码:

\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}

相关内容