LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Heiko Oberdiek <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Tue, 4 Jan 2011 09:43:43 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (62 lines)
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

Yours sincerely
  Heiko <[log in to unmask]>

ATOM RSS1 RSS2