ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Vit Zyka <vit.zyka@seznam.cz>
Subject: key=value parameters
Date: Fri, 23 Jul 2004 10:46:10 +0200	[thread overview]
Message-ID: <4100D052.5070801@seznam.cz> (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

             reply	other threads:[~2004-07-23  8:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-23  8:46 Vit Zyka [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4100D052.5070801@seznam.cz \
    --to=vit.zyka@seznam.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).