# Using tokens derived from \let

It seems that tokens that are derived from \let command can't always be used literally. The following fails. I want to test if the next character is a numerical constant. Of course, the test is not complete; I am only asking a question here.

\newcount\cnta
\def\gobble#1{}
\def\cmda{\futurelet\next\cmdb}
% \next is unabsorbed but remains as character 2. \gobble is meant to gobble 2.
\def\cmdb{\cnta0\next\space\gobble}
\cmda 2
\showthe\cnta
-
It's not clear what your question is? There are many similar instances eg \egroup is \let equal to } but \def\a{\egroup} and \def\a{}} are not at all the same. – David Carlisle Jun 3 '12 at 23:44
\next is here not expandable and therefore ends the read number mode. You are right, such implicit tokens are not generally interchangeable with the explicit tokens. The will case the same result if they are typeset but not in most other cases. For example you can't use an implicit token inside \csname ..\endcsname. I had this issue with the tikz-timing parser. – Martin Scharrer Jun 3 '12 at 23:49
@DavidCarlisle: I thought \, { and } are special cases. – Ahmed Musa Jun 4 '12 at 3:36
well it depends if you are a cup half full or cup half empty kind of person. You could say { is a special case and the syntax for a literal <number> is special and the syntax for a unit is special and..., or you could say they are all just parsed "the TeX way" – David Carlisle Jun 4 '12 at 8:56

1. \cmda 2

2. \futurelet\next\cmdb 2

This is equivalent to

3. \let\next 2\cmdb 2

Now \next has meaning "The character 2" and the \let is removed.

4. \cnta0\next\space\gobble 2

\cnta starts an assignment, and \next, which is unexpandable and not a <digit>, ends the search for a number. So \cnta=0 is performed, \next is passed on for execution as it will be the space resulting from \space and \gobble gobbles 2.

TeX does macro expansion when searching for a number, but after \let\next=2, \next is not a macro. Also an assignment such as

\cnta=\next

would be illegal after \let\next=2 (or using \futurelet, which is equivalent); see the syntax for <number> in the TeXbook, page 269: implicit character tokens can't be used.

-
The above is all true of course, but 2 isn't a macro either but \cnta02 would consume the 2 so not being a macro isn't enough of a reason: it's just that the final (after macro expansion) syntax for numbers includes digit character tokens and TeX registers, but not tokens \let equal to characters. – David Carlisle Jun 4 '12 at 9:00
@DavidCarlisle I added something. – egreg Jun 4 '12 at 9:15
So, how could the original task "I want to test if the next character is a numerical constant." be performed? Compare \next with all digits consecutively using \if? – Stephan Lehmke Jun 4 '12 at 9:24
@StephanLehmke yes or depending what you want to do about leading digits, \afterassigntment\foo\cnta0 might do something useful as it consumes all following digits, so if cnta is not 0 you ate a digit, if it is zero you have to work harder – David Carlisle Jun 4 '12 at 9:31
I thought about \afterassignment as well, but wouldn't it read more than one character, expand things etc? – Stephan Lehmke Jun 4 '12 at 9:52