7

How do you unbox \hrules such as in this code sample:

\setbox0=\vbox{1\hrule2\hfil\break3}
\unvbox0
\setbox0=\lastbox % line 3
\unskip           % \baselineskip
\unpenalty        % \break
\setbox0=\lastbox % line 2
\unskip           % \parskip
% Unbox \hrule?
\end
SJU
  • 1,721
  • 3
    Only a box can be caught by \lastbox. Rules don't. And there's no way to remove them from a list, unless you produce them as a vertical leader (and \unskip will remove them). If you look at the macro I suggested, I removed \noalign{\hrule} in the first pass just because of that problem. – egreg Oct 08 '14 at 17:45

1 Answers1

6

TeX has some primitives for “looking back” and removing a node, storing it into a register: \lastskip, \lastkern, \lastpenalty and \lastbox. Other types of nodes can't be examined nor removed.

Note that \lastskip only keep information about the size of the last skip, whether it comes from a “real” skip or \leaders, so the information about leaders is lost in this case.

All of them do nothing, in the sense that they store a null value, if the last node is of the requested type. As usual, boxes are special: \lastbox by itself will remove the last box (if the last node in the list is a box), and reinsert it (see Usage of \lastbox).

However, a rule node is not a box, so \lastbox will do nothing sensible. More explicitly: you can't remove a rule node nor examine it.

egreg
  • 1,121,712