LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show HTML 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 11:27:43 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (70 lines)
Hello,

On Tue, Jan 04, 2011 at 09:26:56AM +0000, Joseph Wright wrote:

> > [empty box test]
> 
> 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.

The example was just a ``proof of concept''.
A solution without global assignments, without a new box register
and with void as empty:

\NeedsTeXFormat{LaTeX2e}
\makeatletter
% empty := empty \(h|v)box | void
\def\ifboxempty#1{%
  \begingroup 
    \ifvoid#1%
      \let\@next\@firstoftwo
    \else
      \let\@next\@secondoftwo
      \def\@nextempty{\let\@next\@firstoftwo}%
      \ifhbox#1%
        \setbox\z@=\hbox{%
          \unhcopy#1\relax
          \ifnum\lastnodetype<\z@ 
            \aftergroup\@nextempty
          \fi
        }% 
      \else
        \ifvbox#1%
          \setbox\z@=\vbox{%
            \unvcopy#1\relax
            \ifnum\lastnodetype<\z@ 
              \aftergroup\@nextempty
            \fi
          }%
        \fi
      \fi
    \fi
  \expandafter\endgroup
  \@next
}
\makeatother

\def\wrong#1{\typeout{WRONG: #1}}
\def\ok#1{\typeout{OK: #1}}
\begingroup
  \setbox0=\box0
\endgroup
\ifboxempty0{\ok{void is empty}}{\wrong{void is not empty}}
\setbox0=\null
\ifboxemptyorvoid0{\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

In an exact manner of speaking the question if a box is empty without
having a box is wrong itself. On the other hand a user might be only
interested, if there is box contents. But in the end this is a matter
of definition and naming the macro.

Yours sincerely
  Heiko <[log in to unmask]>

ATOM RSS1 RSS2