[comp.text.tex] Explanation requested re: \uppercase and \romannumeral

brister@decwrl.dec.com (James Brister) (01/31/91)

Could someone clue me in why line 1 doesn't work, but line 2 does.

	1) \uppercase{\romannumeral\count0}
	2) \uppercase\expandafter{\romannumeral\count0}


Why, in the first example, doesn't the '\romannumeral\count0' get expanded
to the token string, before \uppercase sees it.

I think this is due the 'stomach' vs. 'mouth' business of TeX (a concept
I'm not too clear on yet). True?

Thanks

James
--
James Brister                                           brister@decwrl.dec.com
DEC Western Software Lab., Palo Alto, CA    {uunet,sun,pyramid}!decwrl!brister

eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (01/31/91)

brister@decwrl.dec.com (James Brister) writes:

>Could someone clue me in why line 1 doesn't work, but line 2 does.

>	1) \uppercase{\romannumeral\count0}
>	2) \uppercase\expandafter{\romannumeral\count0}

It is the definition of \uppercase that it takes a token
list and  uppercases every character token in it.
You wouldn't want the reverse, because then things like
\def\IsUppercaseChar#1{\uppercase{\if#1}#1}
wouldn't work because the \if is expandable.

The second line works because \uppercase has to expand
in order to find its opening brace: that can be implicit.
This in contrast to 
\def\foo\expandafter{\romannumeral 4}
which is *not* the same as \def\foo{iv}

Victor.

jcb@cs.ed.ac.uk (Julian Bradfield) (02/01/91)

In article <BRISTER.91Jan30170400@saratoga.decwrl.dec.com> brister@decwrl.dec.com (James Brister) writes:

>	1) \uppercase{\romannumeral\count0}
>	2) \uppercase\expandafter{\romannumeral\count0}

>Why, in the first example, doesn't the '\romannumeral\count0' get expanded
>to the token string, before \uppercase sees it.

>I think this is due the 'stomach' vs. 'mouth' business of TeX (a concept
>I'm not too clear on yet). True?

No, it's all happening in the mouth. In line 1, \uppercase wants a
token list, and expansion is switched off when reading this list (it's
one of the cases listed in Chap. 20).
In line 2, the \expandafter forces expansion of \romannumeral ; the
expansion is put back after the {, and then the token list for
\uppercase is read as normal, without expansion. (Expansion is
switched off when TeX sees the left brace starting the token list.)