0

I have a custom listing defined as follows:

\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},
}

And I created an ``exercise'' macro which takes two arguments: a chapter reference label and text to insert afterwards.

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

Used in the following manner:

\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, .........}

The issue is that I can't seem to pass a listing as an argument to a macro? I'm not sure if what I'm asking to do is possible, but it would be extremely convenient if so! Are arguments to a command simply substituted in, or are they evaluated beforehand (which wouldn't make sense when talking about a traditional macro).

TheProgrammer
  • 404
  • 2
  • 11

0 Answers0