# Welcome to the UK List of TeX Frequently Asked Questions on the Web

## Detecting that something is empty

Suppose you need to know that the argument of your command is empty: that is, to distinguish between \cmd{} and \cmd{blah}. This is pretty simple:

\def\cmd#1{%
\def\tempa{}%
\def\tempb{#1}%
\ifx\tempa\tempb
<empty case>
\else
<non-empty case>
\fi
}


The case where you want to ignore an argument that consists of nothing but spaces, rather than something completely empty, is more tricky. It’s solved in the code fragment ifmtarg, which defines commands \@ifmtarg and \@ifnotmtarg, which examine their first argument, and select (in opposite directions) their second or third argument. The package’s code also appears in the LaTeX memoir class.

Ifmtarg makes challenging reading; there’s also a discussion of the issue in number two of the “around the bend” articles by the late lamented Mike Downes.

Around the bend series
info/challenges/aro-bend (or browse the directory); catalogue entry
ifmtarg.sty
macros/latex/contrib/ifmtarg (or browse the directory); catalogue entry
memoir.cls
macros/latex/contrib/memoir (or browse the directory); catalogue entry

Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=empty

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.