On 04/01/2011 08:43, Heiko Oberdiek wrote:
> On Tue, Jan 04, 2011 at 05:11:34PM +1030, Will Robertson wrote:
>
>> On 04/01/2011, at 8:36 AM, Joseph Wright wrote:
>>
>>> Working on the galley (see the latest SVN checkin), I find that \box_if_empty:NTF is misleading. The test is for a void box, not an empty one:
>>>
>>> \box_new:N \l_my_box
>>> \hbox_set:Nn \l_my_box {}
>>> \box_if_empty:NTF \l_my_box { NOPE } { OOPS }
>>>
>>> I think it should be \box_if_void:NTF - any objections?
>>
>> Not at all.
>> Is there a need to have an actual empty test?
>> Oh wait, this isn't possible, right?
>
> A non-expandable test is possible:
>
> \NeedsTeXFormat{LaTeX2e}
> \makeatletter
> \newbox\test@box
> \def\ifboxempty#1{%
>    \global\let\g@next\@secondoftwo
>    \ifhbox#1%
>      \setbox\test@box=\hbox{%
>        \unhcopy#1\relax
>        \ifnum\lastnodetype<\z@
>          \global\let\g@next\@firstoftwo
>        \fi
>      }%
>    \else
>      \ifvbox#1%
>        \setbox\test@box=\vbox{%
>          \unvcopy#1\relax
>          \ifnum\lastnodetype<\z@
>            \global\let\g@next\@firstoftwo
>          \fi
>        }%
>      \fi
>    \fi
>    \g@next
> }
> \makeatother
>
> \def\wrong#1{\typeout{WRONG: #1}}
> \def\ok#1{\typeout{OK: #1}}
> \begingroup
>    \setbox0=\box0
> \endgroup
> \ifboxempty0{\wrong{void is empty}}{\ok{void is not empty}}
> \setbox0=\null
> \ifboxempty0{\ok{null is empty}}{\wrong{null is not empty}}
> \setbox0=\vbox{}
> \ifboxempty0{\ok{vbox{} is empty}}{\wrong{vbox{} is not empty}}
> \setbox0=\hbox{\write16{}}
> \ifboxempty0{\wrong{hbox with write is empty}}%
>              {\ok{hbox with write is not empty}}
> \csname @@end\endcsname\end

Thanks for that Heiko: quite a nice idea. One obvious conceptual 
question is how to treat void boxes. You've gone for 'void boxes are not 
empty', but this might not be how everyone expects it to be.
-- 
Joseph Wright