I tried to define a macro, for me to quickly create a listing environment. The definition looked like that:
% \def \lstlistingcode[#1] { \begin{lstlisting}#1\end{lstlisting} }
which ends in an Error:
job aborted, no legal \end found
Is it possible to use environments within macros, and if yes - how?
Some environments can, e.g. alltt; however, lstlisting can't, because of how it is written (it apparently has to do with various catcode stuff that it does).
Using \def as you do is sort of outdated; \newcommand is preferred:
\newcommand \allttcode[1] { \begin{alltt}#1\end{alltt} }
...
\allttcode{test}