1

I'm having trouble with the listings package. I can't compile the following minimal example through pdfLaTeX:

\documentclass[a4paper, 11pt, twoside, openright, english]{memoir}

\usepackage{listings}

\newenvironment{haskellCode}
{%
  \begin{lstlisting}%
}
{%
  \end{lstlisting}%
}

\begin{document}
\begin{haskellCode}
  test
\end{haskellCode}
\end{document}

The compilation process just stops and appears to ask me for input:

* <The hell? I'll just try pressing ENTER then...>
(Please type a command or say `\end')
*

But if I move the code in haskellCode directly into the document (i.e. use lstlisting directly) it compiles fine.

Any idea what's happening and how I can fix it?

gablin
  • 17,006

1 Answers1

5

The lstlisting environment is in many respects similar to the verbatim environment and TeX has to "see" explicitly the \end{lstlisting} to know it's finished.

The solution is to use \lstnewenvironment:

\lstnewenvironment{haskellCode}{}{}

is what you need; of course you can add many customizations to the "start" and "end" parts.

egreg
  • 1,121,712