我的目标是让enca
下面的命令在数学和文本模式下使用蓝色。最好的方法是什么?
\documentclass{scrartcl}
\usepackage[skins,breakable,xparse,many]{tcolorbox}
\usepackage{xcolor}
%BOX
\NewDocumentCommand{\enca}{ O{black} m }{%
\ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,extras={colupper={tcbcolback}},colframe=#1,size=fbox]{#2}\else
\tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,extras={colupper={tcbcolback}},colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
}
%
\begin{document}
{\color{blue}
ABCEE \enca{ABCDE},
\[ 1 +\enca{\int_1^2 x^2 \mathrm{d} x}.\]
}
\end{document}
答案1
也许您可以保存当前颜色并应用到颜色框,例如:
\NewDocumentCommand{\enca}{ O{black} m }{%
\colorlet{temp}{.}% Save the current color to temp
\ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,colupper=temp,colframe=#1,size=fbox]{#2}\else
\tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,colupper=temp,colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
}
完整示例:
\documentclass{scrartcl}
\usepackage[skins,breakable,xparse,many]{tcolorbox}
\usepackage{xcolor}
%BOX
\NewDocumentCommand{\enca}{ O{black} m }{%
\colorlet{temp}{.}%
\ifmmode\tcboxmath[standard jigsaw, tcbox raise base,opacityback=0,tcbox width=auto limited,colupper=temp,colframe=#1,size=fbox]{#2}\else
\tcbox[standard jigsaw, tcbox raise base,tcbox width=auto limited,opacityback=0,colupper=temp,colframe=#1,size=fbox,nobeforeafter]{#2}\fi%
}
%
\begin{document}
{\color{blue}
ABCEE \enca[red]{ABCDE},
\[ 1 +\enca[red]{\int_1^2 x^2 \mathrm{d} x}.\]
}
\end{document}
生成结果: