Skip to content

MJ 2.7.9 with new CM-MJ that supports MJ >2.4 - #222

Merged
cben merged 4 commits into
gh-pagesfrom
batched-rendering-MJ-2.7
Oct 20, 2026
Merged

cben merged 4 commits into
gh-pagesfrom
batched-rendering-MJ-2.7

Conversation

@cben

@cben cben commented Oct 12, 2026

Copy link
Copy Markdown
Owner

[resurrecting #169]

MathJax 2.5+ was blocked on 2 things: (cben/CodeMirror-MathJax#33)

  • many Typeset calls are way slower than 2.4,
    mostly solved by newer CM-MJ batching them

  • typesetting out of DOM no longer works,
    fixed by CM-MJ now typesetting in invisible div,

But the new CM-MJ made math tiny in mathdown :-(
=> Turns out "lining_numerals_charter" font was confusing MJ, found a workaround, now I can finally update :-)

@cben

cben commented Oct 13, 2026

Copy link
Copy Markdown
Owner Author

Not certain this is ready? In 2 min testing found bug cben/CodeMirror-MathJax#46 😳. Hard to say if it's a regression, cause I'd seen it before, happens on older CM-MJ too!

I tried this now because I saw it's been "ready" years ago and seemed the blocker was actually solved and it's a shame to hold it back. But the truth is that I don't use Mathdown regularly enough nowdays and deploying a big implementation change like this would reduce confidence. For performance, that's unwise. At present, I better only merge stuff that's definite bug fixes / features.

(Now, if I do fix the bug on CM-MJ head, then it'll be worth bumping.)

@cben

cben commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner Author

What do you know, Chromium still suffers from | lines after each formula.
That's like a decade (umm 11 years!) of Mathdown looking ugly. 😳 😳

  • This does fix it! Should I just go ahead and deploy this?

  • Or could try to workaround by another output? 2.4 had less options.

    • 2.4 MathML warns me "not all features supported" (by both browsers) and indeed some looks worse, but worse disappears on reload ❌. Perhaps measurement for CM insertion gets messed up?
    • 2.4 SVG was rumored fine, indeed has no such line, but renders smaller and does not (large can not) pick up size & color in headers/quotes.

cben and others added 2 commits October 13, 2026 15:46
Finally solves MathJax 2.4 showing a vertical line after
each formula (in Chrome?).

MathJax 25+ was blocked on 2 things:
(cben/CodeMirror-MathJax#33)

- many Typeset calls are way slower than 2.4,
  *mostly* solved by newer CM-MJ batching them

- typesetting out of DOM no longer works,
  fixed by CM-MJ now typesetting in invisible div,

But the new CM-MJ made math tiny in mathdown :-(
=> Turns out "lining_numerals_charter" font was confusing
MJ, found a workaround, now I can finally update :-)
@cben
cben force-pushed the batched-rendering-MJ-2.7 branch from a5578b5 to a40d836 Compare October 13, 2026 13:32
@cben

cben commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner Author

Some anecdotal testing on ?doc=demo (and ?viewurl=demo):

  • It's still somewhat slower! (firefox, ?doc, testing both with local server to rule out Netlify hosting & collab toolbar differences).
    Note "much slower but mostly solved by batching" was the deal here all along!
    (Dunno if MJ 3.x and 4.x are faster but would need significant CM-MJ updates)

    before, HTML-CSS: Initial render around 2–2.2sec
    after, HTML-CSS "Fast Preview" on: 3–3.2sec. 🙁
    after, HTML-CSS "Fast Preview" OFF 💡: 2.4–2.8sec. 😐
    after, Common-HTML "Fast Preview" off: 2–2.5sec 🙂
    after, MathML "Fast Preview" off: 1.4–1.7sec 🚀

    • UPDATE: with 2.7.9, MathML no longer invisible, looks different here & there (logo is atrocious) but mostly usable, and very fast! However, spacing after math is buggy in both directions e.g. Foo $\binom{n}{k}$ bar. Foo $\int\limits_{-\infty}^{\infty}x$Bar. ❌

    MJ 2.5 introduced Common-HTML as "rough but 10x-faster"(!), and Fast Preview renders it before the main renderer completes. Counter-intuitively, it's only detrimental for us, cause math remains invisible off-screen — we shouldn't give CodeMirror a widget until its dimensions are stable!
    MJ 2.6 made it less fast but competitive:

    The CommonHTML output now provides the same layout quality and MathML support as the HTML-CSS and SVG output. It is on average 40% faster than the other outputs and the markup it produces are identical on all browsers and thus can also be pre-generated on the server via MathJax-node. The fast preview mechanism introduced in v2.5 continues to develop as a separate output as PreviewHTML and the fast-preview extension.

    MJ 2.7 had more fixes for Common-HTML, no perf numbers given. (but fast preview now split to use "PreviewHTML" renderer)
    With MJ 2.7, Common-HTML looks very slightly different, mostly just a bit smaller.

    => I'll keep HTML-CSS default, users can still right-click and switch renderers (and this PR makes that useful for first time), but gonna turn off "Fast preview" by default.

  • Before: pretty reproducible 2.001s Fallaback flushMarkTextQueue: 15 elements console warnings, now gone. The setInterval is still there, so might indicate more robust logic improvement(??)

  • Traversing formulas unrenders some, and some don't render back CodeMirror-MathJax#46 reproduces reliably on both when moving cursor directly from within one formula into another.
    For other cases (drag-selection, rapid arrow movement through distinct formulas), it may depend on timing? New version may anecdotally hit it more simply cause render is slower(?)

@cben

cben commented Oct 20, 2026

Copy link
Copy Markdown
Owner Author

BTW over a real network, things are slower yet due to JS, font etc. fetching.

  • I made all above measurements with current MathJax.js?config=TeX-AMS_HTML-full,Safe combined config which is unfair to other renderers!
    Using HTML-CSS, that makes 44 requests, total 1.74MB.
    Whereas right-click-configured to use Common-HTML, that makes 51 requests, total 1.91MB (cache disabled).

  • With TeX-AMS_CHTML-full,Safe, Common-HTML, "Fast preview" off I'm seeing 2.0–2.6sec which is pretty similar (local server is fast), but it does load 44 assets total 1.71MB! So mismatching config vs. cookies wastes ~11%.

    • So it's suboptimal over network, but local timings were precise enough.
  • Is MJ 2.7.9 bigger on the wire? Barely, mathdown.net running 2.4.0, HTML-CSS, made 44 requests, 1.68MB <4%.

@cben

cben commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner Author

=> after fix bildo a bit tighter horizontal spacing than before, I actually like it 🚀

cben added 2 commits October 20, 2026 17:39
MJ 2.4 was wrongly using displaystyle scaled parens for `\choose` and `\binom`.
(also, `\choose` had different horizontal spacing).

MJ 2.7 matches real TeX, default parens are shorter than text :-(
`\dbinom` helps but has too much vertical gap between the 2 lines;
so do array/matrix solutions.
=> `\small` makes text shorter so it fits the parens nicely, but is smaller than before.
Applied HTML 120% scale so that logo remains bigger than it'd be in editor (and better fit for header line).
End result is almost like before, tighter horizontal spacing which I actually like.

[con: it does not _exactly_ match any semantic math construct. I don't care!]
Measurable speedup on firefox & chrome.  Almost as fast as 2.4.0 was :-/

The preview is wasted work for us, we render math in invisible area
before it's measured and handed off to CodeMirror.
(User can still enable it via MJ menu, cookie overrides config.)
@cben

cben commented Oct 20, 2026

Copy link
Copy Markdown
Owner Author
  • Also, 2.7.9 has had many accessebility improvements since 2.4. Dunno how usable Mathdown is for people who need these, but can't hurt.

@cben
cben merged commit ac25ca7 into gh-pages Oct 20, 2026
5 checks passed
@cben cben added the 6 - Done label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant