0

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?

jub0bs
  • 58,916
tihox1
  • 33
  • 1
  • 3
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jan 19 '15 at 22:16
  • 4
    The listings package provides \lstnewenvironment for such cases. Try \lstnewenvironment{codeListing}{\minipage{\linewidth}}{\endminipage} – cgnieder Jan 19 '15 at 22:19
  • \newenvironment no longer works, you should use \lstnewenvironment. – ollydbg23 Jan 22 '22 at 10:25

0 Answers0