Generic grouping syntax like in LaTeX

In LaTeX, you use { } to group expressions, e.g. for attachments. In Typst, you do that with ( ). Understandably, though, ( ) outside of those situations renders as actual parentheses. But in LaTeX, you can also use { } directly in normal equations with no special syntactic role. You can write e.g. 1 + {2 + 3}, which renders like 1 + 2 + 3 would.

However, I find that { } in LaTeX also has nice properties that I’m having trouble finding Typst equivalents for. Unfortunately, I don’t know the actual under-the-hood semantics of { }, so I’m going to describe my mental model here.

In LaTeX, { } will make LaTeX parse the semantic meaning of everything inside the braces separately from everything outside. So, for instance, if you write 1 {+ 2}, the + will be treated as a unary operator even though it’s preceded by another operand. Then, the spacing to the outside of the braces is calculated as if the braces were an ordinary operand, like x or 2.

Some example uses:

  1. Turn an operator into a normal symbol. For instance, some theories will use * as the name of a value, but LaTeX sees it as an operator in many cases. You can write e.g. 3 {*} + 2 to avoid this being parsed as {3} * {+2}.
  2. Avoid something being parsed as a function application, if you e.g. use the convention of writing log x instead of log(x) normally, but still want to group something like log (x + y). log {(x + y)} ensures this isn’t displayed as log(x + y).

As far as I can tell, Typst doesn’t have anything that works like that. I was initially optimistic that #$$ would, e.g., $log #$(x + y)$$. But that doesn’t work.

You can solve case #1 by using class, but using class is always a bit clunky.

Do you think it would be a good idea to add something like this to Typst? Maybe a group function? Or some special syntax? Or does something like this already exist and I missed it? Or do you think it’s not useful at all?