将列表作为参数传递给命令?

将列表作为参数传递给命令?

我有一个自定义列表定义如下:

\newtcblisting[auto counter, number within=chapter]{MyCListing}[2][]{%
    enhanced,
    frame hidden, 
    breakable,
    borderline north = {0.5pt}{0pt}{black},
    borderline south = {0.5pt}{0pt}{black},
    opacityfill=0,
    listing only,
    top=-5pt,bottom=-5pt,left=0pt,right=0pt,
    listing options={
        basewidth=0.5em,
        commentstyle=\color{orange},
        keywordstyle=\color{blue},
        stringstyle=\color{red},
        morekeywords={NULL},
        language=C,
        basicstyle=\small\ttfamily,
        breaklines=true,
        showstringspaces=false,
        escapeinside={(*;}{;*)},
        literate={~}{{\fontfamily{ptm}\selectfont \textasciitilde}}1
    },
    title={\textcolor{black}{Listing \thetcbcounter\ifstrempty{#2}{}{---#2}\ifstrempty{#1}{}{~(\texttt{#1})}}},
    attach boxed title to top center={xshift=-3.55mm,yshift=-0.4mm},
    boxed title style={frame hidden,colback=black!0!white},
    minted language=c,
    minted options={autogobble},
}

我创建了一个“练习”宏,它接受两个参数:章节参考标签和之后要插入的文本。

\newcommand{\exercise}[2]
{\noindent\textbf{Exercise {~\ref{#1}}.\theexcounter.} {#2} \stepcounter{excounter}}

按以下方式使用:

\exercise{chapter-interpretation1}{The \texttt{strcpy} .....

\begin{MyCListing}[main.c]{\texttt{strcpy} is Unsafe!}
#include <string.h>

int
main(int argc, char *argv[]) {
    char buffer[8];
    strcpy(buffer, "Hello world how are you doing?");
    return 0;
}
\end{MyCListing}

The problem is that \texttt{strcpy} has no bounds checking and, .........}

问题是我似乎无法将列表作为参数传递给宏?我不确定我要求做的事情是否可行,但如果可行的话会非常方便!命令的参数是简单地替换,还是事先进行评估(这在谈论传统宏时没有意义)。

相关内容