# [OS X TeX] A problem with catcodes

Morten Høgholm morten.hoegholm at gmail.com
Thu Apr 12 12:20:45 EDT 2007

On 4/12/07, Ross Moore <ross at ics.mq.edu.au> wrote:

> > \def\bbb #1{#1}
>
>   ... the argument is read-in when \bbb is encountered ...
>
> >
> > \begin{document}
> >
> > $\aaa .$
> >
> > \bbb{$\aaa .$}
>
>    ... so this cannot work as you want it to.

Yes it can, one just have to unlock the catcodes again.

\documentclass{article}

{
\catcode.=\active
\gdef\aaa {\catcode.=\active\let.=\times}
}

\def\ReactivateChars#1{%
\begingroup
\endlinechar=-1\relax% otherwise \endlinechar is inserted
% can also be prevented by \noexpand at the end but requires
% \endlinechar to be -1, 13 or 32 and \everyoef to be empty.
\everyeof{}% clear it, just to be safe
\scantokens{\endgroup#1}%
}

\def\bbb #1{\ReactivateChars{#1}}

\begin{document}

$\aaa .$

\bbb{$\aaa .$}no space added I hope

\bbb{$\aaa .$} normal space added I hope

\end{document}

The problem here of course being that then it only works for commands
being augmented with \ReactivateChars. I could do something like that
for xparse though since there I have control over all arguments being
parsed at the document level.
--
Morten