I’ve encountered a strange behavior when typesetting long math expressions in Typst, particularly when the line breaks across operators. It seems that when I break a line inside a math expression, superscripts (and subscripts too) don’t render properly.
Here’s a minimal example:
$
y = (a x^2 + \
+ b x + c)^2
$
and this is what I get:
Is this expected behavior? Or am I missing a better way to break long equations over multiple lines while preserving correct math formatting?
Hello, there. You provided screenshot from different code, there is no plus sign to the left of the b. And with cutting like this, it changes from addition to signed value:
You need to add med or something to make it readable.
Looks like lr creates a new scope. I don’t know how practical it is to break a parenthesized expression, but you can cancel the automatic sizing:
$
y = \(a x^2 + \
+ b x + c)^2
$
If you need it back, then you would probably have to recreate it manually:
#let big(p) = $lr(size: #200%, #p)$
$
y = big(\()1 / a x^2 + \
+ med b x + c big(\))^2
$
$
y = \(1 / a x^2 + \
+ med b x + c \)^2
$
$
y = (1 / a x^2 + b x + c)^2
$
I added a comment to the github issue, but this is definitely a bug in the math layout code. Want to echo that the general solution is to escape the parentheses with backslashes: $ y = \(a x^2 + \ + b x + c\)^2 $ which will avoid creating the LR element that causes the grouping behavior.