On Sat, 15 Nov 2008, Wolfgang Schuster wrote:
>
> Am 14.11.2008 um 19:37 schrieb Aditya Mahajan:
>
>> On Fri, 14 Nov 2008, Aditya Mahajan wrote:
>>
>>> On Fri, 14 Nov 2008, Wolfgang Schuster wrote:
>>>
>>>> Hi,
>>>>
>>>> I make in a module the comment sign a simple letter to pass
>>>> number formats to a lua function and want to know if should
>>>> use another (better) way to change the catodes.
>>>
>>> I think it will be cleaner to use catcode tables. See syst-cat.mkiv.
>>
>> and syst-cat.tex
>
> I keep now my low level solution but with fewer lines.
Even though you are still using the mailling list, I will reply :-)
> To help other users with the same question I present
> here my solution:
>
> \def\????ax{@@@@ax}
>
> \def\setupaxis
> {\catcode`\%\@@letter
> \dodoubleargument\dosetupaxis}
>
> \def\dosetupaxis[#1][#2]%
> {\def\docommand##1{\getparameters[\????ax##1][#2]}%
> \catcode`\%\@@comment
> \processcommalist[#1]\docommand}
>
> \setupaxis
> [\c!x,\c!y]
> [\c!format=%d]
Here you are assuming that whenever \setupaxis will be used, the catcode
of % is comment. This may not be the case. You can of course, store the
inital catcode of % and then restore it later, as done by many LaTeX
packages.
The main advantage of catcode tables is that you can do
\pushcatcodetable, and \popcatcodetable, and not do the book keeping
yourself. Here is a solution using catcodetables:
\unprotect
% A mixture of \startcatcodetable and \extendcatcodetable
\long\def\startchangecatcodetable#1#2#3\stopchangecatcodetable
{\bgroup
\catcodetable\scratchcatcodetable
\catcodetable#1\relax
#3%
\savecatcodetable#2\relax
\egroup}
\newcatcodetable \LUAstringcatcodes
\startchangecatcodetable \ctxcatcodes \LUAstringcatcodes
\catcode`\%\@@letter
\stopchangecatcodetable
\protect
\starttext
\pushcatcodetable
\catcodetable\LUAstringcatcodes
% Does this print
Hello world
\popcatcodetable
\stoptext
So, you code now becomes
\unprotect
\def\????ax{@@@@ax}
\def\setupaxis
{\pushcatcodetable
\catcodetable\LUAstringcatcodes
\dodoubleargument\dosetupaxis}
\def\dosetupaxis[#1][#2]%
{\def\docommand##1{\getparameters[\????ax##1][#2]}%
\popcatcodetable
\processcommalist[#1]\docommand}
\setupaxis
[\c!x,\c!y]
[\c!format=%d]
Hans, do you think that something like \startchangecatcodetable should be
added to the core. An old definition of \extendcatcodetable almost does
that, but does not provide a name to the resulatant catcodetable.
Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________