Note: In the submitted version of the question, the comma is no longer being displayed – but when I edit the question, it’s displayed again in the preview.

I encountered a strange bug (at least it seems like one; perhaps I just don’t see the logic behind the behaviour):

$$ \int\frac1x\,\mathrm dx $$

\begin{eqnarray} \int\frac1x\,\mathrm dx \end{eqnarray}

\begin{eqnarray} \int\frac1x\,\mathrm dx \end{eqnarray}

The code for all three is the same, with \, used to put some space between the quotient and the differential. The only difference is that the first one is written as $$...$$, the second one as \begin{eqnarray}...\end{eqnarray} and the third one as \begin\{eqnarray}...\end{eqnarray}, with a spurious slash in front of the opening brace. I would have thought that this should lead to a syntax error warning, not to \, being interpreted as a comma in the environment.

  • $\begingroup$ On my PC (Fedora Linux running Chromium browser, HTML-CSS as MathJax renderer) I am not seeing any comma or other perceptible difference between the three expressions. $\endgroup$ – hardmath Mar 26 '20 at 13:47
  • 1
    $\begingroup$ @hardmath: Did you see the note at the top? Does it not show up when you try to edit? It's the same for me in Firefox, Safari and Chrome (all on Mac OS $10.14.6$), so it doesn't seem to be browser-dependent. $\endgroup$ – joriki Mar 26 '20 at 13:51
  • $\begingroup$ Yes, in the Edit preview the third expression suddenly acquires a comma ! $\endgroup$ – hardmath Mar 26 '20 at 13:54
  • $\begingroup$ @hardmath: OK, I've made the note more prominent :-) $\endgroup$ – joriki Mar 26 '20 at 13:57
  • $\begingroup$ The same happens if one writes "\end\{eqnarray}" or puts any other valid thing instead of "eqnarray". But why would you use a "\" after the environment name? It's the first time I see it written like that. $\endgroup$ – Zacky Mar 26 '20 at 15:27
  • $\begingroup$ @Zacky: It was a typo, I don't usually write it like that :-) Still, it seems like a bug when you have a typo in the environment header and instead of a warning it causes escape sequences to malfunction. It took me a bit to figure out why \, wasn't working... $\endgroup$ – joriki Mar 26 '20 at 21:27
  • $\begingroup$ Yes, when you write code with syntax errors, unexpected things will happen. I don't see how it's a bug. $\endgroup$ – Najib Idrissi Mar 27 '20 at 7:47
  • $\begingroup$ @NajibIdrissi: The important question isn't whether we should call it a bug but whether it should be changed. I think it should be changed. Error handling is an important part of functionality. Ideal error handling is outputting a helpful error message. Adequate error handling is failing at the point of the error. Error handling that causes spurious errors elsewhere that are hard for the user to connect to the actual error is bad error handling and should be fixed. $\endgroup$ – joriki Mar 27 '20 at 10:02

This turns out to be an interaction between StackExchange's Markdown processor and MathJax. Here's what's going on: in the editor, the preview code has to remove the mathematics before it is processed by Markdown (so that the mathematics isn't changed by Markdown) and then puts it back in the text of the post. It does that by looking for the math delimiters, which includes $...$, $$...$$, and \begin{...}...\end{...}. Since \begin\{eqnarray}...\end{eqnarray} does not match any of these (because of the \{ rather than {), it is not removed from the document as math, and instead is processed directly by Markdown. Markdown uses the backslash as an escape character that prevents the usual Markdown action of the following character. In doing so, the backslash is removed (but apparently only when it actually prevents a Markdown action), so \{ becomes { and \, becomes , (but \b stays \b and \e stays \e since these are not preventing any Markdown action).

That means that

\int\frac1x\,\mathrm dx


\int\frac1x,\mathrm dx

in the actual HTML for the preview. When MathJax runs on the result, it now does match as a math delimiter (since the \{ has been turned into { by markdown), and the math is processed. Because \, has been turned into , by Markdown, you see the comma rather than the space that \, would have produced.

When the final post is created, it is processed on the server to do the Markdown formatting. Originally, the server-side code and the preview code were the same, but over time, the server-side code has been updated, and it appears that it no longer does exactly what the preview code does. I suspect that the Markdown processing is slightly different, and that while \{ is being converted to {, the \, is not being changed. The , is not really a Markdown command, so \, its not escaping a markdown function, and so it shouldn't be altered, just as \b and \e aren't. I suspect that the in-browser Markdown processor is just treating \ followed by any non-letter as an escape, whereas the server-side one is more discerning. I don't know that for sure, but that is what it looks like.

As for error messages, MathJax only reports errors on things that it recognizes as math, and since \begin\{ doesn't look like \begin{...}, MathJax doesn't recognize it as a math delimiter, and doesn't process it (including not reporting any errors). If you used \begin\{ inside other math delimiters (e.g., $$\begin\{array}{c} a \end{array}$$, MathJax would report an error.

  • $\begingroup$ Thanks for the detailed analysis! $\endgroup$ – joriki Apr 3 '20 at 16:29

You must log in to answer this question.

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