This code fails with Emergency stop:
\documentclass{scrbook}
\usepackage{listings}
\newcommand{\demo}{%
\begin{lstlisting}
foobar
\end{lstlisting}
}
\begin{document}
\demo
\end{document}
Why?
|
In your code the whole However, the Now, when the code is already read as part of a macro argument all catcodes have already be assigned to the characters and some have already be transformed as mentioned above, so that the changes made by the verbatim environment afterwards when it is executed do not have any effects any longer. In general there is the rule that verbatim material can't be used inside a macro argument or pseudo-environment (an environment which reads its whole content, see e.g. the |
|||
|
|
|
The
As such, the following works:
This does not answer your question, but instead provides a different work-around, if you're interested. Not sure how effective this is in general, but you can store an
|
|||||||||
|
lstlistinghas to play with category codes and putting it into the definition of a command inhibits category code changes. – egreg Sep 29 '11 at 20:55