New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support highlight, overline, underline, and strike for math equations #3953
base: main
Are you sure you want to change the base?
Conversation
crates/typst/src/math/equation.rs
Outdated
} | ||
last_frame_index = Some(index); | ||
} | ||
if let Some(index) = first_frame_index { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand what's going on here. Why are we only background-decorating the first and foreground-decorating the last MathParItem::Frame
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, wait, are you creating an overlarge decoration for all the items, but applying it to the first one? That seems problematic when the equation breaks over multiple lines. We should probably rather create individual decorations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Now each frame is decorated on its own.
Special case will be any empty space between two frames, in that case we need to fill the void and decorate the space as well. For such space in between frames, we use the last frame and append the decorations to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, interesting. I tried the following new test case, where the equation breaks over multiple lines:
--- highlight-inline-math-multiline ---
#line(length: 100%)
#h(1fr)
#highlight[$a + b + c + d + e + f + g$]
I think the trailing space after the "+" shouldn't be there. However, this is not a problem with your PR, but rather the math equation line breaking. However, if that bug was fixed, the solution of decorating the space together with the previous frame wouldn't work anymore, as the highlighting would continue into the margin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not figured out a good way of doing highlight for the trailing space. It seems that in order to do that we need to do decoration after the linebreak, which would require us to do the decoration in commit
(just like the normal text case).
In order to do this, we need to associate the style to the frame (just like how a style is asscoited with Item::Text(shaped)
. It seems a little bit tricky and honestly I am not so sure this might be a good way.
Or another possibility is to just do not care about the space, which would create some void between two or more MathParItems).
BTW, what is this bug with math equation line breaking and how is it going to be solved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is that there is a space at the end of the first line in the picture above. I think the spacing should be "weak" and collapse at the end of the line, just like normal text spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is that there is a space at the end of the first line in the picture above. I think the spacing should be "weak" and collapse at the end of the line, just like normal text spaces.
Sorry for the late update. While I have not figured out a good solution, I added a predecessor PR that eats white space introduced by the math equation in #4087 I think I will find a new way for the decoration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really quite tricky. Ideally, we'd also not couple math and paragraph layout too tightly.
Maybe we should apply the highlighting completely in paragraph layout rather than math, on a per-line base (i.e. highlight consecutive stuff together with a larger bounding box, no matter whether it is text, math, h or whatever)? This could also fix #1716.
Regarding #2200, it turns out the highlight is supported for normal text but not for math equations. This PR implement the highlight for math equations.
Like highlight, other line-based decorations are supported now as well, including overline, underline, strikethrough. Result
(tests added in
deco.typ
)Old
This is the second of two PR for solving #2200 (and shoud be easier to review if #3941 is merged first) (or Just merge this PR directly)
It continues on #3941 that add support for overline underline and strike for math equations. Some refactoring and corresponding tests are added as well.