Skip to content

Commit 1334ab6

Browse files
committed
Restore math-italic ASCII fold for MathJax combining accents
_mathItalicCpToChar was simplified during rebase to a one-line String.fromCodePoint(cp), on the theory that pt6's cmap aliases would re-route U+1D400-block math-italic letters to the plain-letter glyphs where the GPOS mark anchors live. In practice the aliased path did not trigger the mark feature for combining diacritics, so \hat{x}, \bar{H} etc. rendered with accents in the wrong place. Restore the explicit U+1D434/U+1D44E/U+1D456 + U+210E + ASCII fold from a3225f7 ("Fix the diacritics in the mathjax rendering") so the injected text node carries plain ASCII letters that shape through the font's mark anchors directly. Also tighten the wide-mover overline position: anchor the hand-drawn bar to baseRect.top with a small gap rather than overRect.top, which includes the extra vertical padding MathJax allocates above the stretched en-dash strip and pushed the bar visibly high above \overline{a+b+c}.
1 parent 4b3b588 commit 1334ab6

9 files changed

Lines changed: 19 additions & 11 deletions

File tree

xkcd-script/samples/ligatures.png

-7.43 KB
Binary file not shown.
1.25 KB
Loading
6 Bytes
Loading
-3.33 KB
Binary file not shown.
-2.79 KB
Binary file not shown.
-3.09 KB
Binary file not shown.
-22 Bytes
Loading
-1.56 KB
Binary file not shown.

xkcd-script/xkcd-mathjax3.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,16 +1915,22 @@
19151915
'2035': '̀', // \grave — reversed prime → combining grave
19161916
};
19171917

1918-
// Math italic / bold / Greek codepoints (U+1D400 block, U+210E, etc.)
1919-
// are aliased to their plain Latin / Greek glyph in the font's cmap
1920-
// via pt6's _math_aliases. So injecting the codepoint directly into
1921-
// a text node is enough — the browser shapes it through the font's
1922-
// cmap alias and gets the correct glyph. Returns null for inputs
1923-
// that don't parse so the caller can skip cases the font won't
1924-
// cover (e.g. fancy decorative codepoints we never aliased).
1918+
// Map a hex glyph-class codepoint to a plain text character we can feed
1919+
// into a Unicode text node. Math-italic letters (U+1D400 block) and
1920+
// the U+210E (italic h) outlier are folded back to ASCII A-Z / a-z so
1921+
// the browser shapes them via the font's plain-letter glyphs — the
1922+
// mark-anchor rules for combining diacritics attach to those, not to
1923+
// the math-italic codepoints, so going through pt6's cmap alias path
1924+
// produced mis-placed accents in practice.
19251925
function _mathItalicCpToChar(hex) {
19261926
const cp = parseInt(hex, 16);
1927-
return Number.isFinite(cp) ? String.fromCodePoint(cp) : null;
1927+
if (!Number.isFinite(cp)) return null;
1928+
if (cp >= 0x1D434 && cp <= 0x1D44D) return String.fromCharCode(0x41 + (cp - 0x1D434)); // A-Z italic
1929+
if (cp >= 0x1D44E && cp <= 0x1D454) return String.fromCharCode(0x61 + (cp - 0x1D44E)); // a-g italic
1930+
if (cp >= 0x1D456 && cp <= 0x1D467) return String.fromCharCode(0x61 + (cp - 0x1D44E)); // i-z italic (hole at U+1D455; h lives at U+210E)
1931+
if (cp === 0x210E) return 'h';
1932+
if (cp >= 0x20 && cp < 0x7F) return String.fromCharCode(cp);
1933+
return null;
19281934
}
19291935

19301936
function _glyphClassCp(el) {
@@ -2029,9 +2035,11 @@
20292035
// letters it's covering, not the fallback over glyph.
20302036
const left = baseRect.left - containerRect.left;
20312037
const width = Math.max(baseRect.width, fontSizePx * 0.4);
2032-
// Vertical: just above the base's top; nudge so the bar/tip sits
2033-
// where the font's natural overline would.
2034-
const top = overRect.top - containerRect.top - barH * 0.5;
2038+
// Vertical: anchor to the base's top with a small gap so the bar
2039+
// sits where the font's natural overline / macron would.
2040+
// overRect.top is unreliable here — MathJax allocates extra
2041+
// vertical space above the en-dash ink in the over's bbox.
2042+
const top = baseRect.top - containerRect.top - barH - fontSizePx * 0.05;
20352043

20362044
_hideOver(over);
20372045
mover.dataset.xkcdWide = '1';

0 commit comments

Comments
 (0)