[texhax] TeX command works for "1 Foo" but not for "11 Foo"
Morten Høgholm
morten.hoegholm at gmail.com
Wed Oct 31 11:43:29 CET 2007
On 10/31/07, martin f krafft <madduck at madduck.net> wrote:
> also sprach Martin Heller <mr_heller at yahoo.dk> [2007.10.30.2335 +0100]:
> > Your test for empty arguments is broken.
>
> Hello, thanks for your reply! Your proposed solution does in fact
> work. Thank you very much.
>
> Now I would like to understand what's going on. And I have two
> questions:
>
> 1. Why do you postpone the command creation until \makeatletter? It
> works just fine if I define it in the preamble with \newcommand.
Martin's solution as well as your original code makes use of a command
with @ in it, requiring @ to be a letter at the time of definition.
See <http://www.tex.ac.uk/cgi-bin/texfaq2html?label=atsigns> for
details.
> 2. I still don't understand the problem I had. It seems that my test
> somehow ate arguments.
[...]
> My function did
>
> \if\@empty#2\relax\else{ }\begin{smaller}{[#2]}\end{smaller}\fi%
\if does compare tokens but first expands them. Hence \@empty is
expanded (to nothing) and then the next two tokens are compared. If
the date is the 10th, 1 and 0 are compared. If the date is the 11th, 1
and 1 are compared.
The source where you learned about using \if ought to be clear on
this, be it a book or a TeX hacker.
In general, use dedicated functions for these things. I use
\tlist_if_empty:nTF and \tlist_if_blank:nTF from the expl3 code, where
the names should indicate what they test for (tlist = token list).
Cheers,
--
Morten
More information about the texhax
mailing list