7

Sometimes, in LaTeX one wants to do the simple test if a macro is empty, e.g.

\def\foo{%
  This is...
  \ifx\baz\@empty
    Sparta!
  \else
    a pony farm.
  \fi
}

I am interested in how the definition of \baz has to be made in order to obtain the desired results. A few thoughts make evident that all of the three definitions

\def\baz{}
\edef\baz{\@empty}
\let\baz=\@empty

will lead to the true case. Now, I would like to know, what is the best practice, or if there aren't any differences (as far as \def\@empty{}), or if there are cases in which one is to favor, (obviously) depending on what one is doing? (Examples would be really nice!)

1

1 Answer 1

8

If you are asking about the definition (rather than about the form of the test which is the focus of earlier questions)

then assuming \@empty has its usual meaning

\def\baz{}
\edef\baz{\@empty}

are identical in terms of the resulting definition of \baz.

\let\baz=\@empty

is in theory slightly different as TeX can share the memory used to store both definitions but as the definition in this case is empty, that isn't really a difference and in any case the difference is not detectable within TeX.

1
  • That is exactly what i was looking for, and also what i was afraid of. So you are basically saying that all the definitions in the end are equivalent (with a negliable difference). Hence one has the free choice. Thank you though for dealing with it.
    – Ruben
    Commented Aug 15, 2013 at 18:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .