listings with background color and mathescape broken

The problem seems to be that listings expects a constant line height, and that \vdots just takes up too much vertical space. One fix is to redefine \vdots so that it takes up less vertical space:

\renewcommand\vdots{%
  \vbox{\baselineskip3pt\lineskiplimit0pt\kern1pt\hbox{.}\hbox{.}\hbox{.}\kern-1pt}}


\documentclass{book}
\usepackage{color}
\definecolor{grey}{gray}{0.9}
\usepackage{listings}

\lstset{%
language=Lisp,
basicstyle=\small,
backgroundcolor=\color{grey},
mathescape=true}

\begin{document}
\begin{lstlisting}
(let ((<$var_1$> <$exp_1$>)
      (<$var_2$> <$exp_2$>)
      $\makebox(0,7.5){\vdots}$
      (<$var_n$> <$exp_n$>))
   <$body$>))
\end{lstlisting}
\end{document}

Tags:

Listings