How to control line breaks (wrap opportunities) in inline math?

#set page(height: auto, width: 10em, margin: 1em)
Then $exists x > 0, f(x) = y$ and why?

图片

How to allow the line to break after ,? I think the following would be better.

Then ∃x>0,
f(x) = y and
why?

Why can’t I split it?

$exists x > 0$, $f(x) = y$

My document is not English, and I have to use a dedicated font for my main text. The font provides a good glyph for this comma, but it does not fit well among Latin-like characters in math equations.

Moreover, I can’t set text(font: (covers: regex_matching_comma_period_etc, …)), because it will destroy kerning.

My (failed) attempts

  • Adding med/thin/etc. doesn’t break the line.
  • Inserting zwj/zwnj changes nothing.
  • Inserting a #linebreak() gives a weird result.
    图片
1 Like

You could just wrap the comma in a separate equation to get the correct font. The space of the comma relative to the zero looks to be equal to the case where everything is in the same equation. The space behind the comma will be wider by default because you have to use the “plain-text” space between the last two equations. This is however not an issue when you have a line break.

Then $exists x > 0$$,$ $f(x) = y$ and why?

Thank you! Inspired by your reply, I realize that I can simply write:

$exists x > 0,$ $f(x) = y$

But to be honest, I don’t think this is an elegant way…

2 Likes

Indeed, this is how you would split it.

Well, long inline math is hard to make look good. Typst is a WYSIWYM tool, so if you explicitly don’t say it to break, it won’t break. If you want, you can always open a new issue and see if others will agree. Perhaps this can be improved.

1 Like

WYSIWYM

But it breaks between> and 0!

I will create an issue when I have time, unless someone does it first.

True. I guess changing the breaking locations and their priority would be nice to have.

A related issue regarding customizable line breaking behaviour in math already exists:

1 Like

I’ve just found an exact issue:

Therefore, I will close this topic. Hope the linebreak algorithm will be improved someday.