I'm using the listing package for displaying source code in my document.
I want to use the minipage environment to avoid page breaks within the listing, but I don't want to write, at every listing,
\begin{minipage}{\linewidth}
\begin{lstlisting}
... code goes here ...
\end{lstlisting}
\end{minipage}
I've tried to define a new environment, like so
\newenvironment{codeListing}{\begin{minipage}{\linewidth}\begin{lstlisting}}{\end{lstlisting}\end{minipage}}
for using it like this
\begin{codeListing}
... my code ...
\end{codeListing}
What am I doing wrong?
\documentclass{...}and ending with\end{document}. – Jan 19 '15 at 22:16listingspackage provides\lstnewenvironmentfor such cases. Try\lstnewenvironment{codeListing}{\minipage{\linewidth}}{\endminipage}– cgnieder Jan 19 '15 at 22:19\newenvironmentno longer works, you should use\lstnewenvironment. – ollydbg23 Jan 22 '22 at 10:25