4

In this post, @Heiko Oberdiek said

BUT each number TeX expects have to be catcode 12 (the problems)! Eg. \hspace{1em}

What does he meant by "each number"? In addition to counters/dimensions/glues, which of the following will break?

\def\cs#1{}
\box 255
\numexpr 1+1 \relax
\ifcase 1 ... \fi
\char"26
$1+1$

(please feel free to expand the list)

  • There is no problem when you want to print a number. The issue is when the digits are part of syntax – egreg Jun 30 '16 at 8:56
  • @egreg I quite upset. Roman numeral makes my code ugly since the lengths of control sequences vary. – Symbol 1 Jun 30 '16 at 9:03
  • @Symbol1 You could use descriptive names, rather than roman numerals, or letters, like “wipet style” \def\foo{} \def\fooA{} \def\fooB{} \def\fooC{} \def\fooL{} \def\fooX{}, etc. – Manuel Jun 30 '16 at 9:34
3

It can be immediately see from this syntax scheme borrowed from the TeXbook, page 269, that essentially all syntactic constructs requiring a number will break if digits have category code 11 and not 12.

⟨number⟩ → ⟨optional signs⟩⟨unsigned number⟩
⟨optional signs⟩ → ⟨optional spaces⟩
| ⟨optional signs⟩⟨plus or minus⟩⟨optional spaces⟩
⟨unsigned number⟩ → ⟨normal integer⟩ | ⟨coerced integer⟩
⟨normal integer⟩ → ⟨internal integer⟩
| ⟨integer constant⟩⟨one optional space⟩
| '12⟨octal constant⟩⟨one optional space⟩
| "12⟨hexadecimal constant⟩⟨one optional space⟩
| `12⟨character token⟩⟨one optional space⟩
⟨integer constant⟩ → ⟨digit⟩ | ⟨digit⟩⟨integer constant⟩
⟨octal constant⟩ → ⟨octal digit⟩ | ⟨octal digit⟩⟨octal constant⟩
⟨hexadecimal constant⟩ → ⟨hex digit⟩ | ⟨hex digit⟩⟨hexadecimal constant⟩
⟨octal digit⟩ → 012 | 112 | 212 | 312 | 412 | 512 | 612 | 712
⟨digit⟩ → ⟨octal digit⟩ | 812 | 912
⟨hex digit⟩ → ⟨digit⟩ | A11 | B11 | C11 | D11 | E11 | F11
| A12 | B12 | C12 | D12 | E12 | F12
⟨one optional space⟩ → ⟨space token⟩ | ⟨empty⟩
⟨coerced integer⟩ → ⟨internal dimen⟩ | ⟨internal glue⟩

Also definitions like \def\cs#1{...} would break, because the syntax prescribes that the digit following # has category code 12, if we want a parameter.

You'd have no problem when printing numbers, but simple things such as \\[1ex] would break horribly.

You might always \detokenize your syntactic numbers, because TeX will perform expansion when in need of a ⟨number⟩:

\hspace{\detokenize{1}em}

would work in the document. Is this worth the pain?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.