# Peek ahead a \vbox: \vsplit and reassemble again?

I'm wondering if it's possible to implement a peek method to inspect the head of a \vbox without changing the content of the \vbox. It could be done by brute force using a \copy of the original \vbox, but I'm looking for a not so brutal method.

With the following code, a \bigbox is constructed, its head split of as \partbox, and finally all is reassembled again as \bigbox. \testmybox serves for showing the boxes.

\documentclass{article}
\usepackage{blindtext}

\def\testmybox#1{%
\par%
{\fboxsep0pt\fbox{\copy#1}}\par%
\edef\myboxheight{\the\dimexpr\ht#1+\dp#1\relax}%
Total height: \myboxheight%
}

\begin{document}

\newbox\bigbox
\newbox\partbox

\setbox\bigbox=\vbox{\hsize 11cm%
\footnotesize\blindtext[1]}

\textbf{Original box}\par
\testmybox\bigbox

%\splittopskip=0pt
%\splitmaxdepth=0pt

\setbox\partbox=\vsplit\bigbox to 45pt%

\textbf{Splitted box:}\par
\testmybox\partbox

\textbf{Rest:}\par
\testmybox\bigbox

\setbox\bigbox=\vbox%
{%
\unvbox\partbox
\unvbox\bigbox
}

\textbf{Reassembled box:}
\testmybox\bigbox

\end{document}


The problem is that the reassembled box is not identical to the original box. Here, there is too much space between the two parts. This space depends on the \splittopskip value, but I don't know how to set this value such that it works with all thinkable situations.

Is it possible to reassemble the original box without deviation?

Since nobody answered or commented this question, I thought there was no answer. But then I found \splitdiscards and \savingvdiscards from e-TeX which seem to be exactly the missing commands. With it, the answer seems to be stupidly easy - would have saved my many hours if I knewed this before:

\documentclass{article}
\usepackage{blindtext}

\def\testmybox#1{%
\par%
{\fboxsep0pt\fbox{\copy#1}}\par%
\edef\myboxheight{\the\dimexpr\ht#1+\dp#1\relax}%
Total height: \myboxheight%
}

\begin{document}

\newbox\bigbox
\newbox\partbox

\setbox\bigbox=\vbox{\hsize 11cm%
\footnotesize\blindtext[1]}

\textbf{Original box}\par
\testmybox\bigbox

\splittopskip=0pt
%\splitmaxdepth=0pt
\setbox\partbox=\vsplit\bigbox to 45pt%

\textbf{Splitted box:}\par
\testmybox\partbox

\textbf{Rest:}\par
\testmybox\bigbox

\setbox\bigbox=\vbox%
{%
\unvbox\partbox%

• I still believe that \setbox\tempbox=\copy\bigbox is cleaner if you just want to access \bigbox for measuring but not touching it. – egreg Jul 31 '14 at 6:45