MathJax fails to render inline math when followed by curly apostrophe (U+2019) but works with straight apostrophe (U+0027)

I’m encountering a rendering issue with inline MathJax in Discourse when the math expression is followed by a curly apostrophe (U+2019), which is commonly substituted by smart quotes in some browsers or editors.


:white_check_mark: This renders correctly:

$\mathbb{R}^2$'s basis

This uses the straight ASCII apostrophe (U+0027).

\mathbb{R}^2's basis


:cross_mark: This fails to render:

$\mathbb{R}^2$’s basis

$\mathbb{R}^2$’s basis

This uses the curly right single quote (U+2019), sometimes auto-inserted by mobile keyboards, rich text editors, or copy/paste from formatted sources.


Expected behavior:

Both versions should render the math properly. The character immediately following an inline math block shouldn’t affect MathJax parsing.

Why this matters:

  • This is hard to detect unless you’re comparing Unicode.
  • The curly apostrophe is visually indistinguishable from the straight one in most fonts.
  • A minor formatting difference like this shouldn’t silently break rendering.
  • Inconsistent behavior undermines the authoring experience for math-heavy posts.

I wouldn’t expect TeX to treat a quote and a curly quote the same way. This seems like the expected behavior, however annoying.

This seems like the source of the problem, but that’s probably just because I’m old. :wink:

1 Like

oh so the MathJax engine, can it see what’s outside of $…$ or \begin{matrix}\$\$ \\\vdots\\\$\$ \end{matrix}

Hmm. I really shouldn’t have replied since I quit using LaTeX a decade ago, but here I am.

I think that the closing $ needs to be followed by a space and somehow the regular apostrophe is a special case.


$\mathbb{R}^2$s basis
$\mathbb{R}^2$’s basis
$\mathbb{R}^2$ ’s basis

$\mathbb{R}^2$s basis
$\mathbb{R}^2$’s basis
\mathbb{R}^2 ’s basis

So, I think your simple solution is to always put a space after the closing $.

I’m pretty sure that this is the expected behavior and am surprised that my decades old knowledge still seems to work, but that’s why the TeX version number approaches \pi.

Well, there’s still that annoying extra space if you put a space. And a period after the closing dollar works as expected.

I’m back to thinking that maybe I don’t know what the expected behavior is and I’m not willing to try to render TeX from my phone.

Edit: Aha. The answer is, I think, more complicated than either of us expected. See TeX and LaTeX math delimiters — MathJax 3.2 documentation

Tl;dr— you don’t want to start rendering math just anytime someone uses a dollar sign!

1 Like