I get strange errors with the last versions of mdframed (v 1.4) and listings (v 1.4). Here is a minimal example:



The error I get is

You can't use \prevdepth in horizontal mode.

which I don't really understand... Any pointer as to what is going on would be greatly appreciated.

  • Seems to be a bug. As a temporary workaround you can put the lstlisting within \begin{minipage}{\linewidth} ... \end{minipage}. Mar 22, 2012 at 21:44
  • 2
    Another workaround is to add the line \makeatletter\let\par\@@par\makeatother just below \end{lstlisting} (it seems that this environment doesn't reset \par to its expected value).
    – egreg
    Mar 22, 2012 at 22:13
  • @PeterGrill: In this case the contents of listings can't be splitted. Mar 23, 2012 at 12:44
  • @MarcoDaniel: Yep, that's why it was intended as a temporary workaround. I should have made a note of that in the original comment. Mar 23, 2012 at 14:58

2 Answers 2


As @egreg wrote in the comment it seems that listings changed the internal definition of \par without reseting. However based on great comments of @DavidCarliste and @egreg in the chat I fixed the problem.

Please try the new version on github.

With the new version I get 0 errors and the following result:

enter image description here

  • Perhaps my answer above was too lukewarm: HUGE thanks to you for being so responsive! :-)
    – Olivier
    Mar 24, 2012 at 8:41
  • @Olivier: No problem ;-) Mar 24, 2012 at 8:43

If you comment the line no 752 in mdframed, the file is compiling:

Comment the below mentioned:

\par\unskip\nointerlineskip\hrule \@height\z@ \@width\hsize
  • 2
    This would break many other things.
    – egreg
    Mar 23, 2012 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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