定义“tcolorbox”环境时避免重复代码

定义“tcolorbox”环境时避免重复代码

有没有办法分解以下代码,其中环境doclatex和之间的唯一区别doclatex-flat在于使用listing side text

\documentclass[12pt]{article}

\RequirePackage{tcolorbox}

\tcbuselibrary{minted, breakable}

\newtcblisting{doclatex}{%
    breakable,
    sharp corners,
    left   = 1mm, right = 1mm,
    bottom = 1mm, top   = 1mm,
    listing side text
}

\newtcblisting{doclatex-flat}{
    breakable,
    sharp corners,
    left   = 1mm, right = 1mm,
    bottom = 1mm, top   = 1mm,
}

\begin{document}

\begin{doclatex}
$just + A = test$
\end{doclatex}

\begin{doclatex-flat}
$just + A = test$
\end{doclatex-flat}

\end{document}

答案1

tcolorbox的 key-val 方案来自pgfkeys,它由 或 自动加载pgf。因此,您可以使用键处理程序tikz定义样式键。/.style

\documentclass[12pt]{article}

\RequirePackage{tcolorbox}

\tcbuselibrary{minted, breakable}

\tcbset{
    doc latex common/.style={
        breakable,
        sharp corners,
        left   = 1mm, right = 1mm,
        bottom = 1mm, top   = 1mm,
    }
}

\newtcblisting{doclatex}{%
    doc latex common,
    listing side text
}

\newtcblisting{doclatex-flat}{
    doc latex common,
    bottom = 1mm, top   = 1mm,
}

\begin{document}

\begin{doclatex}
$just + A = test$
\end{doclatex}

\begin{doclatex-flat}
$just + A = test$
\end{doclatex-flat}

\end{document}

相关内容