MJ4 mathjax-tex: Overhead lines touch but didn't in MJ2
Issue Summary
Overhead lines touch for mathjax-tex in MJ4 but not in MJ2
Steps to Reproduce:
- Go to https://codepen.io/alexedgcomb/pen/QWzOprZ
Observed: Overhead lines touch
Expected: Overhead lines to not touch, like in MJ2:
https://codepen.io/alexedgcomb/pen/bGOYWwZ
Technical details:
- MathJax Version: 4.0.0-alpha.1
- Client OS: Mac OS 13.4
- Browser: Firefox 117 and Chrome 117
I am using the following MathJax configuration:
// Using CDN direct link b/c String 'mathjax-tex' yields the wrong URL, so falls back to mathjax-modern
MathJax = {output:{font:'https://cdn.jsdelivr.net/npm/[email protected]/es5/output/fonts/mathjax-tex'}};
and loading MathJax via
<script src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-svg.min.js"></script>
Supporting information:
Overhead lines in 4.0.0-beta.3 touch:
https://codepen.io/alexedgcomb/pen/yLGPbyB
Overhead lines in mathjax-modern do NOT touch:
https://codepen.io/alexedgcomb/pen/RwEjVwQ
Here is the situation: when an accent is to be stretched over a base, there may be several versions of the accent at different sizes that MathJax looks through to find one that covers the base, and if none of the fixed-size ones do the job, a multi-character assembly may be used. The sizes available and how large they are depend on the font in use. MathJax tries to follow the TeX algorithm for this, though it has to be modified to handle situations that don't arise in TeX. The v4 algorithm was modified from that used in v3 and v2 to be a closer match to the TeX algorithm, while taking account of some of the differences in various fonts that are now available.
One thing to note is that the width of single-character accents sometimes include space at either end (called the left- and right-hand bearings), while that may not be the case for the multi-character assembly. This is the case for the characters used for the macron (U+00AF) that you are using in the mathjax-modern and mathjax-tex fonts. If the single-character version is used (as occurs in mathjax-modern), its width includes a small amount of extra space on each side, so the macro may not fully cover the base character even though the width of the character in the font says it does. But when the multi-character version is used (as is the case for mathjax-tex), it does cover the full width of the base. In your example, the two characters have no space between them, so when multi-character accents are needed over both bases (in mathjax-tex), they will touch. That is what you are seeing here, and will happen in nearly all the new mathjax fonts as well. That didn't happen in v2 due to the differences in the algorithm for choosing the correct size to use.
Note that in TeX, the construction \overline{1}\overline{2} also produces overlines that touch:
so MathJax is modeling this same behavior.
Note that the macron is stretchy by default, so acts like \overline in TeX rather than \bar, which doesn't stretch. If you use
<math>
<mover accent="true">
<mn>1</mn>
<mo stretchy="false">¯</mo>
</mover>
<mover accent="true">
<mn>2</mn>
<mo stretchy="false">¯</mo>
</mover>
</math>
you will get
which may be more like what you are looking for. This is what \bar 1 \bar 2 would produce.
So this is the expected current behavior for MathJax v4. While investigating your report, I did locate one issue, which is that the largest single-character version of the accent is never actually used (it goes to the multi-character version in that case), so I will be making a correction for that, but it will not change the output in this case, as the larger macron doesn't have any left- or right-bearing while the smaller size does, so the multi-character version is essentially the same as the larger variant in any case (in mathjax-tex and mathjax-modern).
@dpvc , thank you for the explanation! I understand :)