# MathJax wrongly rendered when used as alt text for image

When MathJax is used within the alt text of an image, like this:

![test $2$][1]

the rendered result will show the MathJax 'outside' the image:

Interestingly, the preview renders the image correctly, presumably because it doesn't try to render the MathJax:

<img src="https://cdn.sstatic.net/Sites/math/img/logo.svg?v=2ad3f9715b74" alt="test <span class="math-container">$2$</span>"></p>
which is invalid HTML. The quotation marks for the math-container element end the quotation marks for the alt attribute, which means the > before $2$ is parsed as the end of the img tag, and so the $2$ now falls outside the alt text, and is displayed by MathJax. This doesn't happen in the preview because the math-container tags are not inserted during previews.