KaTeX icon indicating copy to clipboard operation
KaTeX copied to clipboard

Negative spaces in Safari appear outside subscript that uses them

Open jrus opened this issue 3 years ago • 4 comments

I expected mkern and mskip commands to only affect the spacing at a single place, but they seem to cause follow-on spacing bugs afterward.

An example can be seen by navigating to the katex.org homepage and typing the following into the demo box:

Y_{A} = 5 \\
Y_{\mskip{-4mu}A} = 5 \\
Y_{\mkern{-4mu}A} = 5

Results: Screen Shot 2022-06-18 at 8 08 10 PM

Notice that the spacing after the equals sign is different between lines, even though we would only have expected to change the space between Y and A.


Workaround: put negative mkern in the main symbol not the subscript.

{Y\mskip{-7mu}}_A=5

But it’s kind of annoying if you also want a superscript. Y_A^2 = 3 ends up turning into:

{Y\mskip{-7mu}}_A^{\mskip{9mu}2} = 3

Here is my updated workaround, seems to work (but is certainly not the right way to do things, and is probably brittle).

Y_{\mkern8mu{\mathllap{A}}} = 5 \\
Y_{\mkern8mu{\mathllap{A}}}^2 = 3

jrus avatar Jun 19 '22 03:06 jrus

What browser are you using? I can't reproduce on Chrome on Windows 10, so I imagine it's browser-specific.

image

I also assume this has to do with the difficulty of negative spacing, so only applies to negative spacing. Can you confirm that positive spacing does not trigger this?

edemaine avatar Jun 20 '22 14:06 edemaine

This is in Safari (v. 15.4 running on Mac OS 10.15.7). Only happens with negative spacing. (And the behavior is the same if negative spaces are added by \!.)

Seems like this doesn’t happen in either Firefox or Chrome. Mysterious. I wonder what causes the bug here.

jrus avatar Jun 20 '22 15:06 jrus

For reference, here is Chrome 99 vs Safari 15.5, both on macOS 12.4:

Chrome 99 Safari 15.5

The style rule .katex * {background: #f001} was added for these screenshots.

mootari avatar Jun 22 '22 07:06 mootari

FWIW, this isn't new. I can reproduce on Safari versions 10, 11, 12, 13, 14, 15. But it's presumably a Safari bug, as it works fine in Chrome and Firefox.

I expect this is related to the makeVList table-row "hack" that implements vertical stacks as used in subscripts. #1409 discusses some alternatives but these are likely difficult. If any Safari or makeVList experts have any ideas, I'm all ears, but this seems like a pretty weird bug to work around...

I can't think of better workarounds than those you listed. You seem to need to pull the negative space outside any subscripts.

edemaine avatar Jun 22 '22 16:06 edemaine