Optional parameter in custom function to specify color

I was able to create a shorthand to cancel() like this:

#let cl(x) = math.cancel(x);

But I thought it would be nice to allow an optional parameter to specify color: how would you go about this?

Use argument sink, then check on the length of the positional arguments.

1 Like

if you do one of these:

#let cl = math.cancel
// or
#let cl(..args) = math.cancel(..args)

Then cl supports all the same arguments as math.cancel. The first one is the simplest, the second one is the starting point if you want to have further logic or change a few default values (while still allowing them to be specified directly.)

The regular parameter for color (and the stroke) is called stroke.

3 Likes

Thanks everyone!

The next step would be for the script to look for ‘special’ arguments which are a shorthand for color (eg. dd for red, yy for yellow etc.): I suppose I’ll figure that out one day!