4

In TeX, \uppercase{a\lowercase{bC}} produces Abc not ABC, why? As far as I know, TeX will run the inner group before run the outer group, so I think it should be ABC and even \uppercase{a\expandafter{\lowercase{bC}}} can't change bc to BC. May you tell me the reason?

10
  • Why do you think 'TeX will run the inner group before ... the outer group'? As far as I know, that's false. \uppercase applies to the sequence of tokens. TeX provides that sequence. That is, it feeds the primitive a\expandafter{\lowercase{bC}} but it doesn't otherwise touch them. There's no sense in which it 'runs' the 'inner group' first. Try \uppercase{ab\lowercase{cD}}
    – cfr
    Commented Nov 24, 2023 at 6:45
  • @cfr For example, \def\cdf{hello}, the \centerline{\cdf} can make hello center, so TeX could expand the inner group first. In this post, as expandafter{\lowercase{bC}} makes \lowercase{bC} ran first, so it is bc that will be feeded into \uppercase. Where is wrong?
    – Y. zeng
    Commented Nov 24, 2023 at 6:48
  • Because it doesn't expand the inner group first. If you think that only because it would explain some cases, well, that's a flawed methodology ;). If that was the rule, you'd get a centred hello and BC. But that's not what TeX does. So it's a bad way to predict results.
    – cfr
    Commented Nov 24, 2023 at 6:52
  • 2
    tex.stackexchange.com/questions/467360/… Commented Nov 24, 2023 at 9:04
  • 1
    @Y.zeng Yes. From left to right.
    – cfr
    Commented Nov 24, 2023 at 15:20

2 Answers 2

7

The \uppercase and \lowercase primitives are defined as converting the tokens their input into the appropriate case-mapped output. They perform no expansion and are themselves not expandable (so for example \expandafter{\lowercase{ABC}} is just the same as {\lowercase{ABC}}).

It is possible to implement case changing in macros that performs expansion before case changing, or indeed to go all the way and avoid \uppercase and \lowercase entirely. This is what expl3 does in \text_uppercase:n - you get the 'function-like' result but this is a design choice at the macro level.

1
6

Your assumption is incorrect. TeX starts from \uppercase, so it sends the contents down and the stomach regurgitates

A\lowercase{BC}

in the input stream, because the \uppercase operation acts only on character tokens. So the final result, after doing also \lowercase is the same as

Abc

had been input to begin with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .