我使用下列方法更改方程的颜色:
\documentclass{article}
\usepackage{xcolor}
\everymath=\expandafter{\the\everymath\color{blue}}
\AtBeginEnvironment{equation}{\color{blue}}
\AtBeginEnvironment{equation*}{\color{blue}}
\begin{document}
$inside\;math$
\begin{equation}
inside\;math\;equation
\end{equation}
\begin{tabular}{c}
inside tabular
\end{tabular}
\end{document}
方程的颜色发生了变化,但 Tikz 图像中的表格和某些线条的颜色也发生了变化。我做错了什么?如何防止其他所有内容改变颜色?
编辑
根据@DavidCarlisle 的回答,这里有一个解决 $...$ 符号内部颜色变化问题的方法,即将它们重新定义为 \(...\)。欢迎改进和更正。
\documentclass{article}
\usepackage{xcolor}
% change color inside equation environment
\AtBeginEnvironment{equation}{\color{blue}}
\AtBeginEnvironment{equation*}{\color{blue}}
% change color of math inside \(...\) and \[...\]
\AddToHook{cmd/(/after}{\color{blue}}
\AddToHook{cmd/[/after}{\color{blue}}
% redefine $...$ as \(...\)
\begingroup
\catcode`\$=\active
\protected\gdef$#1${\(#1\)}
\endgroup
\AtBeginDocument{\catcode`\$=\active}
\begin{document}
A possible trick is to change all $\$\;math\;\$$ to \(\setminus(math\setminus)\).
\begin{equation}
inside\;math\;equation
\end{equation}
\begin{tabular}{c}
inside tabular
\end{tabular}
\end{document}
答案1
\everymath
捕获所有内部数学模式,包括大多数垂直居中的构造,例如tabular
,minipage
。
\documentclass{article}
\usepackage{xcolor}
\AtBeginEnvironment{equation}{\color{blue}}
\AtBeginEnvironment{equation*}{\color{blue}}
\AddToHook{cmd/(/after}{\color{blue}}
\begin{document}
\(inside\;math\)
\begin{equation}
inside\;math\;equation
\end{equation}
\begin{tabular}{c}
inside tabular
\end{tabular}
\end{document}