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 }}
Text decoration functions not working with inline equations #2200
Reacted by m4dh0rs3, SimonIT, Arthur Adjedj, Dominik Schwaiger, Andy Li, Iago-lito, Giacomo Bertelli, Nicolai Weitkemper, Abdulaziz Alqasem, JL710 and 8 more
It seems that for now only TextElem would apply the line decorations (highlight, strikethrough, etc). It shoud not be difficult to support math, I will work on it.
The only problem I have is that the metrics provided as arguments to the line decoration, such as baseline, ascender, may only make sense to a TextElem, but does not really make sense for a math expression. For example, if we have a fraction surrounded by some normal text,
#highlight[We have $inline(1/2 < (x+1)/2)$ here]
how should we decide the height of the highlight rectangle for the inline math? As you can see, the math expr can easily go beyond the height of normal text, and the normal font metrics like descender/ascender does not make sense anymore. Should we simply place a highlight rectangle that covers the entirety of the math expression? Maybe we need to first define what those decorations would work on the math expr.
Not sure if this quick and dirty workaround could help any Typst users out there:
If you find short character sequences in math equations not getting highlighted while longer ones do, for example:
If $ a + b = #highlight[c] $ does not result in the c symbol being highlighted, and lengthening the argument of the highlight command by adding more characters: $ a + b = #highlight[ccc] $ successfully highlights ccc.
Then you may like to consider adding non-space characters without glyphs to artificially lengthen the sequence passed to the highlight command. I tried adding U+034F "COMBINING GRAPHEME JOINER" characters to lengthen the sequence, and it works. 👍🏻
Adding U+034F to the Typst code view does not result in visible differences since this character has no glyph and is thus not rendered -- the code would still read like $ a + b = #highlight[c] $ after U+034F characters are appended to c, and the rendered equation will possess the desired highlight spanning the symbol c.
Using characters that are widely treated as a space doesn't appear to work.
There exists several non-space characters without glyphs, and I'm not sure which one is the "best" character to use in this circumstance if one or more of these are indeed better than the rest. https://invisible-characters.com/ contains a list of invisible characters, some of which are treated as spaces (which aren't suitable for this workaround) and others that are non-space characters (suitable for this workaround).
As @LuxxxLucy pointed out, we first need to define how highlight should behave in the first place. I think the most reasonable thing would be to highlight the whole equation bounding box. If we agree on that, the fix should be relatively simple by checking for the presence of the highlighting style when doing the inline equation layout.
Had some initial try. I find that we can do this in layout_inline for the equation, we check the decorations styles and then do line-decoration (such as highlight), Result would be something like this
However, I found that there are some tricky case we have multiple MathParItem (with potential space) in the equation, it seems that it would need some extra effort to check the x and y coordinates. After I figure it out I will submit a PR (or perhaps two PRs, one for fixing the highlight for equations, and then a second PR that does some refactoring and add support for the other line-decorations)
changed the title [-]highlight function not working with equations[/-][+]Text decoration functions not working with inline equations[/+]on Jul 16, 2024
A problem I found with this was that box doesn't break. Thanks to catte_ from the Discord, I got the following workaround using show rules to highlight an equation inside a highlight with the highlight color:
#showhighlight: it=> {
showmath.equation: box.with(fill: it.fill)
it
}
Activity
8LWXpg commentedon Sep 23, 2023
similar issue also happens to
strikeandtext(baseline: length)LuxxxLucy commentedon Sep 30, 2023
It seems that for now only TextElem would apply the line decorations (highlight, strikethrough, etc). It shoud not be difficult to support math, I will work on it.
The only problem I have is that the metrics provided as arguments to the line decoration, such as baseline, ascender, may only make sense to a TextElem, but does not really make sense for a math expression. For example, if we have a fraction surrounded by some normal text,
#highlight[We have $inline(1/2 < (x+1)/2)$ here]how should we decide the height of the highlight rectangle for the inline math? As you can see, the math expr can easily go beyond the height of normal text, and the normal font metrics like descender/ascender does not make sense anymore. Should we simply place a highlight rectangle that covers the entirety of the math expression? Maybe we need to first define what those decorations would work on the math expr.
davidleejy commentedon Nov 20, 2023
Not sure if this quick and dirty workaround could help any Typst users out there:
If you find short character sequences in math equations not getting highlighted while longer ones do, for example:
If
$ a + b = #highlight[c] $does not result in thecsymbol being highlighted, and lengthening the argument of the highlight command by adding more characters:$ a + b = #highlight[ccc] $successfully highlightsccc.Then you may like to consider adding non-space characters without glyphs to artificially lengthen the sequence passed to the highlight command. I tried adding U+034F "COMBINING GRAPHEME JOINER" characters to lengthen the sequence, and it works. 👍🏻
Adding U+034F to the Typst code view does not result in visible differences since this character has no glyph and is thus not rendered -- the code would still read like
$ a + b = #highlight[c] $after U+034F characters are appended toc, and the rendered equation will possess the desired highlight spanning the symbolc.Using characters that are widely treated as a space doesn't appear to work.
There exists several non-space characters without glyphs, and I'm not sure which one is the "best" character to use in this circumstance if one or more of these are indeed better than the rest. https://invisible-characters.com/ contains a list of invisible characters, some of which are treated as spaces (which aren't suitable for this workaround) and others that are non-space characters (suitable for this workaround).
SolidTux commentedon Apr 5, 2024
Is there some update on this? Or some place I could try to help with?
laurmaedje commentedon Apr 6, 2024
As @LuxxxLucy pointed out, we first need to define how highlight should behave in the first place. I think the most reasonable thing would be to highlight the whole equation bounding box. If we agree on that, the fix should be relatively simple by checking for the presence of the highlighting style when doing the inline equation layout.
LuxxxLucy commentedon Apr 12, 2024
Sorry for not being active. Will work a solution and update soon. I think I am going with the bounding box approach.
LuxxxLucy commentedon Apr 14, 2024
Had some initial try. I find that we can do this in

layout_inlinefor the equation, we check the decorations styles and then do line-decoration (such as highlight), Result would be something like thisHowever, I found that there are some tricky case we have multiple MathParItem (with potential space) in the equation, it seems that it would need some extra effort to check the x and y coordinates. After I figure it out I will submit a PR (or perhaps two PRs, one for fixing the highlight for equations, and then a second PR that does some refactoring and add support for the other line-decorations)
[-]highlight function not working with equations[/-][+]Text decoration functions not working with inline equations[/+]DzmingLi commentedon Jul 27, 2024
hope that highlight etc.... function is available in math mode
Enivex commentedon Jul 27, 2024
It will eventually, but there are some things blocking it
conema commentedon Feb 19, 2025
A quick workaround working with simple inline math:
FnControlOption commentedon May 20, 2025
Here are workarounds for underline and strikethrough with inline math:
Underline:
Strikethrough:
tedzards509 commentedon Aug 21, 2025
A problem I found with this was that
boxdoesn't break. Thanks to catte_ from the Discord, I got the following workaround using show rules to highlight an equation inside a highlight with the highlight color:mariansam commentedon Feb 26, 2026
I merged these two approaches to make the underline work: