Mojca Miklavec wrote:
> 
> 
> Seems like understanding \expandafter would solve 90% of my problems.
> I tried to understand that part in TeX book, but it's so cryptic (too
> short) ... I understand the concept, but I'm not able to write the
> code for it yet :(

The trick to \expandafter is that you (normally) write it backwards
until reaching a moment in time where TeX is not scanning an argument.

Say you have a macro that contains some stuff in it to be typeset by
\type:

   \def\mystuff{Some literal stuff}

Then you begin with

   \type{\mystuff}

but that obviously doesn't work, you want the final input to look like

   \type{Some literal stuff}



Since \expandafter expands the token that follows the after next token
-- whatever the next token is -- you have to insert it backwards across
the opening brace of the argument, like so:

   \type\expandafter{\mystuff}

But this wouldn't work, yet: you are still in the middle of an
expression (the \type expects an argument, and it gets \expandafter
as it stands).

Luckily, \expandafter *itself* is an expandable command, so you
jump back once more and insert another one:

    \expandafter\type\expandafter{\mystuff}

Now you are on 'neutral ground', and can stop backtracking.
Easy, once you get the hang of it.

Taco

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to