Why does a line break inside math mode result in superscripts appearing at the wrong height?

Hi everyone,

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:
typst_example

Is this expected behavior? Or am I missing a better way to break long equations over multiple lines while preserving correct math formatting?

Thanks in advance!

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:

image

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
$

image

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
$

image


1 Like

This problem sounds like something that should be reported as a bug, so that it can be discussed if it’s a bug to be fixed or not.

1 Like

This issue has been known for a while, you can follow it on GitHub for any updates:

1 Like

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.