ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* catcode change in macros
@ 2008-11-14 18:22 Wolfgang Schuster
  2008-11-14 18:36 ` Aditya Mahajan
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Schuster @ 2008-11-14 18:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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.


\def\????ax{@@@@ax}

\bgroup

\catcode`\%=11
\catcode`\:=14

\gdef\setupaxis
   {\catcode`\%=11
    \catcode`\:=14
    \dodoubleargument\dosetupaxis}

\gdef\dosetupaxis[#1][#2]:
   {\catcode`\%=11
    \catcode`\:=14
    \def\docommand##1{\getparameters[\????ax##1][#2]}:
    \catcode`\%=14
    \catcode`\:=12
    \processcommalist[#1]\docommand}

\egroup

\setupaxis
   [\c!x,\c!y]
   [\c!format=%d]


Regards,
Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-14 18:22 catcode change in macros Wolfgang Schuster
@ 2008-11-14 18:36 ` Aditya Mahajan
  2008-11-14 18:37   ` Aditya Mahajan
  0 siblings, 1 reply; 8+ messages in thread
From: Aditya Mahajan @ 2008-11-14 18:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-14 18:36 ` Aditya Mahajan
@ 2008-11-14 18:37   ` Aditya Mahajan
  2008-11-14 18:51     ` Wolfgang Schuster
  2008-11-15 13:13     ` Wolfgang Schuster
  0 siblings, 2 replies; 8+ messages in thread
From: Aditya Mahajan @ 2008-11-14 18:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-14 18:37   ` Aditya Mahajan
@ 2008-11-14 18:51     ` Wolfgang Schuster
  2008-11-15 13:13     ` Wolfgang Schuster
  1 sibling, 0 replies; 8+ messages in thread
From: Wolfgang Schuster @ 2008-11-14 18:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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 already know them but you're right, it's better
to use them and avoid low level code.

P.S. Should I now send all my questions to you or
      still use the mailing list :)

Thanks and regards,
Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-14 18:37   ` Aditya Mahajan
  2008-11-14 18:51     ` Wolfgang Schuster
@ 2008-11-15 13:13     ` Wolfgang Schuster
  2008-11-15 20:06       ` Aditya Mahajan
  1 sibling, 1 reply; 8+ messages in thread
From: Wolfgang Schuster @ 2008-11-15 13:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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.

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]

Regards,
Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-15 13:13     ` Wolfgang Schuster
@ 2008-11-15 20:06       ` Aditya Mahajan
  2008-11-15 20:41         ` Hans Hagen
  0 siblings, 1 reply; 8+ messages in thread
From: Aditya Mahajan @ 2008-11-15 20:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-15 20:06       ` Aditya Mahajan
@ 2008-11-15 20:41         ` Hans Hagen
  2008-11-15 20:59           ` Wolfgang Schuster
  0 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2008-11-15 20:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Aditya Mahajan wrote:
> 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.

i wonder if change is the right name, isn't it more cloning?

anyhow, keep in mind that in mkiv we print back to tex every now and 
then and then we use one of the predefined catcode tables.

Another option is:

  [\c!format=\letterpercent d]

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: catcode change in macros
  2008-11-15 20:41         ` Hans Hagen
@ 2008-11-15 20:59           ` Wolfgang Schuster
  0 siblings, 0 replies; 8+ messages in thread
From: Wolfgang Schuster @ 2008-11-15 20:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 15.11.2008 um 21:41 schrieb Hans Hagen:

> Aditya Mahajan wrote:
>> 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.

Right but I dropped catcode tables because I had a problems
with them (see below).

>> 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:
>>

I can't use it in my macro.

\unprotect

\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

\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]

\protect

\starttext
\getvalue{@@@@axxformat}
\stoptext

>> 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.
>
> i wonder if change is the right name, isn't it more cloning?
>
> anyhow, keep in mind that in mkiv we print back to tex every now and
> then and then we use one of the predefined catcode tables.

I save \@@@@axxformat in a Lua table and use it only in string.format,
it never appears in the output.

> Another option is:
>
>  [\c!format=\letterpercent d]

No interest, if I want %d to format my string in Lua I want
to write also in this format in TeX.

Wolfgang


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-11-15 20:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-14 18:22 catcode change in macros Wolfgang Schuster
2008-11-14 18:36 ` Aditya Mahajan
2008-11-14 18:37   ` Aditya Mahajan
2008-11-14 18:51     ` Wolfgang Schuster
2008-11-15 13:13     ` Wolfgang Schuster
2008-11-15 20:06       ` Aditya Mahajan
2008-11-15 20:41         ` Hans Hagen
2008-11-15 20:59           ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).