7

Suppose I use ' as active character to insert another symbol:

{\tt A'C B}

\def\adef#1{\catcode`#1=13 \begingroup \lccode`\~=`#1\lowercase{\endgroup\def~}}
\let\oldtt\tt\def\tt{\adef'{\char"0D}\oldtt}

{\tt A'C B}

{\tt A'c B}
\bye

Log file contains this:

Missing character: There is no ^^dc in font cmtt10!

Why in the second case the result is not A'C B, although the third case works as expected?

4

This is due to not having a space in the definition of the active ':

\adef'{\char"0D}

should be

\adef'{\char"0D }

so TeX will know where the constant terminates (and the space will be gobbled by TeX rule).

In the first case, TeX is presented with

'C

that becomes

\char"0DC

and TeX duly looks for character number "DC (which of course doesn't exist in a seven bit font).

In the second case the input stream is

\char"0Dc

and, since c is not legal in an hexadecimal number, according to the syntax rules, the found number is "0D that's what is wanted.

Always leave a space after a required constant.

  • May \relax be used in such cases instead of space? – Igor Liferenko May 25 '15 at 1:57
  • @IgorLiferenko Using \relax may be bad in cases where full expandability is needed. In the case of \char, there's no problem. – egreg May 25 '15 at 6:25

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.