# What does \empty do? [duplicate]

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:

\usepackage{xstring}
\StrLen{\insertsubtitle}[\subtitlelen]

\ifnum\subtitlelen>0{
\vskip0.2cm
}\fi


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.

## marked as duplicate by Marco Daniel, Guido, m0nhawk, Claudio Fiandrino, yo'Dec 1 '13 at 19:51

• The LaTeX kernel defines \let\empty\@empty and earlier \def\@empty{}. So it is a macro without arguments that expands to nothing. – clemens 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:
\def\@empty{}
% latex.ltx, line 441:
\let\empty\@empty


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

\empty{word}


is just equivalent to typing

{word}


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

\ifx\mymacro\empty
<text to be used if \mymacro expands to nothing>
\else
<text to be used otherwise>
\fi


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

 \makeatletter
\newcommand{\mymacro}[1][]{%
\def\@tempa{#1}%
\ifx\@tempa\@empty
no optional argument (or \mymacro[])
\else
do something with #1
\fi
}


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

\newcommand{\mymacro}[1][]{%
\if\relax\detokenize{#1}\relax
no optional argument (or \mymacro[])
\else
do something with #1
\fi
}


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

\let\cs\@empty


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

\let\par\@empty


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