TeX/expandafter

Synopsis
\expandafter

Description
The \expandafter command delays expanding a macro until its arguments have been expanded.

Examples
will not work, saying "! Use of  doesn't match its definition." This is because while defining, the first argument (denoted  ) appeared in square braces. Therefore,  expects its first argument to appear in square braces, while in , the immediate character after   is not a left square bracket. Using \expandafter, we can write This expands  before , as if we had written the following in the first place: As a result, TeX will print.

The \expandafter command first expands the tokens following, and then expands , with the expanded following it as if they had been typed in the file.

Multiple invocations
One sometimes sees long chains of expandafters, which can normally be read as "expand after N", e.g. This expands  only once (in contrast to TeX/edef).