improved mathjax handling