[NTG-context] How to extend an existing macro to take optional parameters?

Bruce Horrocks ntg at scorecrow.com
Sun Mar 12 14:24:51 CET 2023

I have an existing macro that I'd like to extend.

The current definition is \define[3]\mycommand{...} which I'd like to extend to take an optional 4th parameter plus an optional setup parameter.

Thus I currently invoke it as:


and I'd like to be able to extend it so that any of the following can be used:



  \mycommand[ee]{aa}{bb}{cc}{dd}  % if this is more the ConTeXt way 

where {dd} is the optional extra parameter and, if it is present, then [ee] can also be optionally added (because it controls how {dd} is printed).

If it helps, the actual body of the macro can easily be a call to Lua so it's fine if the function takes 5 params where 4 and 5 can be nil or empty strings.

I've trawled through syst-aux.mkiv but it only covers optional numbers of [ ] or { } but not combinations of both (which given the vast numbers of combinations is perhaps not surprising!). Have I missed something obvious that would help me?

Bruce Horrocks
Hampshire, UK

More information about the ntg-context mailing list