Compute depth of paragraph

I need to compute the distance from the current baseline to the bottom of the next/current paragraph. (Eventually this is going to wind up in \everypar.) Is there an easier way to do this precisely?

\documentclass{article}
\usepackage{lipsum}

\newlength\parsize

\newcommand{\testheight}[1]%
{\bgroup
\skip0=\parskip
\skip1=\parindent
\skip2=\leftskip
\skip3=\rightskip
\skip4=\parfillskip
\skip5=\baselineskip
\skip6=\lineskip
\ifdim\hfuzz<.4pt\relax\let\default=\fussy
\else\let\default=\sloppy
\fi
\sbox0{\parbox[t]{\columnwidth}{%
\parskip=\skip0
\parindent=\skip1
\leftskip=\skip2
\rightskip=\skip3
\parfillskip=\skip4
\baselineskip=\skip5
\lineskip=\skip6
\default #1}}%
\global\parsize=\dp0
\egroup}

\begin{document}

\rightskip=3in
\sloppy
\testheight{\lipsum[1]}
\noindent\llap{\smash{\rule[-\parsize]{1pt}{\parsize}} }
\hskip\parindent\lipsum[1]

\end{document}


The goal is not to draw the line. That was just a test to make sure it was working. My goal is to revise wrapfig using \pdfsavepos and adding some new options.

Postscript:

When I first switched from plain TeX to LaTeX, none of my old code using \vbox would work right. Early experiments indicated that there was no difference between \vbox, \hbox and \mbox, so I learned to make do with \parbox and tabular instead. It was only recently that I discovered that one could still use \vbox to stack \hboxes by inserting \\ between them and using \baselineskip=0pt. It should come as no surprise that \vbox now follows standard paragraph building rules.

• What happens to a paragraph that overflows to a subsequent column or page? – Werner Oct 6 '15 at 19:10
• Wouldn't it be easier to use a \vbox instead of a \parbox? – egreg Oct 6 '15 at 19:19
• My impression is that you want to consider tcolorbox – egreg Oct 6 '15 at 19:33
• @egreg - I'm trying to reproduce the exact size the paragraph will take when printed (at least as close as possible without knowing the stretch/shrink that may be applied at the pagebreak). – John Kormylo Oct 7 '15 at 4:00
• @JohnKormylo Then \setbox0=\vtop{...} is definitely better, because it does not reset any parameter like \parbox does. – egreg Oct 7 '15 at 8:53

LaTeX doesn't change \vbox in any way. The main difference when doing \vbox or \parbox is that in the latter case some initializations are made, which you are taking care of with those assignments to the scratch registers.

Another problem would be that of footnotes and other “migrating” material, but I assume you don't face it; otherwise it would require some redefinitions.

With

\newdimen\lastdepth
\setbox0=\vtop{
\ifdim\hfuzz<.4pt
\let\default=\fussy
\else
\let\default=\sloppy
\fi
\default
<text>\par
\global\lastdepth=\prevdepth
}


you can query for \ht0, that gives the height of the first line, for \dp0, that gives the total remaining size, and for \lastdepth that stores the depth of the last line.

Since no initialization is made, like in \parbox, the typesetting of <text> should not change with respect to having been set in the outer vertical list.

If you don't need the height of the first line, but just the total height, \vbox is perhaps better: with

\setbox0=\vtop{
\ifdim\hfuzz<.4pt
\let\default=\fussy
\else
\let\default=\sloppy
\fi
\default
<text>
}


you have in \ht0 the total height of the text and in \dp0 the depth of the last line.