What does it do and what are its applications? I am currently testing the subtitle of my beamer presentation for its string length to decide about line spacings. Could it be simpler using \empty?

If I just try \empty{word}, it seems that nothing happens. Of course, I do not expect to get a string length, but I thought that I could check the title for being empty or not.

This is how I add space by checking beamer's subtitle:



I try to clarify my question as requested in the comments: I thought that I could check for \empty. \StrLen is easy to understand because you can output that value as text. However, this does not work for \empty so I wondered how one would use it to accomplish the same task.

  • 2
    The LaTeX kernel defines \let\empty\@empty and earlier \def\@empty{}. So it is a macro without arguments that expands to nothing. – cgnieder Dec 1 '13 at 16:45
  • Thank you. Does this mean that I cannot use it for the purpose I thought I could? – Xiphias Dec 1 '13 at 16:49
  • You can use \empty and \@empty to test whether an argument or another macro is empty ("string" length zero). There are also packages that do this and eTeX solutions that do this without using \[@]empty. The sequence \empty{word} is nothing special. In fact, {word} is not an argument here but simply the letters word in a group since \empty doesn't take an argument. What do you want to know? What \empty does? It does nothing, see the linked question. Do you want to know about string lengths? Check the xstring package (xstring) or related questions on TeX.sx. – Qrrbrbirlbel Dec 1 '13 at 16:54
  • For me, your question is not clear. Maybe an example, a use-case and a minimal working example (MWE) would help us help you. – Qrrbrbirlbel Dec 1 '13 at 16:55
  • @Qrrbrbirlbel: Thank you, I clarified my question. – Xiphias Dec 1 '13 at 16:59

\empty is defined in the LaTeX kernel by

% latex.ltx, line 122:
% latex.ltx, line 441:

Actually the kernel macro is \@empty, but \empty is equivalent and is in the kernel for backward compatibility, because Plain TeX uses \empty.

When you expand \empty you get nothing at all, so


is just equivalent to typing


which is not different, under normal circumstances, to typing word without braces.

What's the use of \empty (better \@empty)? If you want to see whether the replacement text of a (parameterless) macro has no tokens, you can do

  <text to be used if \mymacro expands to nothing>
  <text to be used otherwise>

A frequent use case is when you want to test whether an optional argument is empty. For instance

     no optional argument (or \mymacro[])
     do something with #1

However, with e-TeX extensions available, it's better to use

     no optional argument (or \mymacro[])
     do something with #1

The main usage of \@empty in the kernel is for initializing macros to a default value, so the construct


is used many times. During processing, \cs will receive various values, and macros can test whether \cs is in its initial state or not.

Another important use in in the definition of \@array, where


is found, which allows empty lines in array or tabular environments.

  • Although I already upvoted your answer, I'd like to say that this is an excellent answer. Thank you for showing me the uses of \empty! – Xiphias Dec 1 '13 at 20:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.