I am writing a document that contains parts of an compiler interpreter session (GHCi in this case, but this is not relevant). I have a carefully setup style for Haskell code that I would like to use there. But the prompt and especially the output is not Haskell code and should be printed differently.

Here is an example:

Prelude> let fibs = 0:1:zipWith (+) fibs (tail fibs) in fibs !! 10

What is the most elegant way to apply different style to what follows the Prelude > and the rest?

  • I tried to capture the code with escapeinsinde and use escapebegin and escapeend to start a new listing environment, but unfortunately that just loops. Commented Aug 30, 2012 at 12:54
  • Ok, that is one step. But what about the output, i.e. all lines not starting with Prelude>? Commented Sep 5, 2012 at 7:11
  • I know about morekeywords, but I also want every line not starting with Prelude> to be style differently from the code following Prelude> – in the above example, the 55. Commented Sep 5, 2012 at 13:45

2 Answers 2


One approach would be to use the moredelim option to apply a different formatting (and kill syntax highlighting) on certain parts:





@Prelude>@ let fibs = 0:1:zipWith (+) fibs (tail fibs) in fibs !! 10


enter image description here

A possible disadvantage is that you have to do this "by hand". For the Prelude> part you may use the morekeywords option to automatically apply its style, but for the lines not starting with Prelude> this will be more difficult.

  • Regarding automation: Maybe a simple sed script to apply the delimiter around all lines not starting with Prelude> would suffice?
    – Daniel
    Commented Oct 5, 2012 at 18:20
  • Thanks for the suggestion. I guess once I start modifying the highlighted code, I can just put the haskell stuff in lstinline and format the rest using \ttfamily. Commented Oct 6, 2012 at 17:42

Here is a partial answer that is sufficient for my use case, e.g. formatting only the commands and leaving the rest verbatim:




\def > ##1^^M{\char`\>{} \lstinline!##1!\par}%
\def ^^M{\par}%


*Count> let s = "hello stackexchange"
*Count> let x = count 0 [0..100000000]
*Count> x
Just *** Exception: stack overflow

This produces the following output

enter image description here

It is still not entirely satisfying, as I cannot use lstlistings’s frame options, which I had to imitate using the nice adjustbox package. Also, it breaks if there is a > in the output somewhere, but that is something I can live with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .