Changes

Jump to navigation Jump to search
added texcode and cmd markup
< [[Inside ConTeXt]]
 
(a post on the mailing list by Taco Hoekwater from 2004-06-28:)
The 'key' to the keyval functionality in ConTeXt are two macros called
<ttcmd>\getparameters</ttcmd> and <ttcmd>\processaction</ttcmd>.
Here is a 'quickstart', assuming you want to define <tt>\MyZigzag</tt>:
<pretexcode>
\unprotect % enable exclamations in macro names
\getparameters[ZZ][Dir=,Linewidth=1pt,Color=Red,Width=3em,#2]
</pretexcode>
Now you have a set of new macros that all start with ZZ.
Here's a usage example:
<pretexcode>
\edef\mywidth{\ZZWidth}%
</pretexcode>
If you want to use keyword values, then you also need to use <ttcmd>\processaction</ttcmd>.
Say you want "Dir" to be mandatory and that it accepts 4 directional keywords, as well as a direct angle specification.
I've used all mixed case keywords, because otherwise you might run into conflicts with the multilingual interface
<pretexcode>
\expandafter\processaction\expandafter[\ZZDir]
[Down =>\def\Dir{270},
\s!unknown =>\checkDir{\ZZDir}]
} % this brace belongs to \def!
</pretexcode>
<tt>\s!default</tt> may be triggered because <tt>\ZZDir</tt>'s expansion is empty unless the user supplied something.
The first argument to \<cmd>processaction </cmd> has to be expanded, so you need the <ttcmd>\expandafter</ttcmd>s.
for completeness, here is an example definition of <tt>\checkDir</tt> and <tt>\errorDir</tt>:
<pretexcode>
\def\errorDir{%
\def\Dir{0}% error recovery
\protect % end of definitions
</pretexcode>

Navigation menu