[texhax] Fragile command problem?

Donald Arseneau asnd at triumf.ca
Mon Apr 16 02:08:01 CEST 2007

Toby Cubitt <tsc25 at cantab.net> writes:

> I think I understand now. \let and \def are not expandable, so \edef and
> \csname just leave them alone when expanding. 

Yes.  There is a subtle distinction as follows.

When expansion happens out of step with assignments, Lamport
calls that a "moving argument".  Commands that rely on both 
expansion and assignments are "fragile".  To handle the problems 
there is the \protect command that delays expansion until whenever 
assignments will be processed.  Commands that survive a moving
argument intact are called "robust" and are of three types:
Ones that are simple unexpandable tokens, like \beta declared
by \mathchardef; ones that expand "completely" without assignments;
and ones that are defined using \protect internally (self-protecting
commands that would otherwise be fragile).

The distinction comes in the argument of \csname where the 
\protect mechanism won't work.  Not only is \protect not usually
enabled, but there is no way to delay expansion because the
assignments will never be processed.  Only s subset of robust
commands, the completely expandable ones, work in this case.

> macro expansion is nothing like evaluation in a normal procedural
> language (it just appears similar by accident, occasionally).

They are more closely coupled in TeX than in other languages
(like C) which leads to the confusion.  I think it is a big
design misfeature that assignments happen separately from 

Donald Arseneau                          asnd at triumf.ca

More information about the texhax mailing list