math rendering problem with \bar, \vec and possibly others
Describe the bug When using math equations with \bar or \vec with subscripts, the equations are not rendered correctly in some situations.
To Reproduce Type at least two variables with \bar or \vec and subscripts that have letters embraced by { }, and the rendering will fail. In order to render correctly, only the first one could use subscript with { }. If a space is used in front of the first subscript with { } it seems to render correctly.
Expected behavior I expect all the formulas to be rendered correctly.
Screenshots An array of examples of what works and what doesn't is shown in the following picture:
Device
- OS: Windows 11
- Version 25H2
- App Version 2.6.10
Retested a display formula containing \bar{x}, \vec{v}, and \mathbf{F} against the current v2.6.14 source build on macOS. It renders correctly in split preview. Please retest with a current build and attach the original formula if a specific expression remains broken.
Thanks for the minimal test file. I reproduced the second and third equations on v2.6.14, traced it to Comrak turning paired underscores inside $$…$$ into Markdown emphasis, and opened #326. An isolated macOS release bundle passes all five formulas from the attachment.
Partly fixed, and your two observations pinpointed the cause exactly.
#351 protects underscores inside $$…$$ display math. Inline $…$ is not protected, and that's where your examples live — verified by running comrak directly:
input: $\bar{b}_{1} + \bar{b}_{2}$
output: $\bar{b}<em>{1} + \bar{b}</em>{2}$
comrak pairs the two _ into emphasis before KaTeX ever sees the source. That is why only the first subscript worked (a single _ can't pair with anything) and why adding a space before it fixed it (a space makes the _ non-left-flanking, so it can't open emphasis).
This turns out to be the same root cause as #197 (\\ eaten, collapsing multi-line aligned into one line) and #177 (\% eaten, so KaTeX treats the rest as a comment). The current guard covers only _ and only $$ — the intersection of the three. Masking the whole delimited span before comrak and restoring afterwards fixes all three; I'm working on that.