# Which Markdown library is used?

I wonder which markdown library is used in this stackexchange site? In particular I like how it allows LaTeX to be used for Maths. There are many libraries like marked. Many that knows how to render GitHub Markdown even, or some extended Markdown syntax. But which in particular does things for maths.

SE uses two Markdown processors:

As others mentioned, math rendering is done by MathJax. But the question

how [Markdown library] allows LaTeX to be used for Maths

is still nontrivial. By itself, Markdown processor does not know anything about MathJax. If it was called after MathJax, it would remove all <span> tags with formulas, as it removes most HTML tags. If it was called before MathJax, it would destroy some TeX formulas by replacing, e.g., the valid formula $f *g* h$ with $f <em>g</em> h$.

The solution implemented on StackExchange is to preprocess user input by a third script (about 130 lines, named mathjax-editing.js) which escapes the text within $...$ or $$...$$ from Markdown. This way, formulas go intact through Markdown processing, and eventually get handled by MathJax. For example, $f *g* h$ renders correctly.

For various reasons, LaTeX formula delimiters  and  are not supported by this setup. The most one can do is to type \$\$ to escape backslashes manually, but this leaves the content of the formula exposed to Markdown processor: for example,
\$f *g* h \$ becomes $f g h$. So much for good LaTeX practice.

• Oh I was wondering if there was some parser that could handle Markdown+MathJax, but looks like its still done separately – Jiew Meng May 21 '13 at 13:38
• Why would they need a server side processor? They can just store the markdown. Can't they? @75064 – Atiq Rahman Jun 6 '18 at 20:56

MathJax is responsible for the rendering of LaTeX on math.stackexchange.

You might also be interested to know that you can right-click on the formatted mathematics to bring up a menu: