I am trying to do a new environment or command (i tried both) where i can put in the name, description and code of a Method in c++ and it gives me a new section with the MethodName, the code listed and the description below. But i am not able to use the listings environment in a new command or new environment.. Consider my MWE
\documentclass[a4paper,11pt]{article}
\usepackage{listings}
\newcommand{\method}[3]
{
\section{#1}\label{#1}
\begin{lstlisting}
#2
\end{lstlisting}
#3
}
\begin{document}
\method{MethodName}{Method Void MethodName()}{Description of the Method blablabla}
\end{document}
How can I fix this?
I would prefer to do it using a macro since I don't need an ending.
lstlistings(or any other verbatim-like environment) inside another command, you have to use dedicated approaches. Also, you really need to use an environment rather than a command for verbatim to work. – Joseph Wright Jul 02 '13 at 07:28\lstnewenvironmentapproach will work just fine. You cannot wrap listings environments like that anyway. Besides,\macro{}{}{}makes the source code very hard to read. Environments provide a much better structure. – daleif Jul 02 '13 at 07:51}itself a macro solution would be possible, if you don't read the verbatim material as macro argument. For example\newcommand{\method}[1]{\section{#1}\label{#1}\lstinlinewould do it for this particular MWE. Here the second argument is read by\lstinlineand the third argument is just kept as is. However, if as soon you want to modify the material after the verbatim it's getting complicated, because you need to execute a macro after the\lstinline. I will have a look later at home at it. – Martin Scharrer Jul 02 '13 at 07:56xparseto handle things, but even then I'm wary. – Joseph Wright Jul 02 '13 at 07:58\lstinlineor store the verbatim content yourself first with the same catcodeslistingsuses e.g. using mynewverbspackage. – Martin Scharrer Jul 02 '13 at 08:06