I have been following this topic about using \NewDocuentCommand
with lstlisting
and the accepted answer is nice except it is too big and it doesn't quite work for me.
I came up with this example to test xparse
:
\documentclass{article}
\usepackage{xparse}
\usepackage{listings}
\ExplSyntaxOn
\NewDocumentCommand{\code}{m +v}{
\begin{lstlisting}[style=#1,numbers=none,xleftmargin=0.35cm,framesep=0mm]
#2
\end{lstlisting}
}
\ExplSyntaxOff
\begin{document}
\code{C}{
int x = 200;
unsigned int y = 0;
}
\end{document}
Like stated in the CTAN xparse documentation I first used m
as a normal parameter and then +v
as a multiline verbatim parameter, but it fails. It looks like I am still missing something...
\lstnewenvironment
instead.