von weltio2 » Di 25. Dez 2012, 17:57
Ich möchte Quellcodes durchnummerieren und ein Verzeichnis dafür anlegen.
Dazu habe ich folgendes gemacht:
\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}
So funktioniert das allerdings nicht, da ich folgendes bekomme:
! Missing \endcsname inserted.
<to be read again>
\global
l.17 \begin{code}{Caption}
Jemand ne Idee?
Ich möchte Quellcodes durchnummerieren und ein Verzeichnis dafür anlegen.
Dazu habe ich folgendes gemacht:
[code]
\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}
[/code]
So funktioniert das allerdings nicht, da ich folgendes bekomme:
[quote]! Missing \endcsname inserted.
<to be read again>
\global
l.17 \begin{code}{Caption}[/quote]
Jemand ne Idee?