# How to get the natural width of the last box in a paragraph?

I want to get the natural width of the last line in a paragraph. For example, the last line of the following paragraph

Georg Friedrich Bernhard Riemann (September 17, 1826 – July 20, 1866) was an influential German mathematician who made lasting contributions to analysis, number theory, and differential geometry, some of them enabling the later development of general relativity.

may be from some to relativity(that is, some of them enabling the later development of general relativity.) When the line-breaking happened, the last line will be put into an hbox, so, how can I get this hbox?

-

\documentclass{article}

\begin{document}

Georg Friedrich Bernhard Riemann (September 17, 1826 -- July 20, 1866) was an
influential German mathematician who made lasting contributions to analysis, number
theory, and differential geometry, some of them enabling the later development of
general relativity.
$$\mbox{the last line had length \the\predisplaysize}$$

\end{document}


Actually \predisplaysize is set to 2em more than the natural size so you may need to subtract 2em, depending..

To get the value without leaving a visible display math you can do something like this (copied from afterpage)

\makeatletter
Georg Friedrich Bernhard Riemann (September 17, 1826 -- July 20, 1866) was an influential German mathematician who made lasting contributions to analysis, number theory, and differential geometry, some of them enabling the later development of general relativity.
{\abovedisplayshortskip\z@\abovedisplayskip\z@
\belowdisplayshortskip\z@\belowdisplayskip\z@
$$\global\dimen\@ne\predisplaysize \xdef\tmp{% \predisplaysize\the\predisplaysize \prevgraf\the\prevgraf\relax}%$$\vskip\dimexpr-\parskip-\baselineskip\relax}\tmp

new para in which we can use \the\dimen\@ne

and another new para

-
+1 every day a new command ;-) –  Marco Daniel Apr 9 '13 at 13:40
I think breqn uses this approach: it only uses display math mode to grab info, and all of the actual setting is done in inline math mode. –  Joseph Wright Apr 9 '13 at 13:45
yeah, wonderful! I like this simple and elegant method :-) But if I don't want the last line \mbox ... ... can you show me another way? –  Timothy Li Apr 9 '13 at 13:46
@JosephWright doesn't everyone? (afterpage also:-) –  David Carlisle Apr 9 '13 at 13:48
And yet another non-math application that requires math mode. –  Ryan Reich Apr 9 '13 at 15:23