如何在 tcolorbox 环境中正确使用 \tcbhighmath?

如何在 tcolorbox 环境中正确使用 \tcbhighmath?

如果我在环境\tcbhighmath外使用tcolorbox,它可以正常工作,但如果我在环境\tcbhighmath内使用tcolorbox,它会出错并且无法按预期工作。请查看下面的代码。代码生成附加的图像。知道如何让它在环境内工作吗tcolorbox

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}

\begin{document}

\tcbset{highlight math style={enhanced,%<-- needed for the `remember' options
colframe=blue,colback=red!10!white,boxsep=0pt}} \begin{align*}
\tcbhighmath[remember as=fx]{f(x)}
             &= \int\limits_{1}^{x} \frac{1}{t^2}~dt
              = \left[ -\frac{1}{t} \right]_{1}^{x}\\
             &= -\frac{1}{x} + \frac{1}{1}\\
&= \tcbhighmath[remember,overlay={%
            \draw[red,very thick,->] (fx.south) to[bend right] ([yshift=2mm]frame.west);}]
          {1-\frac{1}{x}.}
        \end{align*}

\begin{tcolorbox}[title=Title]

\tcbset{highlight math style={enhanced,%<-- needed for the `remember' options
colframe=red,colback=red!10!white,boxsep=0pt}} \begin{align*}
\tcbhighmath[remember as=fx]{f(x)}
             &= \int\limits_{1}^{x} \frac{1}{t^2}~dt
              = \left[ -\frac{1}{t} \right]_{1}^{x}\\
             &= -\frac{1}{x} + \frac{1}{1}\\
&= \tcbhighmath[remember,overlay={%
            \draw[blue,very thick,->] (fx.south) to[bend right] ([yshift=2mm]frame.west);}]
          {1-\frac{1}{x}.}
        \end{align*}

\end{tcolorbox}

\end{document}

代码在 tcolorbox 环境之外按预期工作

答案1

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}

\begin{document}

\tcbset{
   highlight math style={
      enhanced,%<-- needed for the `remember' options
      colframe=blue,
      colback=red!10!white,
      boxsep=0pt},
%
   every box on layer 2/.style={ % <---- applied to the nested boxes on layer 2
       highlight math style={
       enhanced,%<-- needed for the `remember' options
       colframe=red,
       colback=red!10!white,
       boxsep=0pt}}} 

\begin{align*}
\tcbhighmath[remember as=fx]{f(x)}
             &= \int\limits_{1}^{x} \frac{1}{t^2}~dt
              = \left[ -\frac{1}{t} \right]_{1}^{x}\\
             &= -\frac{1}{x} + \frac{1}{1}\\
&= \tcbhighmath[remember,overlay={%
            \draw[red,very thick,->] (fx.south) to[bend right] ([yshift=2mm]frame.west);}]
          {1-\frac{1}{x}.}
        \end{align*}
        

\begin{tcolorbox}[title=Title]

 \begin{align*}
\tcbhighmath[remember as=fx]{f(x)}
             &= \int\limits_{1}^{x} \frac{1}{t^2}~dt
              = \left[ -\frac{1}{t} \right]_{1}^{x}\\
             &= -\frac{1}{x} + \frac{1}{1}\\
&= \tcbhighmath[remember,overlay={%
            \draw[blue,very thick,->] (fx.south) to[bend right] ([yshift=2mm]frame.west);}]
          {1-\frac{1}{x}.}
        \end{align*}

\end{tcolorbox}

\end{document}

在此处输入图片描述

相关内容