Forcing unary minus in math

How does one force - to be interpreted as unary in $"if" -x$ ?

The solution I came up with is $"if " #h(0em) -x$.

See example here https://typst.app/project/rxngGTGMnj4UAEVrMj7WNu

Is there a simpler way to do this?

In LaTeX I would just use {-x}. But trying similar things in Typst does not seem to work: $"if" #($-x$)$ $"if" #{$-x$}$

1 Like

try math.class:

$ "if" class("unary", -) x $

maybe

#let umin = math.class("unary", $-$)
$ "if" umin x $

perhaps even

#show sym.minus: math.class.with("unary")
$ "if" -x $
2 Likes

It’s also possible to use a container for your second approach to work:

$"if" #box[$-x$]$

2 Likes

This seems pretty complicated. I’m surprised that $-x$ doesn’t always render as unary minus and $- x$ as regular minus. Or perhaps any instance of -x (that is space, then minus, then symbol).

2 Likes