# MathJax + Markdown rendering in comments

The following comment (edited down from a real-world example) "$\cong$—spacer *italics* spacer—$\mapsto$" should render roughly as "≅—spacer italics spacer—↦", but, on MathJax-enabled sites like MathOverflow, the stars render literally, rather than entering italics. This appears only to happen in comments, not in post bodies.

Here's a slightly more minimal example: $\cong— *italics* \cong$: code
$\cong— *italics*$\cong$. The lack of a space between the MathJax and em-dash is necessary ($\cong$— *italics*$\cong$: code $\cong$— *italics*$\cong$), and there also must be MathJax on both sides ($\cong$— *italics*: code $\cong$— *italics*).  • The code used to hook MathJax into the Markdown for the page is designed to match the way that MathJax locates the math within the page (and it removes the math, then runs Markdown, then puts the math back). I suspect that the code for the comments has not been so carefully crafted. Indeed, I suspect that they are simply using a regular expression match like /\$(.*)\$/ to locate the math, and so this would match the first dollar sign to the last one, and consider the entire contents to the math (including the stars), preventing it from being processed for the mini-Markdown in comments. Jul 22, 2018 at 15:02 • Using /\$(.*?)\\$/` would do better, but still would not always work. It turns out that math that is renderable by MathJax can't be identified by a standard regular expression. Jul 22, 2018 at 15:03