[texhax] testing if a control sequence is primitive

Philip TAYLOR (Webmaster, Ret'd) P.Taylor at Rhul.Ac.Uk
Sat Oct 8 22:48:54 CEST 2011


I am /seriously/ impressed, and was about to nominate you
for the post of vice-Grand Wizard of TeX (no salary, I am
afraid), when I thought to try the following :

\Test \newif

Philip Taylor
--------
Heiko Oberdiek wrote :

> % iniTeX, plain, LaTeX, ...
> \catcode`\{=1
> \catcode`\}=2
> \catcode`\#=6
>
> \long\def\ifprimitivecs#1{%
>   \begingroup
>     \escapechar=`\\%
>     \edef\tempa{\string#1}%
>     \edef\tempb{\meaning#1}%
>   \expandafter\endgroup
>   \ifx\tempa\tempb
>     \expandafter\FirstOfTwo
>   \else
>     \expandafter\SecondOfTwo
>   \fi
> }
> \long\def\FirstOfTwo#1#2{#1}
> \long\def\SecondOfTwo#1#2{#2}
>
> \long\def\Test#1{%
>   \ifprimitivecs{#1}{%
>     \immediate\write16{\string#1 is original primitive}%
>   }{%
>     \immediate\write16{\string#1 is something else}%
>   }%
> }
> \Test\hbox
> \Test\engraf
> \Test\ %
> \Test\-
> \Test\/
> \Test\par
> \begingroup
>   \immediate\write16{Redefine \string\par}%
>   \def\par{\endgraf}%
>   \Test\par
> \endgroup
>
> \csname @@end\endcsname\end
>
> Yours sincerely
>   Heiko Oberdiek


More information about the texhax mailing list