We have a number of questions or rather answers using (and explaining) the \lowercase “trick”.

\lowercase{\endgroup\def~}#1{foo with #1}

However, after reading on uppercase and lowercase codes I started wondering how it is possible that it is working. Quoting TeX by Topic:

To each of the character codes correspond an uppercase code and a lowercase code [...]. These can be assigned by

\uccode number equals number


\lccode number equals number .

In IniTeX codes `a..`z, `A..`Z have uppercase code `A..`Z and lowercase code `a..`z. All other character codes have both uppercase and lowercase code zero.

The commands \uppercase{...} and \lowercase{...} go through their argument lists, replacing all character codes of explicit character tokens by their uppercase and lowercase code respectively if these are non-zero, without changing the category codes.

The last sentence made me thinking: how can the “trick” work if both ~ and the symbol that gets a definition have lowercase code=0? My naive expectation would be that


gives ~ the same lowercase code it had before and is equivalent to \lccode`~=0. But to me this would imply that the “trick” shouldn't work? How come it does work?


\verb+\the\lccode`. += \the\lccode`. \par
\verb+\the\lccode`~ += \the\lccode`~

\lowercase{\endgroup\def~}#1{foo with #1}




enter image description here

  • How did this question come into your mind? ;-)
    – Speravir
    Jan 30, 2014 at 23:59
  • Going to buy a loupe? ;-D
    – Speravir
    Jan 31, 2014 at 0:48
  • As hint for readers able to read German: Was sind catcodes, lccodes und uccodes?
    – Speravir
    Jan 31, 2014 at 18:07
  • 1
    ;-) One upvote is mine, the other ones need new glasses like OP I will not name here …
    – Speravir
    Jan 31, 2014 at 18:15
  • For future readers: I made a package to allow you to write LaTeX code with unusual catcode/charcode easier/more readably tex.stackexchange.com/a/638824/250119 (although the performance is to be improved)
    – user202729
    Apr 5, 2022 at 7:25

1 Answer 1


Your intuition is wrong. In TeX's syntax,


is a number, precisely the ASCII code of the character appearing after the backquote (it can also be a length one control sequence, meaning just the same, to accommodate cases like %). So the assignment


is just the same as

\lccode 126=46

so the lowercase counterpart of the tilde becomes the period, as far as \lowercase is concerned.

If you write


then you'd assign the tilde the lccode 0, but it's very different.

Some more words may be good for the beginner. One can think to \lccode as an array of length 256, with its index starting at 0. The command

\lccode <number1> = <number2>

stores <number2> in the slot numbered <number1>. When \lowercase does its job and finds a character with charcode x, it looks in slot x of the \lccode array; if the numbers stored there is 0, \lowercase does nothing; otherwise it finds a number y > 0 and replaces the charcode x with the charcode y (not changing the catcode).

As usual in TeX, the same primitive that performs the assignment can be used for retrieving the value in the slot. Thus \the\lccode`\A will print 97 (under normal settings) and


would store 97 in the count register 255. One might even say


in order to store 42 in count register 97. But this doesn't seem good usage of \lccode. ;-)

There are several other arrays besides \lccode and \uccode: \sfcode (space factor codes), \mathcode (math codes), \delcode (delimiter code) and \catcode (category code).


You must log in to answer this question.

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