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!)

Ruben
  • 13,448
  • This appears to be a duplicate of earlier questions eg http://tex.stackexchange.com/questions/53068/how-to-check-if-a-macro-value-is-empty-or-will-not-create-text-with-plain-tex-co or http://tex.stackexchange.com/questions/44919/proper-way-to-detect-empty-blank-text – David Carlisle Aug 15 '13 at 16:43

1 Answers1

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.

David Carlisle
  • 757,742
  • 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 Aug 15 '13 at 18:36