is it possible to create a lstlisting environment which is numbered and where I get a listof command?
My try:
Code: Select all
Code, edit and compile here:
\documentclass{book}\usepackage{xparse,tocloft,listings}\newcommand{\codelist}{Codelist}\newlistof{code}{cod}{\codelist}\NewDocumentEnvironment{code}{m}{\begin{lstlisting}\refstepcounter{code}\addcontentsline{cod}{code}{\protect\numberline{\thechapter.\thecode}#1}\par}{\caption{#1}\end{lstlisting}}\begin{document}\begin{code}{Caption}Some Code\end{code}\listofcode\end{document}
Does anybody has an idea to fix it or an alternative?! Missing \endcsname inserted.
<to be read again>
\global
l.17 \begin{code}{Caption}