Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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:

\lstnewenvironment{haskellCode}{}{}

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

 
discard

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.