tags:

views:

274

answers:

3
+2  Q: 

Latex new command

I would like to define a new command like this

\newcommand{\bob}[1]{\excerpt \begin{lstlisting} {#1} \end{lstlisting}}

and then use it like this

\bob{abcd}

but i get the following error in latex.

text dropped after begin of listing latex

EDIT:

I tried the following

\newcommand{\boy}[1] {{%
\begin{Verbatim} %
{ #1 } %
\end{Verbatim} }}

And I still get an error when I try to use it.

\boy{abc}
+2  A: 

Perhaps you are looking for the \newenvironment macro.

In this case you would use it like this

\newenvironment{bob}{%
\excerpt \begin{lstlisting}}{%
\end{lstlisting}}

and later

\begin{bob}
abcd
\end{bob}
dmckee
+1  A: 

The {listing} environment is special and magical; it can't be used inside a command like that. Changing to a \newenvironment setup as described by dmckee should work. If you can't make that work, check out the fancyvrb package.

Norman Ramsey
I tried the fancyvrb and it did not help solve the problem :-(
Milhous
A: 

Try the lstnewenvironment of the listings package.

pixellator