Changes

Jump to navigation Jump to search
Add hint for parsing keyval arguments with TeX interface.
< [[Inside ConTeXt]]
 
== Using ConTeXt ==
 
To parse your own optional keyval argument from a command. You may want to adapt the logic according to your needs. Note that in the example below, <tt>[#1]</tt> is not optional.
 
<texcode>
\tolerant\protected\def\MyCommand[#1]#2
{\ifempty{#1}%
I only got \quote{#2}.
\orelse\ifhastok={#1}%
\getdummyparameters[MyOwnKeyOne={},MyOwnKeyTwo={B},#1]
% this is to define default values; overwritten when mentioned as part of ",#1"
\ifcstok{\dummyparameter{MyOwnKeyOne}}\emptytoks
\else
% if this one is not empty, we do ...
Here is #1!
\fi
And I also got \quote{#2}.
\else
#1 and #2 % whatever
\fi}
</texcode>
 
Of course, one can pass on <tt>#1</tt> as argument to other commands. If <tt>MyOwnKeyOne</tt> is not matched by its argument list, it's ignored.
 
See also https://www.mail-archive.com/ntg-context@ntg.nl/msg100795.html.
== Using Lua ==
57

edits

Navigation menu