(Opinions needed) Likely upcoming changes to math mode precedence

I know I’m a bit late, but I think that an Option F is missing from the suggested solutions: Always greedily match subscripts as far right as possible. That is, f_i(x), f_1(2+2) or g_3(y) would put everything to the right of _ into the subscript. This eliminates all ambiguity, and lets the user determine this with spaces.

This behavior mirrors what new users encounter with implicit multiplication: Writing ab + x produces an error, as ab is parsed as a function. Thus, they have to write a b + x. In exchange, they get functions without leading delimiters (# or \), leading to much cleaner syntax.

The same can be applied for subscripts. In long expressions, reducing parentheses makes code more readable. Letting users control subscripts with x_2(i+1) or f_2 (i+1) achieves this.

Cons:

  • Requires more spaces in the simple cases such as f_1 (x)
  • For simple subscripts, this contradicts the expected behavior from LaTeX, unlike the proposed solution.
  • Is a breaking change, (with wide-spread effect)

Pros:

  • Achieves the same unambiguous parsing as the proposed solution
  • Allows using spaces as a typographic tool, leading to more readable syntax-code than wide parentheses.

I hope this option can be considered – I think a minimal syntax is a key strength of Typst, and is a goal that should be pursued.

7 Likes