0

On page 40 of The TeXbook,

Conversely, you can go from a list of character tokens to a control sequence by saying ‘\csname\endcsname’.

So \csname TeX\endcsname equals \TeX. However, \TeX contains four tokens, and those are \0 T11 e11 X11. So, why doesn't \csname need the first token, \0, here?

3
  • 2
    No, after tokenization \TeX does not contain four tokens. It's a single control sequence token.
    – campa
    Commented Nov 23, 2023 at 12:47
  • Yes. I forgot that. @campa
    – Y. zeng
    Commented Nov 23, 2023 at 12:49
  • 2
    The name of the cstoken is TeX not \TeX it's just that to access such a token you need to prefix it by a character of catcode 0 (it does not have to be \ ) after \catcode`Q=0 you can use \TeX or QTeX these are both the same control sequence, as generated by \csname TeX\endcsname Commented Nov 23, 2023 at 13:10

1 Answer 1

3

With the standard category codes, when TeX reads the four characters \•T•e•X (spaces are only for visually separating the characters) it sees \ which has category code 0, so it knows it has to build a single token.

Thus it looks at the next one and finds T, which is assigned category code 11, so now TeX knows it has to build a control word, hence it reads all the following characters until finding one that's not of category code 11. At that point it forms a single token, in this case |TeX| (in the TeXbook you'd see a box around the control sequence name) and enters state S (skipping spaces). Never confuse the “reading part” with the tokens TeX forms from it.

The category code 0 character only serves to initiate the procedure to establish the control sequence name and it's not saved in any way.

If you say

\catcode`|=0 |TeX

you obtain exactly the same token you'd get with \TeX.

Similarly, \csname TeX\endcsname produces the same exact token.

5
  • How to understand this: Never confuse the “reading part” with the tokens TeX forms from it.?
    – Y. zeng
    Commented Nov 23, 2023 at 13:26
  • @Y.zeng Read chapter 7.
    – egreg
    Commented Nov 23, 2023 at 13:36
  • I am reading it and now read page 40.
    – Y. zeng
    Commented Nov 23, 2023 at 13:45
  • @Y.zeng Restart from page 37, then. In particular, look at the bottom of page 38, the dangerous bend after exercise 7.2.
    – egreg
    Commented Nov 23, 2023 at 14:03
  • Okay. Thanks a lot.
    – Y. zeng
    Commented Nov 24, 2023 at 0:43

You must log in to answer this question.

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