I have lots of C++ sources with LaTeX formulas in the comments. Ideal for using the listings packages to pretty print the source. However, most of the formulas break either, the background or the frame lines when the formula is "tall" (e.g. contains an integral or a sum) as seen in the following working example and preview. The question is: how can I force listing not to break the frame on tall lines produced by tall math equations?
\documentclass{article}
\usepackage[]{listings}
\usepackage{xcolor}
\lstset{
backgroundcolor=\color[gray]{0.9},
frame=single,
mathescape=true,
}
\lstset{language=C++}
\begin{document}
\begin{lstlisting}
for(i = 0; i < 10; i++)
{
// gratuitious equation $\mathcal{D}_3(x) = \frac{x^n}{n} \int_{0_0}^{x^2} \frac{t^n}{e^t-1}dt$
*p++ = i;
House h = new house();
int romms = h.getRooms():
}
\end{lstlisting}
\end{document}

Note: If this is an intrinsic limitation of listings packages, then the real question could be how can equations be force to use the normal vertical space as much as possible in math mode. For example to force integrals and sums to be even shorter than inline math model.
I am also aware of this other question: listings with background color and mathescape broken, but that only solved for a particular math symbol.

