I would like to redefine a short command (without \begin ... \end) for single line code examples using the listings package.
Here is what I tried:
\documentclass{article}
\usepackage{listings}
\newcommand{\my}[1]{
\begin{lstlisting}
#1
\end{lstlisting}
}
\begin{document}
\my{code}
\end{document}
However, it gives the following error:
! Emergency stop.
<*> example.tex
*** (job aborted, no legal \end found)
Using lstlisting directly works, though:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
code
\end{lstlisting}
\end{document}