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.

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.

1 Like