[texhax] testing if a control sequence is primitive

Heiko Oberdiek heiko.oberdiek at googlemail.com
Sun Oct 9 04:07:47 CEST 2011


On Sun, Oct 09, 2011 at 03:27:53AM +0200, Heiko Oberdiek wrote:

> \long\def\SecondOfTwo#1#2{#2}
> \begingroup
>   \catcode`\|=0 %
>   \catcode`\\=12 %
> |SecondOfTwo{}{|endgroup
>   |def|Backslash{\}%
> }

Just for fun, the definition of \Backslash rewritten in a way
that it uses the "expansion" of `{':

\catcode`\{=1
\catcode`\}=2
\catcode`\#=6

\long\def\FirstOfOne#1{#1}

\catcode`\\=12%
\expandafter\catcode\expandafter`\expandafter\\\the\catcode`\\%
\expandafter\noexpand\expandafter\FirstOfOne\expandafter{%
  \expandafter\def\expandafter\Backslash{\}%
}

\immediate\write16{[\meaning\Backslash]}

\csname @@end\endcsname\end

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list