7
\$\begingroup\$

When writing a MathJax heavy post I noticed a couple of bugs. For reference, here is an example of how the MathJax should look:

$$ a_{i+1} = \begin{cases} \frac{a_i}{2} & \text{if $a_i \% 2 = 0$ (even)} \\ 3a_i + 1 & \text{if $a_i \% 2 = 1$ (odd)} \end{cases} $$

Begin and end work outside of math mode

Code

a_{i+1} = \begin{cases}
    \frac{a_i}{2}  & \text{if $a_i \% 2 = 0$ (even)} \\
    3a_i + 1 & \text{if $a_i \% 2 = 1$ (odd)}
\end{cases}

Live

a_{i+1} = \begin{cases} \frac{a_i}{2} & \text{if $a_i \% 2 = 0$ (even)} \\ 3a_i + 1 & \text{if $a_i \% 2 = 1$ (odd)} \end{cases}

Preview

How the live is displayed in the preview.

An unclosed math-mode delimiter swallows some backslashes

Related: The MathJax newline \\ is broken in tag wikis

Code

$$
a_{i+1} = \begin{cases}
    \frac{a_i}{2}  & \text{if $a_i \% 2 = 0$ (even)} \\
    3a_i + 1 & \text{if $a_i \% 2 = 1$ (odd)}
\end{cases}

Live

$$ a_{i+1} = \begin{cases} \frac{a_i}{2} & \text{if $a_i % 2 = 0$ (even)} \ 3a_i + 1 & \text{if $a_i % 2 = 1$ (odd)} \end{cases}

Preview

How the live is displayed in the preview.

\$\endgroup\$
6
  • \$\begingroup\$ It might be useful to indicate what you think should happen in these cases. It's not clear to me. \$\endgroup\$
    – Edward
    Commented Mar 22, 2021 at 21:13
  • \$\begingroup\$ @Edward Personally I don't think MathJax should be eagerly evaluating. We've had posts break because of MathJax before, adding a single $$ to your post shouldn't mangle the backslashes in your question. If SE disagrees, I'd want the output to at least be correct (first example) and not be striping backslashes. Since the related bug has regressed to the point where MathJax seems to not work at all in the tag wiki. I really only care the bugs are fixed, not how. \$\endgroup\$
    – Peilonrayz Mod
    Commented Mar 22, 2021 at 21:29
  • 2
    \$\begingroup\$ I'm not disagreeing, just not understanding. Typical bug report forms ask both "what did happen" (which you have documented) and "what should happen" which I'm not yet able to infer. \$\endgroup\$
    – Edward
    Commented Mar 22, 2021 at 21:33
  • 1
    \$\begingroup\$ Why are your previews in dark mode? Are you using a script to change this? I do get the same results without the $$ when I paste this code but, with them, it works as expected - is it the fact that the MJ is rendering at all without the $$ that is part of the issue? I think @Edward makes some good points - Having a "what you think should happen instead" might make this easier to understand for me - This also occurs on some other MJ-enabled sites, such as Mathematics, so It'd be good to know what the common concern is and how it should be addressed. :) \$\endgroup\$
    – Catija
    Commented Mar 26, 2021 at 18:35
  • \$\begingroup\$ @Catija "Why are your previews in dark mode?" Because my preferred browser has a dark mode addon and white previews hurt my eyes when writing up. I do check on a browser with no scripts but keep activity in such an environment to the minimum. "what you think should happen instead" I don't know how better to explain myself than in my first comment. The two solutions I talked about are; ① don't eagerly evaluate the MathJax outside of where I properly tell the software where MathJax is ② render things correctly (see the blockquote example at the top of the question). \$\endgroup\$
    – Peilonrayz Mod
    Commented Mar 26, 2021 at 19:20
  • \$\begingroup\$ Tested the second half of the post on Math.SE. \$\endgroup\$
    – Peilonrayz Mod
    Commented Aug 13, 2023 at 16:24

2 Answers 2

3
\$\begingroup\$

Begin and end work outside of math mode

The dollar signs are not the only delimiters that MathJax looks for. Because environments like \begin{align}...\end{align} also introduce math mode (they don't require other delimiters in LaTeX), MathJax also processes any \begin{xyz}...\end{xyz} pairs as math delimiters. So even though you haven't closed your dollar signs, MathJax picks up on the \begin{cases}...\end{cases} and thinks they are math delimiters, so processes the contents. That is why you are seeing part of your expression processed by MathJax.

An unclosed math-mode delimiter swallows some backslashes

It's not MathJax that's doing it, it is the Markdown processing. The \% has been turned into % in the page source, and so the rest of that line (2 = 0$ (even)}) is considered by MathJax to be a comment. Note also that the final \\ has been turned into a single slash. It used to be that the preview code was set up to work the same as MathJax in terms of determining what is math and what isn't, but that seems to have diverged over time. So the preview doesn't realize this is math, and so is performing Markdown substitutions. I suspect the unclosed $$ is confusing the preview.

\$\endgroup\$
0
0
\$\begingroup\$

Although we don't have the new "Live/Preview" editor on math.SE, I have seen the the Live part of the first bug many times when entering a post. I have believed this to be a problem with the browser. Usually, if I wait for a few seconds, the MathJax renders fine in the Live window. If I copy the post (so that I keep all my changes after the last draft save) and refresh my page until the Live window renders immediately, I can paste the copied version of my post back into the Code window and all continues as it should.

I've not noticed the second bug, but when my MathJax is not rendering properly, I look for where the problem is in my code and correct it. Perhaps this bug exists for me, but I've corrected my code too quickly to notice that it is this bug.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ My main concern is eagerly evaluating MathJax breaking users code without MathJax being intentionally used - related meta. I have in the past seen high rep users just straight up blame the bug on the low rep user. Who posted code and didn't intentionally use MathJax. We don't need even more ways for such unpleasantries to occur. And as I think you've described; if you're intentionally using MathJax you can probably fix the issues. Making the bug mostly a trivial issue for most other MathJax enabled sites. \$\endgroup\$
    – Peilonrayz Mod
    Commented Mar 26, 2021 at 20:13
  • 1
    \$\begingroup\$ Okay. Since "a MathJax heavy post " was mentioned, I did not realize that the concern was related to unintentional MathJax use. I haven't looked, but I wonder if an option to turn MathJax off/on (per post) for sites that do/don't generally use MathJax has been suggested or investigated. \$\endgroup\$
    – robjohn
    Commented Mar 26, 2021 at 20:42

You must log in to answer this question.

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