Why does Typst allow minus signs in identifiers?

Kebab case may be a bit niche but still, apart form the already mentioned CSS and Lisp it’s used at least in COBOL (hum), Forth and Raku (Perl 6), and also modern Lisp variants like Clojure. It has two great advantages:

  • Easier to read than all the other options
  • Easier to type than snake case (in most keyboard layouts you need shift for _ but not for -)

and one great downside:

  • It’s ambiguous with subtraction in languages that have infix operators

I personnally love the Typst solution, which is to require spaces around the minus operator in code. Because this makes code even more readable. I think the biggest issue with kebab case in Typst is the inconsistency in math mode where #a-b and func(a-b: xxx) are parsed as one word but a-b alone is parsed as a - b. But it’s not a big deal either. I think the two benefits mentioned above make it well worth it.

2 Likes