MathJax
October 15 201794 words, ~1 min. read
javascript, maths, chemistry, tex
MathJax is a cross-browser JavaScript library for maths which can be used to display maths formulas and equations beautifully in all browsers. In addition to maths, it can also be used for chemical equations and formulas with the help of TeX extensions.
Usage
- Include the following JavaScript,
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"></script>
- Configure MathJax extensions, as appropriate; for example, to include
mhchemextension,
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ TeX: { extensions: ["mhchem.js"] }});
</script>
Examples
- Equation for Pythagorean Theorem: \(a^2 + b^2 = c^2\)
- Algebra formula: \((a+b)^2=a^2+b^2+2ab\)
- Chemical equation for water formation: \(\ce{2H_2 + O_2 -> 2H_2O}\)