有条件地向 tcolorbox 突出显示数学样式添加选项

有条件地向 tcolorbox 突出显示数学样式添加选项

我已经定义了以下包:

% Configuration
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{eqbox}[2018/01/01 Boxed Equations]
\RequirePackage{xcolor}
\RequirePackage{pgfopts}
\RequirePackage{amsmath}
\RequirePackage{fancybox}
\RequirePackage[most]{tcolorbox}

% Package options
\pgfkeys{
    /eqbox/.cd,
    colframe/.store in = \colframe,
    colframe = ,
    colback/.store in = \colback,
    colback = white,
    shadow/.store in = \shadow,
    shadow = ,
}
\ProcessPgfPackageOptions{/eqbox}

% Main style
\tcbset{
    highlight math style={
        enhanced,
        sharp corners,
        breakable,
        boxrule = 0.4pt,
        boxsep = 3pt,
        left = 0pt,
        right = 0pt,
        top = 0pt,
        bottom = 0pt
    }
}

% Conditional styles
\ifx\colframe\empty\else\tcbset{colframe = \colframe}\fi
\ifx\colback\empty\else\tcbset{colback = \colback}\fi
\ifx\shadow\empty\else\tcbset{shadow = {2pt}{-2pt}{0mm}{\shadow}}\fi

其工作原理是,首先定义一个主要样式。然后,如果用户在加载包时提供他们的选项(例如\usepackage[shadow=blue]{eqbox}),则将添加选项。

问题是,在当前版本中,全局的tcolorbox colframecolbackshadow参数已更改。相反,我想更改highlight math style colframecolbackshadow。但是如果我写:

% Conditional styles
\ifx\colframe\empty\else\tcbset{highlight math style = {colframe = \colframe}}\fi
\ifx\colback\empty\else\tcbset{highlight math style = {colback = \colback}}\fi
\ifx\shadow\empty\else\tcbset{highlight math style = {shadow = {2pt}{-2pt}{0mm}{\shadow}}}\fi

似乎忘记了之前定义的主要highlight math style选项,而只是设置了相关的条件选项。如何实现这一点?

注意:用例:

\documentclass[letterpaper, 11pt, onecolumn]{article}

\usepackage{lipsum}
\usepackage[colback = blue]{eqbox}

\begin{document}
\lipsum[1]
\begin{equation}
\tcbhighmath{x^2 + 3}
\end{equation}
\lipsum[1]
\end{document}

答案1

根据我阅读tcolorbox手册的方式,/tcb/highlight math style={...}这是 的快捷方式/tcb/highlight math/.style={...},因此正如您所说,这会覆盖样式。因此我怀疑您想要的是/tcb/highlight math/.append style={...},并建议将样式文件的最后三行替换为

\ifx\colframe\empty\else\tcbset{highlight math/.append style={colframe=\colframe}}\fi
\ifx\colback\empty\else\tcbset{highlight math/.append style={colback=\colback}}\fi
\ifx\shadow\empty\else\tcbset{highlight math/.append style={shadow={2pt}{-2pt}{0mm}{\shadow}}}\fi

相关内容