ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* key=value parameters
@ 2004-07-23  8:46 Vit Zyka
  2004-07-23  9:12 ` Taco Hoekwater
  0 siblings, 1 reply; 8+ messages in thread
From: Vit Zyka @ 2004-07-23  8:46 UTC (permalink / raw)


Hallo ConTeXters,

I am playing with defining my own macro with key=value parameters. 
Please, consider definition:

   \def\setupField[#1]#2[#3]{\getparameters[Field!#1!][#3]}
   \setupField[name][mykey=value,textwidth=2cm]

If you let ConTeXt to show the values by

   \message{
     <mykey=\getvalue{Field!name!mykey}>
     <textwidth=\getvalue{Field!name!textwidth}>
     <tekstbreedte=\getvalue{Field!name!tekstbreedte}> }

you obtain

   <mykey=value>
   <textwidth=\Field!name!textwidth >
   <tekstbreedte=2cm>

While 'mykey' is OK, predefined keys (like textwidth, text, style, ...) 
lead to undefined parameter, that behave like \relax.

I can imagine next solutions:
1) Do not use predefined keys in my macros, e.g. textWidth instead of
    textwidth [=user unfriendly].
2) Use original (mostly Dutch) keys inside of my macros
    [=developer unfriendly].
3) Define:
      \unprotect
      \def\getparametersALL{\dogetparameters\dosetvalueALL}
      \def\dosetvalueALL#1#2{\@EA\def\csname#1#2\endcsname}
      \protect

    and use:
      \def\setupField[#1]#2[#3]{\getparametersALL[Field!#1!][#3]}
      \setupField[name][mykey=value,textwidth=2cm]
      \message{
        <mykey=\getvalue{Field!name!mykey}>
        <textwidth=\getvalue{Field!name!textwidth}>
        <tekstbreedte=\getvalue{Field!name!tekstbreedte}> }

    it gives:
      <mykey=value>
      <textwidth=2cm>
      <tekstbreedte=\Field!enname!tekstbreedte>

Is there any other (more elegant and not-so-dirty) solution?

Thankx
Vit Zyka

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

* Re: key=value parameters
  2004-07-23  8:46 key=value parameters Vit Zyka
@ 2004-07-23  9:12 ` Taco Hoekwater
  2004-07-23 10:53   ` Vit Zyka
  0 siblings, 1 reply; 8+ messages in thread
From: Taco Hoekwater @ 2004-07-23  9:12 UTC (permalink / raw)



Hi Vit,

On Fri, 23 Jul 2004 10:46:10 +0200, Vit wrote:
> 
> I can imagine next solutions:
> 1) Do not use predefined keys in my macros, e.g. textWidth instead of
>     textwidth [=user unfriendly].

If you decide on this solution, please use Textwidth instead (at least
something that starts with a capital letter). 

> 2) Use original (mostly Dutch) keys inside of my macros
>     [=developer unfriendly].

In this case, the "correct" solution is to use the interfaced versions 
like \c!tekstbreedte et al. inside your macros. This is unwieldy if you 
are not very familiar with the ConTeXt source, but it allows multilingual
input (very user friendly).

> 3) Define:
>       \unprotect
>       \def\getparametersALL{\dogetparameters\dosetvalueALL}

Actually there is no need to define anything, you can just use \rawgetparameters 
instead of  \getparameters.

-- 
groeten,

Taco

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

* Re: key=value parameters
  2004-07-23  9:12 ` Taco Hoekwater
@ 2004-07-23 10:53   ` Vit Zyka
  2004-07-23 11:07     ` Taco Hoekwater
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Vit Zyka @ 2004-07-23 10:53 UTC (permalink / raw)


Thank you Taco.

>>I can imagine next solutions:
>>1) Do not use predefined keys in my macros, e.g. textWidth instead of
>>    textwidth [=user unfriendly].
> 
> If you decide on this solution, please use Textwidth instead (at least
> something that starts with a capital letter). 

OK, but I do not like this solution.

>>2) Use original (mostly Dutch) keys inside of my macros
>>    [=developer unfriendly].
> 
> In this case, the "correct" solution is to use the interfaced versions 
> like \c!tekstbreedte et al. inside your macros. This is unwieldy if you 
> are not very familiar with the ConTeXt source, but it allows multilingual
> input (very user friendly).

That is true I was not familiar about \c!... But problem is not in 
familiarity with ConTeXt source but Dutch language. One should write 
\c!tekstbreedte instead of \c!textwidth. For non Dutch it means all the 
time search at mult-*.tex. I know, solution is to learn Dutch... Hans 
has plan to rewrite all code to English, hasn't it?
Very good idea.

Multilingual input:
- In late 90. when I met ConTeXt first time, I was very confused. Some 
macros work, something was ignored. It took several days to discover 
that I have to write (in my czech format) \nastavbarvy instead of 
\setupcolors. After that I quickly switch to english interface.
- Multilingual interface is a nice example of ConTeXt capability, but a 
bit inpractical. It keeps from source code exchange. I can imagine some 
transtlators, but...
- I think there is no many ConTeXt users (even any?) that use non 
English or non Dutch interface (languages in which reference manual is 
written).

>>3) Define:
>>      \unprotect
>>      \def\getparametersALL{\dogetparameters\dosetvalueALL}
> 
> Actually there is no need to define anything, you can just use \rawgetparameters 
> instead of  \getparameters.

Great, but unfortunately it does not work with empty parameter list [].
No I have no time but I will look for better definition of 
\rawgetparameters and \rawsetparameter.

Vit Zyka

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

* Re: key=value parameters
  2004-07-23 10:53   ` Vit Zyka
@ 2004-07-23 11:07     ` Taco Hoekwater
  2004-07-23 11:32     ` Re[2]: " Giuseppe Bilotta
  2004-07-23 18:46     ` Hans Hagen Outside
  2 siblings, 0 replies; 8+ messages in thread
From: Taco Hoekwater @ 2004-07-23 11:07 UTC (permalink / raw)


On Fri, 23 Jul 2004 12:53:33 +0200
Vit Zyka <vit.zyka@seznam.cz> wrote:

> That is true I was not familiar about \c!... But problem is not in 
> familiarity with ConTeXt source but Dutch language. One should write 
> \c!tekstbreedte instead of \c!textwidth. For non Dutch it means all the 
> time search at mult-*.tex. 

For me too, I have not used the dutch interface in years and have forgotten
most of the low-level dutch names. I am also eagerly awaiting a fully 
english version.

> > Actually there is no need to define anything, you can just use \rawgetparameters 
> > instead of  \getparameters.
> 
> Great, but unfortunately it does not work with empty parameter list [].

I did not know that. Too bad.

Greetings, Taco

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

* Re[2]: key=value parameters
  2004-07-23 10:53   ` Vit Zyka
  2004-07-23 11:07     ` Taco Hoekwater
@ 2004-07-23 11:32     ` Giuseppe Bilotta
  2004-07-23 18:46     ` Hans Hagen Outside
  2 siblings, 0 replies; 8+ messages in thread
From: Giuseppe Bilotta @ 2004-07-23 11:32 UTC (permalink / raw)


Friday, July 23, 2004 Vit Zyka wrote:

>> Actually there is no need to define anything, you can just use \rawgetparameters
>> instead of  \getparameters.

> Great, but unfortunately it does not work with empty parameter list [].
> No I have no time but I will look for better definition of 
> \rawgetparameters and \rawsetparameter.

A common workaround to this problem (which Hans should fix,
though) is to force the list to not be empty.

Say for example that parameter #1 of your macro accepts the
user list of key=values. you would then use

\rawgetparameters[something=else,#1]

This way, even if #1 is empty it will work.

-- 
Giuseppe "Oblomov" Bilotta

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

* Re: key=value parameters
  2004-07-23 10:53   ` Vit Zyka
  2004-07-23 11:07     ` Taco Hoekwater
  2004-07-23 11:32     ` Re[2]: " Giuseppe Bilotta
@ 2004-07-23 18:46     ` Hans Hagen Outside
  2004-07-24  8:56       ` Vit Zyka
  2 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen Outside @ 2004-07-23 18:46 UTC (permalink / raw)


Vit Zyka wrote:

> Great, but unfortunately it does not work with empty parameter list [].
> No I have no time but I will look for better definition of 
> \rawgetparameters and \rawsetparameter.

I fixed this a while ago, and not have: 

%D \macros
%D   {rawgetparameters}
%D
%D A raw and dirty alternative for \type {\getparameters}; no
%D checking is done!

% \def\rawgetparameters[#1][#2]% scheelt 5\%
%   {\def\rawparameterprefix{#1}%
%    \expandafter\rawsetparameter#2,]=,}
%
% \def\rawsetparameter#1=#2,%
%   {\if]#1\else
%      \expandafter\def\csname\rawparameterprefix#1\endcsname{#2}%
%      \expandafter\rawsetparameter
%    \fi}
%
% the next one handles empty #1 okay:

\def\rawgetparameters[#1][#2% some 5-10% faster
  {\ifx#2]% test is needed, else bomb on [#1][]
     \expandafter\gobbleoneargument
   \else
     \def\rawparameterprefix{#1}%
     \expandafter\dorawgetparameters
   \fi#2}

\def\dorawgetparameters#1]%
  {\expandafter\rawsetparameter#1,]=,}

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

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

* Re: key=value parameters
  2004-07-23 18:46     ` Hans Hagen Outside
@ 2004-07-24  8:56       ` Vit Zyka
  2004-07-24 16:10         ` Hans Hagen Outside
  0 siblings, 1 reply; 8+ messages in thread
From: Vit Zyka @ 2004-07-24  8:56 UTC (permalink / raw)


>> Great, but unfortunately it does not work with empty parameter list [].
>> No I have no time but I will look for better definition of 
>> \rawgetparameters and \rawsetparameter.
> 
> I fixed this a while ago, and not have:
> \def\rawgetparameters[#1][#2% some 5-10% faster
>  {\ifx#2]% test is needed, else bomb on [#1][]
>     \expandafter\gobbleoneargument
>   \else
>     \def\rawparameterprefix{#1}%
>     \expandafter\dorawgetparameters
>   \fi#2}
> 
> \def\dorawgetparameters#1]%
>  {\expandafter\rawsetparameter#1,]=,}

Thankx for quick response, even from outside Hans, this solves the empty 
list problem, but unfortunately not the problem with newline in param list:
   \MyMacro[Field][param1=value,
      param2=value]
and in this way it is incompatible with \setparameters.

What about use the same parameter parser as in the \setparameters:

   \def\rawgetparameters{\dogetparameters\rawdosetvalue}
   \def\rawdosetvalue#1#2{\@EA\def\csname#1#2\endcsname}

Vit Zyka

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

* Re: key=value parameters
  2004-07-24  8:56       ` Vit Zyka
@ 2004-07-24 16:10         ` Hans Hagen Outside
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Hagen Outside @ 2004-07-24 16:10 UTC (permalink / raw)


Vit Zyka wrote:

>
> What about use the same parameter parser as in the \setparameters:
>
>   \def\rawgetparameters{\dogetparameters\rawdosetvalue}
>   \def\rawdosetvalue#1#2{\@EA\def\csname#1#2\endcsname}

there's:  

\setvariables[namespace][key=value]

\getvariable{namespace}{key}

the raw ones are for situations where speed is needed, so don't touch the definitions  

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

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

end of thread, other threads:[~2004-07-24 16:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23  8:46 key=value parameters Vit Zyka
2004-07-23  9:12 ` Taco Hoekwater
2004-07-23 10:53   ` Vit Zyka
2004-07-23 11:07     ` Taco Hoekwater
2004-07-23 11:32     ` Re[2]: " Giuseppe Bilotta
2004-07-23 18:46     ` Hans Hagen Outside
2004-07-24  8:56       ` Vit Zyka
2004-07-24 16:10         ` Hans Hagen Outside

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).