答案1
当前颜色存储在.
(颜色上下文中)。数学模式中的大小由以下方式选择\mathchoice
(请参阅的奥秘\mathpalette
\documentclass[varwidth]{standalone}
\usepackage[theorems]{tcolorbox}
\newcommand{\mymath}[2][]{%
\mathchoice%
{\tcboxmath[colback=blue!20,colupper=.,size=minimal]{\displaystyle#2}}%
{\tcboxmath[colback=blue!20,colupper=.,size=minimal]{\textstyle#2}}%
{\tcboxmath[colback=blue!20,colupper=.,size=minimal]{\scriptstyle#2}}%
{\tcboxmath[colback=blue!20,colupper=.,size=minimal]{\scriptscriptstyle#2}}%
}
\begin{document}
\[\color{red}Z^{\mymath{x^2+1}} \qquad Z^{x^2+1}\]
\end{document}