We have a number of questions or rather answers using (and explaining) the \lowercase “trick”.
\begingroup
\lccode`\~=`\.
\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 numberand
\lccode number equals number .In IniTeX codes
`a..`z,`A..`Zhave uppercase code`A..`Zand 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
\lccode`\~=`\.
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?
\documentclass{article}
\begin{document}
\verb+\the\lccode`. += \the\lccode`. \par
\verb+\the\lccode`~ += \the\lccode`~
\begingroup
\lccode`\~=`\.
\lowercase{\endgroup\def~}#1{foo with #1}
\catcode`\.=13
.{bar}
\end{document}
