Personal blog of Matthias M. Fischer


Beautiful Math Formulas with MathJax

Posted: 15th December 2021

Preface

Some days ago, I mentioned that I still need to find a way of typesetting mathematical formulas in my HTML files. I just noticed that the solution was right in front of my eyes all the time -- on the webpage of the arXiv preprint server, to be precise. They use MathJax to achieve exactly this, and as it turns out, it's extremely easy to set up. In this post, I'll quickly describe how to do it.

Setting up MathJax

To 'install' MathJax, you basically have to only load two external Javascript files by adding the following two lines into the header of the HTML file in question:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

Done.

And using it

You can now simply include tex-syntax formulas in your file by enclosing them in escaped round brachets. For example

\( e^{i \pi} + 1 = 0 \)

will automatically be rendered as

\( e^{i \pi} + 1 = 0\).