[OS X TeX] A problem with catcodes

Ross Moore ross at ics.mq.edu.au
Thu Apr 12 17:44:12 CEST 2007


Hi Alessio,

On 12/04/2007, at 2:29 PM, Alessio Guglielmi wrote:

> Hi,

> The macro \aaa redefines the `.' character as active, so that when  
> one types `.', one gets a cross.
>
> This generally works, but it doesn't when what follows \aaa is an  
> argument in a macro call, for example, when used inside a \bbb call  
> as below. The example shows the two different behaviours. I gather  
> that the problem is due to the fact that when arguments are read,  
> they are transformed into lists of tokens, so that the \catcode  
> commands in \aaa lose their effect. I'm not entirely sure I  
> understood this right.
>
> My problem is to define \aaa in such a way that the dot is always  
> typed as a cross, and without altering in any way \bbb and its use.  
> I can change the way \aaa is used. For example, \aaa could be a  
> macro accepting one argument. In other words, a different  
> definition of \aaa, for example involving calling it as \aaa{.},  
> would be acceptable.

Changing the \catcode of a character only works when the
character is first read in, ...

> Any help is very much appreciated, not just by me, but also by a  
> small (but growing) community of people using my macros.
>
> Ciao,
>
> -Alessio
>
>
> %----------------------------------------------------
> \documentclass{article}
>
> {
> \catcode`.=\active
> \gdef\aaa {\catcode`.=\active\let.=\times}
> }
>
> \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.

The argument, namely  "$\aaa .$"  has been completely read
and tokenised *before* the \aaa  has had a chance to act.
Thus the '.' is already a '.' and cannot be changed to \times .

You need a 2-step macro; defined something like this:

\def\bbb{\bgroup\catcode`\.=\active \bbbb}
{\let`\.=\active
  \gdef\bbbb#1{\let.\times #1\egroup}
}

Now  \bbb{$.$}  should work as you wish it to.


>
> \end{document}
> %----------------------------------------------------

Hope this helps,

	Ross


------------------------------------------------------------------------
Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia  2109                            fax: +61 +2 9850 8114
------------------------------------------------------------------------



------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list