You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Large inline equations can overlap with other lines #1028
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.mathRelated to math category, with its syntax, layout, etc.
What is the state of this isssue ? It's actually a major bug because it limits a lot doing package that user will use with math block a lot.
Is the value of bottom-edge and top-edge suppose to be the fix like mention in #1626 ?
Because those parameters doesn't fix at all the problem that I have mention in #3368.
#1626 fixed a different issues. Fixing this properly would require some smart heuristic in the paragraph layout. Note that you can work around this by using block equations instead of inline equations.
changed the title [-]Paragraph leading does not respect large inline equations[/-][+]Large inline equations can overlap with other lines[/+]on Mar 21, 2024
@Enter-tainer It would be easy to just always expand lines to fit the equation. But that's also undesirable because it leads to uneven line spacing in many very common cases. Hence, we would need the paragraph layout to only expand the leading if truly necessary.
I wonder if there is any example about this. I cannot understand "It would be easy ... But that's also undesirable" well maybe because I cannot think of when it will become ugly. Is there a place I can tweak the code and see what it looks like if I want typst "always expand lines to fit the equation"?
I wonder if LaTeX does such "smart heuristic" when layouting inline equations. It seems that it always expand line height whenever it doesn't fit.
I also wonder if it is easy to fix(or implement) "always expand lines to fit the equation". It looks like typst currently tries to expand the line but for some reason(maybe there are already some heuristics?) it fails to correctly do it.
@Enter-tainer The following example demonstrates the case I'm talking about:
If the bounding boxes would be expanded fully, Typst's paragraph layout would add leading in between them and space the lines apart a lot. This case occurs quite frequently and the results would look really bad. For this reason, Typst has the naive workaround of just always pushing the bounding box of inline math somewhat inwards. A cleaner solution would be to ensure that nothing overlaps while keeping the lines spaced normally somehow.
As you can see, LaTeX also doesn't space the lines apart:
I'm not sure how it works in LaTeX, but it would only partly apply to Typst anyway because their line spacing model is very different. It's based on baselineskip rather than leading in between line bounding boxes.
@laurmaedje which files are relevant? Can you give me a list so I can learn how typst handles this at this moment.(And we can discuss how to improve it) I've discussed offline with @peng1999 and @Myriad-Dreamin about this.
I'm not sure how it works in LaTeX, but it would only partly apply to Typst anyway because their line spacing model is very different. It's based on baselineskip rather than leading in between line bounding boxes.
What do you think of this method: we calculate the baseline skip by adding the leading, along with the main text's ascender and descender height. We then adhere to this baseline skip unless formulas or other elements cause the bounding box to collide with the previous line's descender.
This is basically switching from the original line spacing model to the LaTeX model. Hopefully at most of the time they are compatible.
Reacted by Tesla Zhang, Wenzhuo Liu, LowkeyCoding and yjdyamv
bugSomething isn't workinglayoutRelated to the layout category, which is about composing, positioning, etc.mathRelated to math category, with its syntax, layout, etc.
Activity
[-]rendering: vector and square root[/-][+]Paragraph leading does not respect large inline equations[/+]pauladam94 commentedon Feb 7, 2024
What is the state of this isssue ? It's actually a major bug because it limits a lot doing package that user will use with math block a lot.
Is the value of bottom-edge and top-edge suppose to be the fix like mention in #1626 ?
Because those parameters doesn't fix at all the problem that I have mention in #3368.
laurmaedje commentedon Feb 7, 2024
#1626 fixed a different issues. Fixing this properly would require some smart heuristic in the paragraph layout. Note that you can work around this by using block equations instead of inline equations.
pauladam94 commentedon Feb 7, 2024
@laurmaedje Okk thank you ! There is a fix !
[-]Paragraph leading does not respect large inline equations[/-][+]Large inline equations can overlap with other lines[/+]Enter-tainer commentedon Mar 21, 2024
Can you elaberate more about this? I currently don't quite understand why this happens. Which code is related?
laurmaedje commentedon Mar 21, 2024
@Enter-tainer It would be easy to just always expand lines to fit the equation. But that's also undesirable because it leads to uneven line spacing in many very common cases. Hence, we would need the paragraph layout to only expand the leading if truly necessary.
Enter-tainer commentedon Mar 21, 2024
I wonder if there is any example about this. I cannot understand "It would be easy ... But that's also undesirable" well maybe because I cannot think of when it will become ugly. Is there a place I can tweak the code and see what it looks like if I want typst "always expand lines to fit the equation"?
Enter-tainer commentedon Mar 22, 2024
I wonder if LaTeX does such "smart heuristic" when layouting inline equations. It seems that it always expand line height whenever it doesn't fit.
I also wonder if it is easy to fix(or implement) "always expand lines to fit the equation". It looks like typst currently tries to expand the line but for some reason(maybe there are already some heuristics?) it fails to correctly do it.
laurmaedje commentedon Apr 1, 2024
@Enter-tainer The following example demonstrates the case I'm talking about:

If the bounding boxes would be expanded fully, Typst's paragraph layout would add leading in between them and space the lines apart a lot. This case occurs quite frequently and the results would look really bad. For this reason, Typst has the naive workaround of just always pushing the bounding box of inline math somewhat inwards. A cleaner solution would be to ensure that nothing overlaps while keeping the lines spaced normally somehow.
As you can see, LaTeX also doesn't space the lines apart:

I'm not sure how it works in LaTeX, but it would only partly apply to Typst anyway because their line spacing model is very different. It's based on baselineskip rather than leading in between line bounding boxes.
Enter-tainer commentedon Apr 2, 2024
@laurmaedje which files are relevant? Can you give me a list so I can learn how typst handles this at this moment.(And we can discuss how to improve it) I've discussed offline with @peng1999 and @Myriad-Dreamin about this.
peng1999 commentedon Apr 2, 2024
What do you think of this method: we calculate the baseline skip by adding the leading, along with the main text's ascender and descender height. We then adhere to this baseline skip unless formulas or other elements cause the bounding box to collide with the previous line's descender.
This is basically switching from the original line spacing model to the LaTeX model. Hopefully at most of the time they are compatible.
Enter-tainer commentedon May 22, 2024
Relevant code is:
typst/crates/typst/src/math/equation.rs
Lines 236 to 242 in a24052c
Enter-tainer commentedon May 22, 2024
edit: update code and image

I'm trying to replicate the LaTeX behavior in a very rough way. And it looks good
pauladam94 commentedon Oct 11, 2024
@Enter-tainer The Image you have given is an image of the output given by Typst after your fix ? Or is it the one from Latex ?
I think the next step of this issue is to compare the behavior of :
First it has to be done visually on "edge cases". Then we have to check that other tests are fine with that change.
Enter-tainer commentedon Oct 11, 2024
My pr #4236 has been abandoned for whatever reason i cannot remember.
jassler commentedon Mar 30, 2026
For what it's worth, I added these examples in a duplicate issue (sorry for not checking if the issue was already reported):
AprilGrimoire commentedon Mar 31, 2026
The same issue happens here: