My article has a section about Differential Forms. For convenience, I defined
#let dx = $dif x$
However when I do f dx the spacing is normal, but in f(x) dx^1 the d just sticks to the paren.
I guess this is due to when I do dx^1, it takes dx as an operator, no longer a sequence that has a spacing. If there is not a workaround I would stick to dif x.
But when doing dx wedge dy (or dif x wedge dif y), where wedge is just and, dy seems closer to the wedge than dx. When doing dx^1 wedge dy^2, the spacing is normal but, the spacing in the front disappears.
Is there currently a good and graceful way (to deal with the spacing) in Typst to solve this? If not, can I add a space as convenient as LaTeX’s \, or \;?
Yes, there are predefined spacing constants like: thin, med, thick, quad and more. By default the definition of dif uses a thin space but in a weak version.
You could use the physica package which has one solution to this: a different way of calling and using differentials, like this:
#import "@preview/physica:0.9.5": dd
$ integral f(x) dd(x) $
$ integral f(x) dd(x^1, y^1) $
$ integral f(x) dd(x^1, y^1, p: and) $
$ integral f(x) dd(x, 3) $
Testing the following cases, seen below, I think this is the best we can do so far. With a custom adjustment to attach to “move” the thin weak space from inside of the attach to before it.
#let thinweak = h(math.thin.amount, weak: true)
#let dx = $dif x$ // dif is the same as thinweak upright(d)
#let starts-with(body, item) = {
if body.func() == math.equation { return starts-with(body.body, item) }
body.func() == [].func() and body.children.at(0) == item
}
#show math.attach: it => {
if starts-with(it.base, math.dif) {
thinweak + it
} else {
it
}
}
$f dx + g dx$\
$f dx^1 + g dx^1$\
$A dx and dx$\
$B dx^1 and dx^2$\
$1 + dx$\
$2(dx + 1)$\
$display(integral dx integral dx^1 integral f dx^1 and g dx^1)$\
We could ask why the space in dif and here is weak at all - the answer is the case with (dx) where we need the space in front to collapse, which it does if it is weak(?)