Fixes mathjax bugs

There were some bugs due to markdown processing the mathjax for underscores that came up, especially when using literal curly braces `$\{ \}$` and linebreaks `\\`. This fixes them.

Code from https://github.com/mayoff/python-markdown-mathjax