如何接受 sty 文件中的输入?

如何接受 sty 文件中的输入?

我有一个麦粒肿该文件允许我创建定义框。我的代码如下所示

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{itaewon}[2021/02/21 Boxed for Definition,Theorems etc.]

\RequirePackage[most]{tcolorbox}

\newtcolorbox[auto counter,number within=subsection]{DefinitionBox}[3][]{
        arc=5mm,
        lower separated=false,
        fonttitle=\bfseries,
        colbacktitle=blue!10,
        coltitle=blue!50!black,
        enhanced,
        attach boxed title to top left={xshift=0.5cm,
                yshift=-2mm},
        colframe=blue!50!black,
        colback=blue!10,
        overlay={
        \node[draw=blue!50!black,thick,
        %inner sep=2mm,
        fill= blue!10,rounded corners=1mm, 
        yshift=0pt, 
        xshift=-0.5cm, 
        left, 
        text=blue!50!black,
        anchor=east,
        font=\bfseries] 
        at (frame.north east) {#3};},
        overlay={
        \node[draw=blue!50!black,thick,
        %inner sep=2mm,
        fill= blue!10,rounded corners=1mm, 
        yshift=0pt, 
        xshift=-0.5cm, 
        left, 
        text=blue!50!black,
        anchor=east,
        font=\bfseries] 
        at (frame.north east) {#3};},
        title=#2 \thetcbcounter,#1
                                }

我想要某种逻辑,即当标题是{TheoremBox}我想要的colbacktitle=green!10

答案1

这是你想要的?

\documentclass{scrartcl}
\usepackage[most]{tcolorbox}

\newcommand{\DefineBoxFor}[2][black]{
    \expandafter\newtcolorbox[auto counter,number within=subsection]{#2Box}[3][]{
            arc=5mm,
            lower separated=false,
            fonttitle=\bfseries,
            colbacktitle=#1!10,
            coltitle=#1!50!black,
            enhanced,
            attach boxed title to top left={xshift=0.5cm,
                    yshift=-2mm},
            colframe=#1!50!black,
            colback=#1!10,
            overlay={
            \node[draw=#1!50!black,thick,
            %inner sep=2mm,
            fill= #1!10,rounded corners=1mm, 
            yshift=0pt, 
            xshift=-0.5cm, 
            left, 
            text=#1!50!black,
            anchor=east,
            font=\bfseries] 
            at (frame.north east) {##3};},
            overlay={
            \node[draw=#1!50!black,thick,
            %inner sep=2mm,
            fill= #1!10,rounded corners=1mm, 
            yshift=0pt, 
            xshift=-0.5cm, 
            left, 
            text=#1!50!black,
            anchor=east,
            font=\bfseries] 
            at (frame.north east) {##3};},
            title=##2 \thetcbcounter,##1
        }
}
\DefineBoxFor[blue]{Definition}
\DefineBoxFor[green]{Theorem}
%
\begin{document}

\begin{DefinitionBox}{Definition}{description}
    Some text
\end{DefinitionBox}

\begin{TheoremBox}{Theorem}{description}
    Some text
\end{TheoremBox}

\end{document}

此处的命令\DefineBoxFor用于定义...Box环境。例如,在上面的代码中,

\DefineBoxFor[blue]{Definition}
\DefineBoxFor[green]{Theorem}

定义DefinitionBoxTheoremBox,颜色分别为蓝色和绿色(##1,##2,##3是环境参数...Box)。这比分别定义它们更简单。

结果如下:

在此处输入图片描述

相关内容