There are two common ways to express function application:
- arguments in parentheses
f(x, y, z)
, which is currently supported well in Typst - juxtaposed style
f x y z
, common in functional programming, lambda calculus, and logic, but not supported very well in Typst
Today, juxtaposed variables (those written one after another, separated by spaces) will always be pushed together without any space between them:
#let bdot = math.class("relation", ".")
$(exists x bdot f x (g x) = (lambda y bdot h y) x)$
This causes a lot of trouble for domains where the juxtaposed syntax is common; in my case, this affects writing lambda calculus expressions. The current workaround is to manually add spaces just about everywhere:
#let bdot = math.class("relation", ".")
$(exists x bdot f" "x" "(g" "x) = (lambda y bdot h" "y)" "x)$
…but this is hard to read, quite fiddly, and not ergonomic.
Another solution might be to define a variable for every symbol used, assigning it the math class “relation”. However, this requires all symbols to be defined beforehand, and single-character variables in Typst have the additional ergonomic issue of requiring a preceding #
in math mode. This is arguably even worse than just adding spaces everywhere.
I think the ideal solution would be for the space-removing behavior of math mode to be configurable by a #set
statement; the current behavior would become the default, while preserving space around bare single-character variables would become an option that could be enabled. I take it this isn’t currently possible, judging by the number of questions about spacing in math mode (e.g. this one). I’d like to make the case that it should be supported; perhaps this could be incorporated in the design of the upcoming math overhaul which was teased in the description of PR #5738 and in the last comment on PR #4638
In the meantime, would it be possible to write a #show
rule to change the way spacing is handled in math mode? This could provide a better intermediate solution. I’m imagining something like:
#show math.term: it => {" " + it + " "}
…but my limited experienced with Typst scripting has me stuck on this front.
Thanks in advance!