TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}




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?

share|improve this question
up vote 5 down vote accepted

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:


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

share|improve this answer
Ah, I see! Thanks! – gablin Sep 6 '11 at 9:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.