# How to get \vsplit to separate an equation from the previous line

I've been experimenting with determining the height of lines by using \vsplit to break up a paragraph. I've set pretty much every penalty associated with page breaking to 0. It's not the end of the world if it can't be split off, but I'd like to know why.

\documentclass{article}
\usepackage{amsmath}

\newcounter{count}
\newlength{\size}
\newlength{\total}
\newlength{\prev}

\begin{document}

\setbox0=\vbox{This is the first line of a paragraph, so there is a penalty for
splitting here.  This is the line before a display, so ditto.
$$x=a$$

\noindent\usebox0

\bigskip
\total=\ht0
total height = \the\total

\clubpenalty=0
\widowpenalty=0
\displaywidowpenalty=0
\predisplaypenalty=0
\postdisplaypenalty=0
\interlinepenalty=0

\total=0pt
\loop\prev=\dimexpr \ht0+\dp0\relax
\setbox1=\vsplit0 to \baselineskip
\stepcounter{count}%
\size=\dimexpr \prev-\ht0-\dp0\relax
\thecount{ = }\the\size\par
\ifdim\ht0>0pt\repeat

total height = \the\total

\end{document}

• You have to set the penalties before building the box – egreg Feb 20 '16 at 23:27
• \noindent\begin{document] ? – David Carlisle Feb 21 '16 at 1:31
• @DavidCarlisle -Oops, partial edit. – John Kormylo Feb 21 '16 at 3:21

the penalties are part of the box structure, so changes after the box is set have no effect, setting them earlier produces four lines rather than 3.

\documentclass{article}
\usepackage{amsmath}

\newcounter{count}
\newlength{\size}
\newlength{\total}
\newlength{\prev}

\begin{document}

\clubpenalty=0
\widowpenalty=0
\displaywidowpenalty=0
\predisplaypenalty=0
\postdisplaypenalty=0
\interlinepenalty=0

\setbox0=\vbox{This is the first line of a paragraph, so there is a penalty for
splitting here.  This is the line before a display, so ditto.
$$x=a$$

\usebox0

\bigskip
\total=\ht0
total height = \the\total

\total=0pt
\loop\prev=\dimexpr \ht0+\dp0\relax
\setbox1=\vsplit0 to \baselineskip
\stepcounter{count}%
\size=\dimexpr \prev-\ht0-\dp0\relax