3
$\begingroup$

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.

$\endgroup$
8
$\begingroup$

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.

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

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

$\endgroup$
2
$\begingroup$

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

MathJax menu

$\endgroup$

You must log in to answer this question.

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