MJ4: mathjax-tex font centers an over character too far left
Issue Summary
Over character commands \vec, \overrightarrow, and \dot are too far left in the mathjax-tex font, like the other MJ4 fonts.
Steps to Reproduce:
- Go to https://codepen.io/alexedgcomb/pen/YzJgKpe
Observed: Each over character is too far left
Expected: Each over character to be properly centered, like in mathjax-modern font: https://codepen.io/alexedgcomb/pen/wvYOwoN
Technical details:
- MathJax Version: 4.0.0-alpha.1
- Client OS: MacOS 13.2.1
- Browser: Firefox 113, Chrome 113, Safari 16.3
I am using the following MathJax configuration:
MathJax = {output: {font: 'mathjax-tex'}}
and loading MathJax via
<script src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-mml-svg.min.js"></script>
Supporting information:
The other MJ4.0.0-alpha.1 fonts do NOT have this issue: stix2, asana, bonum, dejavu, pagella, schola, termes, and fira.
MJ v3.2.2 does NOT have this issue.
I looked for related Github issues. These were the closest, but were not specific to mathjax-tex, so not likely related: https://github.com/mathjax/MathJax/issues/3010 https://github.com/mathjax/MathJax/issues/3032
TeX fonts contain data that gives an extra shift for accents based on the base character, called the skew value. In OpentType fonts, this skew data is stored in the MATH table of the font. Unfortunately, the original Mathjax TeX fonts were TrueType fonts rather than OpenType fonts, and they didn't include a MATH table, so the v4 tools for building the font data don't have the skew values for the original MathJax TeX font (I believe I added that data by hand to the original MathJax data files, but v4 automats the creation of the font data, and that extra data isn't available). The v3 font data was generated in a different way — by converting the v2/v1 data files into the form needed for v3, and the hand-created skew data was retained, whereas the v4 tools get all their information from the .otf font files themselves (not previous MathJax data files, as v3 did).
All the v4 fonts other than the old MathJax TeX font have MATH tables, so get the skew data from that, but the mathjax-tex font is missing that information. I will have to add a mechanism for providing skew data for the mathjax-tex font in order to resolve the issue.
@dpvc , got it! Thanks
Do you need a patch for this? I have taken the skew data from mathjax-modern, which is closely related to mathjax-tex, and put together a patch, though there is a lot of data, so it would not be a small file.
Yes, a patch would be great! Thanks, @dpvc
OK, here it is. Put the following into a file called mathjax-tex-skew.js and insert
<script src="mathjax-tex-skew.js"></script>
right after the script that sets up your MathJax configuration (via MathJax = { ... }) but before the one that loads tex-mml-svg.js, or whatever MathJax combined component you are using. That should add the skew data if the font being used is the mathjax-tex font. Let me know if that doesn't work for you.
mathjax-tex-skew.js
(function () {
if (window.MathJax === 'undefined') window.MathJax = {}
if (!MathJax.startup) MathJax.startup = {}
const ready = MathJax.startup.ready;
MathJax.startup.ready = function () {
(ready || MathJax.startup.defaultReady)();
const font = MathJax.startup.document.outputJax.font;
if (!font.options.dynamicPrefix.match(/^\[mathjax-tex\]/)) return;
for (const [variant, skew] of Object.entries(skewData)) {
const chars = font.variant[variant].chars;
for (const [i, sk] of Object.entries(skew)) {
chars[i][3].sk = sk;
}
}
};
const skewData = {
normal: {
0x2A: 0.148,
0x32: -0.01,
0x34: 0.103,
0x36: 0.068,
0x37: -0.147,
0x38: 0.011,
0x42: -0.098,
0x43: 0.146,
0x44: -0.139,
0x45: -0.025,
0x46: -0.018,
0x47: 0.115,
0x4A: 0.06,
0x4B: -0.011,
0x4C: -0.119,
0x50: -0.09,
0x52: -0.134,
0x53: 0.052,
0x58: -0.014,
0x5A: 0.011,
0x60: -0.031,
0x61: -0.036,
0x62: -0.178,
0x63: 0.027,
0x64: 0.099,
0x65: 0.014,
0x66: 0.071,
0x67: 0.082,
0x68: -0.174,
0x6B: -0.164,
0x6C: -0.034,
0x6D: -0.067,
0x6E: -0.067,
0x70: -0.076,
0x71: 0.054,
0x72: -0.015,
0x73: 0.035,
0x74: -0.034,
0x75: -0.033,
0x392: -0.068,
0x393: -0.015,
0x395: -0.022,
0x396: 0.011,
0x39A: -0.011,
0x3A1: -0.058,
0x3A3: -0.011,
0x3A7: -0.014,
0x20D7: -0.264,
0x210C: 0.062,
0x210E: -0.075,
0x2111: 0.06,
0x2119: -0.072,
0x211C: 0.016,
0x211D: -0.072,
0x2128: -0.137,
0x212D: 0.19,
0x1D401: -0.109,
0x1D402: 0.165,
0x1D403: -0.158,
0x1D404: -0.028,
0x1D405: -0.02,
0x1D406: 0.127,
0x1D409: 0.051,
0x1D40A: -0.013,
0x1D40B: -0.114,
0x1D40F: -0.1,
0x1D411: -0.15,
0x1D412: 0.054,
0x1D417: -0.017,
0x1D419: 0.013,
0x1D41A: -0.049,
0x1D41B: -0.194,
0x1D41C: 0.043,
0x1D41D: 0.124,
0x1D41E: 0.018,
0x1D41F: 0.069,
0x1D420: 0.07,
0x1D421: -0.185,
0x1D423: 0.013,
0x1D424: -0.177,
0x1D425: -0.024,
0x1D426: -0.061,
0x1D427: -0.063,
0x1D429: -0.079,
0x1D42A: 0.066,
0x1D42B: -0.021,
0x1D42C: 0.038,
0x1D42D: -0.029,
0x1D42E: -0.024,
0x1D434: 0.175,
0x1D435: 0.041,
0x1D436: 0.205,
0x1D437: 0.013,
0x1D438: 0.095,
0x1D439: 0.074,
0x1D43A: 0.203,
0x1D43B: 0.089,
0x1D43C: 0.084,
0x1D43D: 0.151,
0x1D43E: 0.09,
0x1D43F: 0.019,
0x1D440: 0.085,
0x1D441: 0.082,
0x1D442: 0.114,
0x1D443: 0.011,
0x1D444: 0.1,
0x1D445: 0.018,
0x1D446: 0.168,
0x1D447: 0.016,
0x1D448: 0.022,
0x1D449: -0.018,
0x1D44B: 0.097,
0x1D44C: -0.027,
0x1D44D: 0.114,
0x1D44E: 0.022,
0x1D44F: -0.05,
0x1D450: 0.101,
0x1D451: 0.182,
0x1D452: 0.067,
0x1D453: 0.172,
0x1D454: 0.077,
0x1D456: 0.074,
0x1D457: 0.153,
0x1D458: -0.048,
0x1D459: 0.035,
0x1D45A: -0.035,
0x1D45B: -0.035,
0x1D45C: 0.072,
0x1D45E: 0.121,
0x1D45F: 0.021,
0x1D460: 0.061,
0x1D461: 0.044,
0x1D462: 0.019,
0x1D463: 0.051,
0x1D464: 0.047,
0x1D465: 0.043,
0x1D466: 0.059,
0x1D467: 0.102,
0x1D468: 0.173,
0x1D469: 0.044,
0x1D46A: 0.221,
0x1D46C: 0.099,
0x1D46D: 0.072,
0x1D46E: 0.214,
0x1D46F: 0.091,
0x1D470: 0.086,
0x1D471: 0.153,
0x1D472: 0.095,
0x1D473: 0.018,
0x1D474: 0.086,
0x1D475: 0.083,
0x1D476: 0.11,
0x1D477: 0.012,
0x1D478: 0.093,
0x1D479: 0.014,
0x1D47A: 0.199,
0x1D47B: 0.014,
0x1D47C: 0.015,
0x1D47D: -0.018,
0x1D47F: 0.106,
0x1D480: -0.028,
0x1D481: 0.122,
0x1D482: 0.019,
0x1D483: -0.035,
0x1D484: 0.108,
0x1D485: 0.207,
0x1D486: 0.063,
0x1D487: 0.189,
0x1D488: 0.067,
0x1D489: -0.106,
0x1D48A: 0.08,
0x1D48B: 0.163,
0x1D48C: -0.074,
0x1D48D: 0.022,
0x1D48E: -0.038,
0x1D48F: -0.038,
0x1D490: 0.074,
0x1D492: 0.138,
0x1D493: 0.018,
0x1D494: 0.059,
0x1D495: 0.046,
0x1D497: 0.049,
0x1D498: 0.044,
0x1D499: 0.029,
0x1D49A: 0.05,
0x1D49B: 0.102,
0x1D504: 0.085,
0x1D505: -0.01,
0x1D508: 0.193,
0x1D509: -0.059,
0x1D50A: 0.126,
0x1D50D: -0.054,
0x1D50E: 0.115,
0x1D50F: 0.104,
0x1D510: 0.042,
0x1D511: 0.037,
0x1D512: -0.074,
0x1D513: 0.025,
0x1D514: -0.076,
0x1D517: 0.332,
0x1D518: 0.053,
0x1D519: 0.019,
0x1D51A: 0.01,
0x1D51B: 0.049,
0x1D51C: -0.011,
0x1D51E: 0.079,
0x1D51F: -0.068,
0x1D520: 0.074,
0x1D521: -0.084,
0x1D522: 0.043,
0x1D523: 0.058,
0x1D524: 0.087,
0x1D525: -0.092,
0x1D527: -0.01,
0x1D528: -0.011,
0x1D529: 0.056,
0x1D52A: -0.046,
0x1D52B: -0.037,
0x1D52C: 0.014,
0x1D52D: -0.122,
0x1D52E: 0.088,
0x1D531: 0.051,
0x1D533: -0.121,
0x1D534: -0.26,
0x1D535: 0.01,
0x1D536: -0.121,
0x1D537: -0.01,
0x1D539: -0.072,
0x1D53B: -0.1,
0x1D53C: 0.029,
0x1D53D: 0.029,
0x1D541: 0.151,
0x1D542: 0.013,
0x1D543: -0.139,
0x1D54A: -0.015,
0x1D56C: 0.082,
0x1D56E: 0.218,
0x1D56F: -0.033,
0x1D570: 0.207,
0x1D571: -0.078,
0x1D572: 0.17,
0x1D573: 0.071,
0x1D574: 0.073,
0x1D575: -0.059,
0x1D576: 0.126,
0x1D577: 0.126,
0x1D578: 0.038,
0x1D579: 0.024,
0x1D57A: -0.087,
0x1D57B: 0.013,
0x1D57C: -0.087,
0x1D57D: 0.011,
0x1D57F: 0.153,
0x1D580: 0.104,
0x1D582: 0.022,
0x1D583: 0.064,
0x1D585: -0.169,
0x1D586: 0.087,
0x1D588: 0.081,
0x1D589: -0.105,
0x1D58A: 0.048,
0x1D58B: 0.072,
0x1D58C: 0.111,
0x1D58D: -0.097,
0x1D590: -0.017,
0x1D591: 0.125,
0x1D592: -0.056,
0x1D593: -0.071,
0x1D594: 0.029,
0x1D595: -0.124,
0x1D596: 0.112,
0x1D597: 0.013,
0x1D599: 0.085,
0x1D59A: 0.011,
0x1D59B: -0.142,
0x1D59C: -0.296,
0x1D59D: 0.026,
0x1D59E: -0.127,
0x1D5A1: -0.077,
0x1D5A2: 0.091,
0x1D5A3: -0.109,
0x1D5A4: 0.018,
0x1D5A5: 0.025,
0x1D5A6: 0.073,
0x1D5A9: 0.109,
0x1D5AA: 0.02,
0x1D5AB: -0.132,
0x1D5AF: -0.06,
0x1D5B1: -0.066,
0x1D5B2: 0.015,
0x1D5B7: -0.015,
0x1D5BA: -0.013,
0x1D5BB: -0.139,
0x1D5BC: 0.042,
0x1D5BD: 0.139,
0x1D5BE: 0.016,
0x1D5BF: 0.096,
0x1D5C0: 0.074,
0x1D5C1: -0.14,
0x1D5C4: -0.124,
0x1D5C6: -0.038,
0x1D5C7: -0.038,
0x1D5C9: -0.03,
0x1D5CA: 0.041,
0x1D5CB: 0.034,
0x1D5CC: 0.022,
0x1D5CD: -0.04,
0x1D5D5: -0.07,
0x1D5D6: 0.082,
0x1D5D7: -0.096,
0x1D5D8: 0.015,
0x1D5D9: 0.022,
0x1D5DA: 0.061,
0x1D5DD: 0.097,
0x1D5DE: 0.016,
0x1D5DF: -0.126,
0x1D5E3: -0.064,
0x1D5E5: -0.056,
0x1D5EB: -0.015,
0x1D5EF: -0.152,
0x1D5F0: 0.041,
0x1D5F1: 0.152,
0x1D5F2: 0.011,
0x1D5F3: 0.087,
0x1D5F4: 0.065,
0x1D5F5: -0.153,
0x1D5F8: -0.138,
0x1D5FA: -0.028,
0x1D5FB: -0.028,
0x1D5FD: -0.043,
0x1D5FE: 0.061,
0x1D5FF: 0.03,
0x1D600: 0.015,
0x1D601: -0.047,
0x1D608: 0.147,
0x1D609: 0.047,
0x1D60A: 0.18,
0x1D60B: 0.021,
0x1D60C: 0.098,
0x1D60D: 0.095,
0x1D60E: 0.174,
0x1D60F: 0.108,
0x1D610: 0.108,
0x1D611: 0.209,
0x1D612: 0.1,
0x1D613: 0.016,
0x1D614: 0.112,
0x1D615: 0.11,
0x1D616: 0.131,
0x1D617: 0.048,
0x1D618: 0.131,
0x1D619: 0.04,
0x1D61A: 0.126,
0x1D61B: 0.062,
0x1D61C: 0.106,
0x1D61D: 0.048,
0x1D61E: 0.048,
0x1D61F: 0.065,
0x1D620: 0.04,
0x1D621: 0.084,
0x1D622: 0.084,
0x1D624: 0.096,
0x1D625: 0.237,
0x1D626: 0.09,
0x1D627: 0.133,
0x1D628: 0.116,
0x1D62A: 0.09,
0x1D62B: 0.102,
0x1D62C: -0.017,
0x1D62D: 0.099,
0x1D62E: 0.057,
0x1D62F: 0.057,
0x1D630: 0.079,
0x1D631: 0.05,
0x1D632: 0.126,
0x1D633: 0.069,
0x1D634: 0.08,
0x1D635: 0.043,
0x1D636: 0.084,
0x1D637: 0.034,
0x1D638: 0.034,
0x1D639: 0.032,
0x1D63A: 0.034,
0x1D63B: 0.052,
0x1D671: -0.073,
0x1D672: 0.1,
0x1D673: -0.098,
0x1D676: 0.072,
0x1D679: 0.085,
0x1D67B: -0.11,
0x1D67F: -0.07,
0x1D681: -0.097,
0x1D682: 0.046,
0x1D68A: -0.048,
0x1D68B: -0.172,
0x1D68C: 0.043,
0x1D68D: 0.088,
0x1D68F: 0.077,
0x1D690: 0.07,
0x1D691: -0.172,
0x1D693: 0.057,
0x1D694: -0.169,
0x1D695: -0.085,
0x1D696: -0.052,
0x1D697: -0.071,
0x1D699: -0.074,
0x1D69A: 0.044,
0x1D69B: -0.018,
0x1D69C: 0.04,
0x1D69D: -0.074,
0x1D69E: -0.043,
0x1D6A9: -0.075,
0x1D6AA: -0.019,
0x1D6AC: -0.027,
0x1D6AD: 0.013,
0x1D6B1: -0.013,
0x1D6B8: -0.063,
0x1D6BA: -0.015,
0x1D6BE: -0.017,
0x1D6E2: 0.177,
0x1D6E3: 0.077,
0x1D6E4: 0.074,
0x1D6E5: 0.17,
0x1D6E6: 0.094,
0x1D6E7: 0.11,
0x1D6E8: 0.089,
0x1D6E9: 0.117,
0x1D6EA: 0.084,
0x1D6EB: 0.09,
0x1D6EC: 0.17,
0x1D6ED: 0.085,
0x1D6EE: 0.082,
0x1D6EF: 0.097,
0x1D6F0: 0.117,
0x1D6F1: 0.089,
0x1D6F2: 0.049,
0x1D6F4: 0.104,
0x1D6F5: 0.012,
0x1D6F7: 0.082,
0x1D6F8: 0.097,
0x1D6F9: 0.025,
0x1D6FA: 0.137,
0x1D6FC: 0.072,
0x1D6FD: 0.148,
0x1D6FE: -0.019,
0x1D6FF: 0.107,
0x1D700: 0.051,
0x1D701: 0.067,
0x1D702: 0.024,
0x1D703: 0.075,
0x1D705: 0.043,
0x1D706: -0.053,
0x1D707: 0.048,
0x1D708: 0.028,
0x1D709: 0.06,
0x1D70B: 0.043,
0x1D70C: 0.096,
0x1D70D: -0.034,
0x1D710: 0.036,
0x1D711: 0.028,
0x1D712: 0.018,
0x1D713: 0.143,
0x1D714: 0.034,
0x1D715: 0.069,
0x1D716: 0.066,
0x1D717: 0.116,
0x1D718: 0.053,
0x1D719: 0.125,
0x1D71A: 0.102,
0x1D71B: 0.039,
0x1D71C: 0.174,
0x1D71D: 0.069,
0x1D71E: 0.071,
0x1D71F: 0.168,
0x1D720: 0.098,
0x1D721: 0.117,
0x1D722: 0.09,
0x1D723: 0.108,
0x1D724: 0.085,
0x1D725: 0.093,
0x1D726: 0.167,
0x1D727: 0.085,
0x1D728: 0.082,
0x1D729: 0.104,
0x1D72A: 0.111,
0x1D72B: 0.09,
0x1D72C: 0.039,
0x1D72E: 0.11,
0x1D72F: 0.01,
0x1D731: 0.08,
0x1D732: 0.106,
0x1D733: 0.029,
0x1D734: 0.135,
0x1D736: 0.059,
0x1D737: 0.153,
0x1D738: -0.02,
0x1D739: 0.115,
0x1D73A: 0.058,
0x1D73B: 0.083,
0x1D73C: 0.019,
0x1D73D: 0.062,
0x1D73F: 0.025,
0x1D740: -0.072,
0x1D741: 0.042,
0x1D742: 0.028,
0x1D743: 0.061,
0x1D745: 0.046,
0x1D746: 0.1,
0x1D747: -0.029,
0x1D74A: 0.037,
0x1D74B: 0.033,
0x1D74C: 0.011,
0x1D74D: 0.151,
0x1D74E: 0.039,
0x1D74F: 0.079,
0x1D750: 0.074,
0x1D751: 0.119,
0x1D752: 0.053,
0x1D753: 0.126,
0x1D754: 0.094,
0x1D755: 0.043,
0x1D757: -0.04,
0x1D758: 0.022,
0x1D75A: 0.015,
0x1D75F: 0.012,
0x1D766: -0.034,
0x1D76C: -0.015,
0x1D7D0: -0.011,
0x1D7D2: 0.127,
0x1D7D4: 0.048,
0x1D7D5: -0.164,
0x1D7D6: 0.011,
0x1D7E3: 0.01,
0x1D7E6: 0.073,
0x1D7E8: 0.084,
0x1D7EE: -0.016,
0x1D7F0: 0.068,
0x1D7F2: 0.056,
0x1D7F5: -0.016,
0x1D7F7: 0.015,
0x1D7F8: -0.011,
0x1D7F9: -0.015,
0x1D7FA: 0.06,
0x1D7FC: 0.054,
0x1D7FD: -0.184
},
bold: {
0x20D7: -0.264
},
italic: {
0x237: 0.083
},
'bold-italic': {
0x131: -0.012,
0x237: 0.063
},
fraktur: {
0x2A: 0.148,
0x32: -0.01,
0x34: 0.103,
0x36: 0.068,
0x37: -0.147,
0x38: 0.011
},
'sans-serif': {
0x237: 0.013
},
'bold-sans-serif': {
0x237: 0.015
},
'sans-serif-italic': {
0x131: 0.083,
0x237: 0.097
},
'-tex-calligraphic': {
0x41: 0.274,
0x42: 0.09,
0x43: 0.135,
0x44: 0.06,
0x45: 0.143,
0x46: 0.266,
0x47: 0.164,
0x48: 0.163,
0x49: 0.159,
0x4A: 0.219,
0x4B: 0.173,
0x4C: 0.249,
0x4D: 0.128,
0x4E: 0.121,
0x4F: 0.166,
0x50: 0.099,
0x51: 0.124,
0x52: 0.123,
0x53: 0.139,
0x54: 0.112,
0x55: 0.06,
0x56: 0.042,
0x57: 0.035,
0x58: 0.121,
0x59: 0.083,
0x5A: 0.033
},
'-tex-bold-calligraphic': {
0x41: 0.283,
0x42: 0.101,
0x43: 0.15,
0x44: 0.045,
0x45: 0.151,
0x46: 0.151,
0x47: 0.177,
0x48: 0.178,
0x49: 0.199,
0x4A: 0.26,
0x4B: 0.196,
0x4C: 0.259,
0x4D: 0.115,
0x4E: 0.139,
0x4F: 0.183,
0x50: 0.126,
0x51: 0.138,
0x52: 0.133,
0x53: 0.141,
0x54: 0.144,
0x55: 0.07,
0x56: 0.035,
0x57: 0.057,
0x58: 0.125,
0x59: 0.079,
0x5A: 0.133,
0x131: -0.012,
0x237: 0.063
},
'-tex-oldstyle': {
0x42: -0.098,
0x43: 0.146,
0x44: -0.139,
0x45: -0.025,
0x46: -0.018,
0x47: 0.115,
0x4A: 0.06,
0x4B: -0.011,
0x4C: -0.119,
0x50: -0.09,
0x52: -0.134,
0x53: 0.052,
0x58: -0.014,
0x5A: 0.011
},
'-tex-variant': {
0x3F0: -0.015
}
};
})();
Works like a charm! Thanks, @dpvc
Glad to hear it. It will be in the next v4 release.
@dpvc , turns out that k doesn't quite get the over character centered:
https://codepen.io/alexedgcomb/pen/poQobPO?editors=1000
I made a brute force visual test for all uppercase and lowercase letters: https://codepen.io/alexedgcomb/pen/MWzWeEZ?editors=1010
- A bit too far left:
b,h,k,D - A bit too far right:
C
@dpvc , another one: \ddddot and \dddot are too high and left:
https://codepen.io/alexedgcomb/pen/QWJwora
\ddot and \dot look good. Issue not present in mathjax-modern.
Perhaps the too high issue is related to https://github.com/mathjax/MathJax/issues/3011 ?
The skew values that are given above are based on the values from the OpenType MATH table of the Latin-Modern font that is the basis of the mathjax-modern font. These values are horizontal offsets meant to center an accent over the visual center of the top of the base character. For example, an italic capital "A" has its peak somewhat to the right of the center of the width of the character, so for accents to be above that peak, they have to be shifted right a bit. That is why 0x1D434 has a skew value of 0.175 ems, so that \dot A produces
|
| rather than |
|
Now for characters like b, d, h, and k that have ascenders, accents generally are placed above the ascender itself, not centered over the width of the character as a whole. For example:
|
| not |
|
This applies to all accents:
In particular, it also applies to the vector accent, which is centered on the ascender of the k, not on the width of the k:
The Latin-Modern font's Opentype MATH table includes skew values for not just the italic characters, but upright characters as well, so that \dot {\rm d} and \dot {\rm k} will still have the accents placed above the ascenders rather than centered on the character as a whole:
But that does mean that the vector arrow is also centered on the ascenders:
This is OK for the "d" but less good for the "k". It looks like the Computer Modern fonts in TeX itself don't have skew values for the upright characters, as the TeX output for these are:
If you look carefully, you will see that the vector arrow is not actually centered on the width of the base character. This can be more easily seen on a character like "x":
It can also be seen by overlapping the dot and vector notations using \rlap{$\dot k$}\vec k in TeX
where you can see that the vector arrow is not centered on the dot. This is one of the places in TeX where the font metrics are used to handle layout tasks: the advance-width of the vector arrow is shorter than the width of the arrow itself (i.e., the arrow extends to the right of its character box) so that when the width of the arrow is centered, the glyph is slightly to the right of its visual center.
MathJax uses the actual bounding box of the ink of the accent in order to center it, and so that sneaky use of the font metrics that TeX uses to adjust the vector arrow's position isn't available in MathJax, and the vector is always centered on the skewed accent location. That is why \vec k and \widehat {\rm k} seem to be too far to the left compared to TeX. But these are centered on the ascender of the "k", just as every other accent is.
This approach makes for better centering for normal characters, like "x", where \vec x\qquad \vec {\rm x} produces
which is a better result than TeX's offset version of the vector shown above. Both TeX and MathJax have made trade-offs about how the vector arrow is to be placed. TeX shifts its slightly to the right, which improves the results for b, h, and k, but makes things worse for most other characters. MathJax, on the other hand, favors the majority of characters, making things a bit worse for the few characters with left-hand ascenders. In both cases, it is really the font data that controls this, and it would be possible to adjust the font data to bring things more in line with TeX. For example:
MathJax.startup.document.outputJax.font.variant.normal.chars[0x20D7][3].dx = .06
would shift the vector arrows to the right a bit.
Note also that TeX has a \skew macro that can be used to adjust the position of an accent, e.g., \vec k\quad \skew{1}\vec k would produce
The \skew macro replaces the font's skew data for the base, so \skew{0}\widehat {\bf k} would center over the width of the k:
Because the font's skew value is only used when the base is is a single character, you could get a similar result by using \widehat {\bf k{}}, where the base is no longer just a single character. A similar technique could be used in MathML:
<math display="block">
<mover>
<mrow>
<mi mathvariant="bold">k</mi>
<mi/>
</mrow>
<mo>^</mo>
</mover>
</math>
Because of the way the \skew macro is written, it can only accept positive skew values (this is true in TeX as well), but you could make a macro, say \nskew that does negative skews, if needed.
I am not planning to adjust MathJax's centering of accents, but some of the skew values may not be optimal, especially for some of the capital letters. There may be some issues with interactions with the italic correction in the computations of the skew values from the MATH table, for example, as the italic corrections are being estimated from other font metrics right now. I will look into that, and may be able to produce better skew values for the next v4 release.
The Opentype MATH table specification indicates that the skew value of the accent should also be used when it is being placed (the two skewed positions are to be aligned), and that isn't the case right now in MathJax (only the base skew is used), so that would be another route to allowing an accent to be shifted compared to other accents. I will make a PR for the changes needed for that (they are small), and will fix the font data to make that work properly.
For now, you can, of course, adjust (or delete) the skew values in the code I gave you above to better suit your preferences.
\ddddot and \dddot are too high and left:
This is because the characters needed of these are not in the mathjax-tex fonts, so MathJax has no metric information about those characters. It makes generic requests for the U+20DB and U+20DC, and the browser may find the glyphs in other fonts on your system, but MathJax doesn't know anything about their bounding boxes, so can't palace them very well. Version 2 used three or four periods to handle these accents (which is sub-optimal). If you want to do that, you can use
MathJax.startup.document.outputJax.font.variant.normal.chars[0x20DB] = [.12, 0, 3*.278, {c: '...'}];
MathJax.startup.document.outputJax.font.variant.normal.chars[0x20DC] = [.12, 0, 4*.278, {c: '....'}];
to define them again. There are a few other faked characters like that. I will look to see what might want to be added into the v4 fonts that worked that way.
@dpvc , thank you for explaining!
Slight correction to the four dots above unicode (20DB -> 20DC):
MathJax.startup.document.outputJax.font.variant.normal.chars[0x20DB] = [.12, 0, 3*.278, {c: '...'}];
MathJax.startup.document.outputJax.font.variant.normal.chars[0x20DC] = [.12, 0, 4*.278, {c: '....'}];
Thanks, I've updated my post above, to avoid future confusion.
@dpvc , I'm upgrading from alpha.1 to beta.4
The over character was completely resolved in alpha.1 via this above comment.
Beta.4 seems to have regressed a little in the case of Z. Steps:
- Go to https://codepen.io/alexedgcomb/pen/PoLVGQo?editors=1000
Observed: Arrow over Z is too far right
Expected: Arrow over Z to be centered, like alpha.1 with the aforementioned patch
https://codepen.io/pen/
Adding the skew patch resolves the beta.4 issues.
I figured you'd want to know of the slight regression :)
OK, it turns out that the skew value for the vector arrow (U+20D7) is no longer needed (the character was adjusted to remove a hack that was in the original MathJax TeX fonts and that made the skew value necessary). I will remove it in the next release. For now, you can use
MathJax = {
output: {
font: 'mathjax-tex'
},
startup: {
ready() {
MathJax.startup.defaultReady();
const variant = MathJax.startup.document.outputJax.font.variant;
delete variant.normal.chars[0x20D7][3].sk;
delete variant.bold.chars[0x20D7][3].sk;
}
}
};
to resolve the issue.
Many thanks!