47

While this is not the way I wanted to announce this, it seems the cat is out of the bag. But for those who haven't noticed, as part of our Community Asks Sprint, I spent the week investigating how we might go about upgrading our MathJax version from 2.x to 3.x+, as had been requested in several places, notably:

Caveats

Right off the bat, I want to place some important caveats on this work:

  1. It's still experimental and early stages.
  2. There are several features that were removed in v3 that will likely come back in v4 that are probably worth including in a GA release.
  3. If there are too many insurmountable issues, we may have to stick with v2 for the foreseeable future until we can further dedicate / prioritize efforts.

For these reasons, v3+ right now is opt-in only at the individual account level for folks who would like to take part in early beta testing and report back any issues they find (on this post). On sites that have MathJax enabled, you'll see a preference toggle under /users/preferences/current that will enable MJv3 for your account.

MathJax v3 User Preference Toggle

If this in any way impedes your work please feel free to toggle back off to V2. If we need to roll this back for any reason, we can disable the toggle and serve all users v2 until any Sev 0 issues are fixed. Also, if there are any syntax choices that work better in v2 than v3, please stick with v2 while drafting new posts to optimize for all viewers until we've rolled this out everywhere.

Known Issues / Deltas / Mitigations

  • Currently only the TeX font is available (HTML-CSS.availableFonts not implemented)
    • Note: we used to allow STIX & TeX, but preferred TeX, so only having that option should be acceptable.
  • The HTML-CSS.EqnChunk option is not yet implemented (but may be in a future release)
    • Note: Chunking allows for the site to process small batches of changes to optimize load times. On mobile we chunked 10 at a time, on desktop 50. The new version is more efficient and does all loading in a single pass, so chunking is not really a concept there and much less of a need.
  • Extension TeX/begingroup is not yet implemented (but may be in a future release)
    • Note: Grouping allowed expressions from one post to not impact another by sideloading resources. This is not implemented for v3 so it's possible to have side-effects from multiple different posts on the same page. This may be a blocker for GA.
  • The HTML-CSS.linebreaks option is not yet implemented (but may be in a future release)
  • MHChem is now included in the base package by default, so we may eventually be able to do away with enabling mhchem on a site-by-site basis as it will automatically lazy load if used.
  • Packages that are \require'd in many have been moved around, notably AMScd which seems to break spectacularly enough that JS throws for the entire page. I'll try to get a quick turnaround to patch that up, so we can focus on more edge case error reporting here.

Reporting / Future

A future consideration is how any content changes will work if we need to update syntax on posts between v2 and v3. For Example, in my testing AMScd seems to be case sensitive, which is gonna be a tricky migration if we need to fix during the upgrade, but maybe there's a programmatic solution we can unlock as well.

I wanna thank Davide Cervone for his helpful analysis here and ongoing project updates. Please feel free to report any issues you run into under this post, that'll be helpful for the full migration, but please be aware that there's not a team on this full time right now, so this is more to help line up and document remaining work than a full feature rollout at this point.

7
  • 4
    Thanks for you and the team's work on this, @KyleMit! :)
    – V2Blast
    Commented Oct 1 at 17:57
  • 3
    \sin looks uneven in v3 Commented Oct 1 at 18:18
  • 1
    @ТymaGaidash It looks correct to me. Thus, this may likely depend on your browser, OS, fonts, and such things; you need to supply more details. Commented Oct 4 at 9:45
  • 2
    The title mentions "v4" but the screenshot shows "Enable MathJax v3". Is the upgrade to v4 another step that is scheduled after the upgrade to v3?
    – A.L
    Commented Oct 4 at 12:27
  • Given that MathJax v4 seems to be around the corner (see the releases page and the milestones), wouldn't the testing for v3 be invalidated soon? Commented Oct 6 at 7:41
  • 4
    As per math.meta.stackexchange.com/a/35383 , the API of v3 and v4 is substantially the same, thus once the upgrade to v3 is working, switching to v4 should be relatively easy. Commented Oct 6 at 9:57
  • 1
    @Kyle Said non-backward incompatibility of the \color command is a serious problem that needs to be fixed before making the upgrade, e.g. I have almost 2800 answers that use color to convey essential information. Destroying that info would make many of these answers much harder to icomprehend (possibly incomprehensible in many cases). Are you able to write a script to fix these on your end? (it's too much work and disruption for users to do so) Commented Oct 16 at 23:49

8 Answers 8

8

In preview, display math $$ ... $$ is incorrectly rendered as ordinary in-line math $ ... $.

E.g., when editing this answer, the preview looks like this:

Screenshot of an editing window with preview rendering two displays inline

It shows up correctly in the final post.

Strangely enough, editing this post shows an opposite behaviour: $$ ... $$ displays properly, but normal paragraph breaks are not rendered. Also, Markdown formatting including *...* and **...** is not rendered:

Screenshot showing paragraph breaks and Markdown markup not rendered in preview

Again, it shows up correctly in the final post, and in v2.

3
  • 2
    And even if $$ ... $$ is surrounded by blank lines the equation is left-aligned instead of centered in preview mode.
    – Martin R
    Commented Oct 5 at 9:58
  • 2
    Oh, I didn’t notice that. On second thoughts, blank lines are completely irrelevant: display math shows up in preview as inline math, period. When surrounded by blank lines, it simply creates a paragraph consisting solely of the equation (hence, naturally, left-aligned). However, the equation is still in inline math: this can be easily seen when you try things like $$\frac{a+b}{c+d}$$ versus $$\displaystyle\frac{a+b}{c+d}$$. Commented Oct 5 at 11:10
  • Yes, that makes sense.
    – Martin R
    Commented Oct 5 at 11:25
6

In many of my answers on Math SE and MathOverflow, I use the \label MathJax command with equations, e.g., \label{eq1A}, so I can later reference them using the \eqref command, e.g., \eqref{eq1A}. This, however, doesn't work properly with the new version's editor, with it complaining about each of the labels being duplicated, even though one of them are actually being used.

For example, with my answer on Math SE, when the option is turned off and I edit the answer, the top part of what I see is:

Math answer edit using MathJax v2

However, when I turn on the MathJax v3 beta option, the top part of this is now:

Math answer edit using MathJax v3 beta

These yellow multiple definition error messages continue further for every equation where I used \label. Note this problem also occurs while I'm initially creating a new answer. Nonetheless, apart from requiring a refresh if I save my edits, the final display does otherwise work properly (including if I'm only just displaying these answers).

3
  • 2
    The old preview would often get confused with labels, too—I don't remember what circumstances tripped it, but I think that, for example, a reference to a label defined in another post (but on the same page) would confuse it, and I'm pretty sure that even some inter-post labels wouldn't work. It just gave the old classic (???) instead of this "multiply defined" stuff. (I've kind of got the impression that the mantra for the post preview is "it's great if it works, but you should expect it to break, or at least display different results from the final, regularly.")
    – LSpice
    Commented Oct 1 at 13:59
  • 1
    @LSpice I've encountered similar type issues. For example, using the same label as one used in another post on the same page doesn't work properly (e.g., I asked about this issue on Math meta in Display issue with first 2 equations in an answer, although they appear fine in Edit mode). Regarding giving "???", I get that if I use \eqref with a label that doesn't exist, while I also do get the "multiply defined" stuff if the same label was used more than once, including in other posts on the same page. Finally, the preview does sometimes get ... Commented Oct 1 at 14:15
  • 1
    @LSpice (cont.) quite confused when I use labels, such as it not converting the MathJax commands in the equations, with it just showing this inside a square box, similar to the image in that Math meta question I referenced above. Finally, I don't recall ever getting the "multiply defined" error in any cases other than when that was true, with it obscuring the later defined equations only, so this is now a new issue since I now can't even at least see the MathJax commands in the preview window. Commented Oct 1 at 14:19
5

I added a comment using the MathJax \color command to make several parts of a couple of equations be red. To better show the text that I used and the results, I repeated this using an answer on Math meta's "Formatting Sandbox" post. Here's what it looks like with the option turned off while editing:

MathJax v2 color for part of an equation

After saving this, both the post, as well as the comment, appear correctly. However, when editing that post with the MathJax v3 beta option turned on, it instead appears as:

MathJax v3 beta color for part of an equation

Notice how the first equation now has all of it being red (as shown in the first blue oval) after the first usage of \color, as opposed to just the intended 3 separate smaller parts. Also, in the second equation on the next line, the last 3 terms (in the second blue oval) are red, instead of just the the last term of the LHS of the equation.

Unfortunately, this problem persists when I view this post, as well as the original comment.


Note that wizzwizz's comment below states:

This behaviour is documented; there's a fix available, but I think this should only be applied to old posts, if possible.

Fortunately, one quite simple way to have the color handling work properly in both MathJax v2 and v3, as it's now without any potential fixes or other changes being implemented, is to use brace brackets around each of the color commands and text, so they form their own groups. For example, we can change \color{red}{2abc} in the first equation above to {\color{red}{2abc}}. More details, including the updated MathJax text, is in the Math meta answer I mentioned earlier.


This issue may potentially cause a syntax error to be displayed instead of the equation. Using MathJax v2, the last part of this answer is:

MathJax v2 for an equation in the last part of an answer

The issue is with the red '+' superscript being used. In MathJax v3 beta, this causes the equation display to become:

MathJax v3 beta for an equation in the last part of an answer

Note that the edit preview shows the same behaviors as in both the corresponding v2 and v3 beta displays. Fortunately, my earlier suggestion of using brace brackets around the entire part also solves the problem here for both v2 and v3 beta, i.e., in the MathJax for the equation of

$$\lim_{x\to0}\sqrt{|x|}\ln|x|=
\lim_{x\to0^\color{red}{+}}x^{\frac12}\ln x=0.$$

I changed in the middle part of the second line the \color{red}{+} text to {\color{red}{+}}.

3
  • 3
    This behaviour is documented; there's a fix available, but I think this should only be applied to old posts, if possible.
    – wizzwizz4
    Commented Oct 1 at 17:38
  • 1
    @wizzwizz4 Thanks for those details. I've added a link to your comment, as well as what it states, to the end of my answer. I'm unsure about how the SE staff working on this will deal with the problem, but I think that we should ideally all be using the new method once the update is complete. If so, then perhaps the old posts can be updated automatically at that time. Commented Oct 1 at 17:50
  • 1
    @wizzwizz4 The fix would need to be done by SE since there are far too many occurrences, e.g. I use color in almost 2800 answers (many of which would be much harder to comprehend if that info was destroyed). Commented Oct 16 at 23:52
4

It seems v3 has some issues with bounding box of some expressions with exponents. Here are two examples I found now - notice the exponents being cut out:

source: 0\leq(x(x-a)(x-b))^{2^n}=-1.

(from https://math.stackexchange.com/a/2647669/290240 )

v3: enter image description here

v2: enter image description here

source: x^2+x-\zeta_{2^{n+1}} \equiv x^2+x-1 \in O_K/(\pi)[x]\cong \Bbb{Z/2Z}[x]

(from https://math.stackexchange.com/a/3340575/290240 )

v3: enter image description here

v2: enter image description here

I'm sure there are better examples around. I think I saw v2 doing this too but it was very rare, in current v3 beta I see it much more often.

Edit: I just noticed that the second example shows how v2 and v3 render the number two at the end differently. But I guess v3 is correct in this case, since \Bbb{} applies to the whole Z/2Z.

4
  • 1
    FWIW, I've noticed the same issue myself, with it always appearing (at least as far as I've noticed so far) to be having only the top being cut off (as opposed to mostly the bottom, as I've seen in several posts with v2). Also, as you suggested, I don't recall which ones, but I've seen several examples where I believe the top cut-off amount is even somewhat more than in your 2 examples. If I see any more such cases, I might leave another comment here with a link to the post, as well as links to screenshots of how it looks in v2 and v3. Commented Oct 4 at 20:24
  • 1
    @JohnOmielan Yes, please - the link is fine, I can update the post. I saw some examples yesterday, but I didn't save them...
    – Sil
    Commented Oct 4 at 20:28
  • 1
    In the MathJax context menu, you can choose a different renderer in Math Settings / Math Renderer. I generally prefer the SVG renderer on my phone browser (Samsung Internet). The exponents in your examples don't get cut off in v3 with the SVG renderer.
    – PM 2Ring
    Commented Oct 4 at 22:38
  • 4
    This seems to be caused by some CSS in primary.css that sets overflow: auto hidden for mjx-container. I presume this is to allow wide expressions to be scrolled. Unfortunately, you can't use auto with visible. But you could include padding: 2px 0, say, in order to get a little leeway on the top and bottom. I would recommend using mjx-container[display="true"] for this rather than just mjx-container, so as not to have it applied to in-line expressions. Commented Oct 6 at 18:01
2

Certain special characters are not currently being handled appropriately with MathJax v3 beta. For example, the top part of Sea ships and their space-time equations, in MathJax v2, appears as:

MathJax v2 display

However, with MathJax v3 beta, it now shows as:

MathJax v3 beta display

i.e., "Math input error" is displayed instead for both equations. The editor display of that part of the question is:

Editor display

What's interesting is that the problematic character displays as a space followed by a question mark enclosed in a square. However, this display isn't the same here, e.g., with

x ⃗

Instead, as you can see, it appears to be a small square (at least for me, with this being similar to how unsupported characters with the current font are displayed), and a small arrow when shown by itself. However, on MathJax supported sites like the Math meta one, the square box is displayed as an arrow as well! This is a Unicode character that causes a backspace and overlay, which is how the "x" with an arrow overtop of it is shown in the top MathJax v2 output. Note that one may get a very similar result using MathJax with $\vec x$ instead.


There are also other special characters that work in MathJax v2 but result in the yellow "Math input error" message with MathJax v3 beta. For example, in Revision 4 of Find the smallest constant $C$ with given condition., the OP used the Euro symbol character. Unlike the other character mentioned above, this one appears to always be displayed properly, e.g.,

$€$

I'm unsure about why this problem is occurring with certain characters in MathJax v3 beta. I checked, but didn't find, this issue in the Upgrading from v2 to v3 - MathJax 3.2 documentation Web page. My suspicion is that MathJax v3 may be trying to interpret them as being some sort of unrecognized special MathJax characters.

0
2

In v2, the quote characters “...” (U+201C and U+201D) display as themselves just like most other Unicode characters:

Screenshot of a question using quote characters as rendered in v2

In v3, they are engorged into huge double stroke characters:

Screenshot of the same question as rendered in v3

(The screenshots are from this MathOverflow question.)

0
2

With MathJax v2 it was possible to copy/paste a line containing MathJax into a plain Text editor. Of course this gives only a simplified representation.

For example, this is what I get when copying the title of this Math SE question on a Mac into a TextEdit window (raw format), or into BBEdit:

Determine a unit vector which is perpendicular to 2𝑖+𝑚𝑗−3𝑘 and parallel to 2𝑖+𝑗−𝑘.

With MathJax v3 I get only

Determine a unit vector which is perpendicular to and parallel to .

so apparently all math content is omitted from the copy.

1
  • Well, this is inconvenient, but it does not actually break any posts, old or new. It might even be a good thing, as it prevents clueless people from blindly copy-pasting the rendered form of a post, destroying the proper MathJax markup (I’ve seen this happen many times). Commented Oct 23 at 12:43
1

Another preview bug: < followed by a letter inside a MathJax expression renders the rest of the paragraph invisible (as it is presumably misparsed as a start of an invalid HTML tag).

Screenshot of preview window

It works correctly in the final post, and it worked even in preview in v2.

You must log in to answer this question.

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