Andrew Stacey

Andrew Stacey
Information about my research, teaching, and other interests.

By: Andrew Stacey
Contact details

 home :: HowDidIDoThat :: Hints :: ExpandAfter Feeds:Atom RSS2.0

Wed, 31st Oct 2007 (HowDidIDoThat :: Hints)

Some TeX Hints

I've started writing really complicated style files for my TeX documents. Here are a few useful hints that I've come across and feel that I need to write down else I'll forget them.

#### Expandafter

The rules for expanding \expandafter can be fairly complicated. Here's an example of a command called on two macros with the macros expanded before the call:

\expandafter
\expandafter
\expandafter
\command\expandafter
\expandafter
\expandafter
{\expandafter
\argone
\argtwo}

Here's the same where the command takes the two arguments separately

\expandafter
\expandafter
\expandafter
\command\expandafter
\expandafter
\expandafter
{\expandafter
\argone
\expandafter
}\expandafter
{\argtwo}

Phew!

A useful trick for figuring out \expandafters is to use the delete-word and forward-word shortcuts in emacs. More-or-less, taking a line without extraneous spaces and doing delete-word + forward-word on each expandafter leaves you with what TeX does. Repeated doing of this can give you insight into what TeX does when it encounters a complicated string such as the above.