This already exists as a plugin:
https://meta.discourse.org/t/mathjax-plugin-supports-math-notation-using-latex/12826