In a suggested edit I just reviewed, about a third of the MathJax renders properly, but the rest doesn't. Note that the delimiters on puzzling are \$, so that doesn't escape it.

Bad MathJax rendering


Don't render MathJax when viewing source: Broken LaTeX rendering of markdown differences

Render MathJax when viewing rendered output: MathJax rendering for suggested edit queue


That's because once the system has modified it to add red and green (added and removed) backgrounds, it's no longer valid MathJax.

Since MathJax is rendered client-side and not server-side, it would need to be valid when outputted from the server. However, for example, the very first place it breaks is not valid because it actually looks something like this:

  • 3
    Hmm. Looks like this explains it. I wonder if they should just mark the whole span as modified, like they do for some other changes.
    – Kevin
    May 23 '14 at 15:26
  • So this is status-bydesign, right? Mar 1 '18 at 14:47

This has bugged me for a long time. Unfortunately, there doesn't seem to be any easy way to fix it on the client side, since the MathJax markup is already mangled when it's sent from the server.

However, there's a (relatively) easy way this could be fixed on the server:

Make the "rendered output" diff engine treat MathJax blocks as atomic units.

The server-side Markdown parser is already MathJax-aware (since it needs to disable normal Markdown parsing within MathJax blocks), so this would seem reasonably doable.

The obvious down side of this solution is that even small changes inside long equations would be shown as the whole equation changing. Alas, there seems to be no way to fix that without somehow embedding diff support within MathJax itself. Fortunately, those kinds of changes are usually best viewed in source diff mode, anyway, and at least this would still be an improvement over the current broken rendering.

  • 1
    This is exactly what we do as of about an hour ago. :)
    – Adam Lear StaffMod
    Sep 20 '18 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .