Optional delimited arguments with key-value sets?

Hi ConTeXt users, I'm trying to build a user-defined command called *mycommand* and followed the hints on (https://wiki.contextgarden.net/ConTeXt_and_Lua_programming/Tutorials/System_...) \def\dodefinemycommand[#1][#2]% {\getparameters[\??xx#1][#2]} \def\mycommand% {\dodoubleargumentwithset\dodefinemycommand\strut\blank[2*big] See what happens: \@@xxonex} and call it with: *\mycommand[one,two][x=1,y=2]* ** This yields a fatal error; while I'd expect something like: *See what happens: 1* What am I doing wrong here? ** ** Gerard P.S. Currently using version: 2023.02.14 17:44!

Am 23.04.2025 um 17:33 schrieb G.C.H.M. Verhaag via ntg-context:
Hi ConTeXt users,
I'm trying to build a user-defined command called *mycommand* and followed the hints on (https://wiki.contextgarden.net/ ConTeXt_and_Lua_programming/Tutorials/System_Macros/Handling_Arguments)
\def\dodefinemycommand[#1][#2]% {\getparameters[\??xx#1][#2]}
\def\mycommand% {\dodoubleargumentwithset\dodefinemycommand\strut\blank[2*big] See what happens: \@@xxonex}
and call it with:
*\mycommand[one,two][x=1,y=2]*
**
This yields a fatal error; while I'd expect something like:
*See what happens: 1*
What am I doing wrong here?
You can't use ? or @ as part of command names unless you use \unprotect .. \protect when you create and access them. In the following example the first \@@test command which is placed in the protect works as expected but the second fails because TeX treats only \@ as command (which doesn't exists and results in an error) and everything afterwads (i.e. @test) is simple text. %%%% begin example \starttext \unprotect \def\@@test{[test]} A\@@test B \protect A\@@test B \stoptext %%%% end example Below is a simple definition of \mycommand which uses the old method to create optional arguments. There are better ways to achieve the same result with newer ConTeXt versions but you didn't provide enough information about your goal. %%%% begin example \starttext \protected\def\mycommand {\dodoubleargument\domycommand} \def\domycommand[#1][#2]% {\def\dodomycommand##1{\getparameters[mycommand##1][#2]}% \processcommalist[#1]\dodomycommand % See what happens: \getvalue{mycommandonex}} \mycommand[one,two][x=1,y=2] \stoptext %%%% end example Wolfgang

Hi Wolfgang, Thanks for your explanation; but I was unable to grasp it, sorry! I don't have an application for it yet, but simply followed the wiki manual page to find out whether I could use this feature. Being unable to figure out why it didn't work, I decided to ask this question. Being a simple user of ConTeXt, I consider all this far too complicated, and have decided not to dig any deeper. My eyes don't allow very much screen work, due to my old age. Spending too much time at the computer screen isn't an option for me anymore! But I appreciate your effort in trying to help me understand it! Regards, Gerard
participants (3)
-
G.C.H.M. Verhaag
-
Gerard Verhaag
-
Wolfgang Schuster