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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to