How can I supply an argument that contains a comma

I wanted to define a macro to denote the ring ideal generated by some elements. In latex I would do $\newcommand{\gen}[1]{\langle #1\rangle}$ so I could do $\gen{x}$ or $\gen{x, y}$ or $\gen{\{x \mid n \in \phi(x)\}}$ to typeset the ideal generated by one element, two elements, resp. a set of elements.

In Typst, I tried to define #let gen(generators) = $angle.l generators angle.r$. Then $gen(x)$ works fine, but when doing $gen(x, y)$, it understandibly thinks that I want to supply two arguments to a function taking only one argument. What would be the idiomatic way to proceed here?

I know of at least the following tricks. There are probably other ways of doing this, and they might not all be identical down to the pixel.

// escape the comma
$gen(x\, y)$
$gen(x"," y)$
$gen(x#[,] y)$

// group "x,y" as one item
$gen(#{$x,y$})$
$gen(#$x,y$)$

// cursed
$gen(#eval("x,y", mode: "math"))$
1 Like

I’d say it’s best to copy what, for example, the math.lr function does internally here and reconstruct the commas. Something like this would work: (hopefully this works, can’t test on my phone :sweat_smile:)

#let gen(size: 100%, ..args) = {
  let generators = args.pos().join($,$)
  $lr(angle.l generators angle.r, size: size)$
}

(I added a size parameter for completeness, matching math.abs, etc.)

3 Likes