While reviewing a suggested edit, I observed that the Mathjax formatting was not respected in the rendered output view (see screenshot below). Shouldn't the Mathjax formatting be displayed like it would be when the post is viewed?

mathjax not rendered.

I also observed this a while back for a previous suggested edit (see screenshot below). I asked about it in the 2nd monitor and was told "it's possibly a bug".

mathjax not rendered

Other sites like Math.SE do render Mathjax properly, as per screenshot below for this suggested edit.

mathjax on math.se

  • I can partially reproduce this on Firefox. What's your browser? – Mast Jun 12 at 12:35
  • Opera and chrome on Windows 10; I will try FF (regular and Developer edition) and see if it exists there as well – Sᴀᴍ Onᴇᴌᴀ Jun 12 at 12:38
  • The Mathjax markdown is not rendered in FF (regular or Dev Ed.), though in all browsers mentioned above, I do see what you showed in your answer about the \$\space x^{high\space number}\space\$ being rendered properly – Sᴀᴍ Onᴇᴌᴀ Jun 12 at 15:42
up vote 3 down vote accepted

So... This isn't the bug you think it is. The same behavior can and does show up on Mathematics, and they've lamented it for years:

The insidious bit of this is that sometimes, it seems to work - the diff engine and MathJax processor interact in juuust the right way to both render the expression properly and highlight the change...

But usually it doesn't work, and you're lucky if you only get unrendered MathJax; if you're unlucky, you get a hash of partially-rendered expressions making the diff all but impossible to decipher.

A proper solution here is probably to treat MathJax expressions as atomic, in the same way we do for (say) images: if there's a change to any part, the entire expression is marked as added/removed. This would highlight the change, albeit not with any real granularity; you'd have to carefully examine complex expressions to determine what was different. Making this happen would require some amount of awareness of Mathjax within our diff engine though, (and/or some awareness of our diff engine within our Mathjax postprocessor) so it's a non-trivial change.

The work-arounds for now are as follows:

  • Switch to "markdown" diffs. This shows you the raw expression, complete with granular diffs.

  • Hit "Improve" and view the preview. No diffs, but at least the expressions are rendered properly.

  • 2
    I generally use Option B. You can then just cancel the improve after looking at the newly rendered result. – Stephen Rauch Jun 13 at 0:24

Other sites like Math.SE do render Mathjax properly, as per screenshot below.

That's not comparing like with like. The problem in the suggested edit you reviewed is that the highlighting of the changes doesn't cover the entire width of the MathJax block, so the starting \$ and the ending \$ are in different spans. In the Math.SE screenshot, the highlight covers the entire block.

I think the only way of fixing this would be to make the highlighting code know about MathJax and treat a MathJax block as a single indivisible escape.

  • Considering that the relevant math edit changed \$dx\$/\$dy\$ to \$\frac{dx}{dy}\$ I'd think that we can expect the rendered diff on math to be the expected behavior – Vogel612 Jun 12 at 16:52
  • @Vogel612, I've no idea what specifically about "the relevant math edit changed \$dx\$/\$dy\$ to \$\frac{dx}{dy}\$" you think either should be or is being considered; but the thing that's actually relevant is that the HTML supplied to the browser contains a single <span class="diff-delete"> wrapping the first one and a single <span class="diff-add"> wrapping the second one. – Peter Taylor Jun 12 at 17:34
  • What I wanted to get at was that the change should exhibit similar "this stayed the same" semantics as apply for the tan(x) in the edit on CR. – Vogel612 Jun 12 at 18:53
  • Ah. I would guess that that comes down to what the diff function considers to be a "word", so that ties into the second paragraph of the answer. – Peter Taylor Jun 12 at 21:00

I can only partially reproduce this behaviour and if I recall correctly, it used to work just fine.

Screenshot of same question, different behaviour

Note the second paragraph, second line.

Definitely a . Quite possibly a recent one.

You must log in to answer this question.

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