Chris Henson


Using MathJax to Display Equations in HTML

Just something small for my first entry here. You might be wondering "how are you going to effectively display equations on your website?"

The mathematics notation is pretty painless, provided you're already familiar with LaTeX. In the header of this page I have the following:

<script type="text/x-mathjax-config">
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
<script type="text/javascript"

which imports the JavaScript engine MathJax and allows me to natively use LaTeX in my HTML. So I can simply type:

$$ \sum _{n=1}^{\infty } \frac {1}{n^{2}} =\frac {1}{1^{2}} +
                                           \frac {1}{2^{2}} +
                                           \frac {1}{3^{2}} +
                                           \cdots $$

which is rendered as: $$ \sum _{n=1}^{\infty } \frac {1}{n^{2}} =\frac {1}{1^{2}} + \frac {1}{2^{2}} + \frac {1}{3^{2}} + \cdots $$

Check out the page source (Ctrl+U in chrome) and you'll see that the above equation comes from the exact same code.

If you've never seen that equation before, this is the Basel problem, which will likely be the subject of a future post.