Gavin R. Putland,  BE PhD

Sunday, November 24, 2013 (Comment)

Using MathJax with a ‘Classic’ Blogger template

The LVRG Blog, like this one, uses a “Classic” Blogger™ template. The post “Ramsey and Pigou: crypto-Georgists” (LVRG Blog, Sep.19, 2013) uses MathJax to render mathematical symbols and equations. These are written in LaTeX commands mixed with the HTML source file, except that the delimiters for inline equations are ‘\(’ and ‘\)’ because dollar signs are not accepted in the default mode. The usual delimiters for displayed equations also work. All LaTeX commands must be enclosed in such delimiters, even if they would not be so enclosed in a pure LaTeX source file.

To render the mathematics, the following code is inserted just before the first use of mathematical symbols (i.e. just after the paragraph announcing “The rest of this page requires JavaScript...”):

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({TeX:{equationNumbers:{autoNumber:"AMS"}}});
</script>
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>

The first script enables automatic numbering of equations (although in the post in question, because the equations are all quoted, I've chosen to number them manually with the \tag{} command).* The second script specifies that the input is in TeX/LaTeX and the output in HTML/CSS (other options are available, but I find the HTML/CSS output more attractive than the alternatives). That's all there is to it!

The above code can be inserted anywhere in the page. But inserting it just before it is needed will allow earlier parts of the page to be displayed with minimum delay, and later parts with minimum jitter.

It is also possible to include the necessary code in the blog template — at the top of the <head> tag — making the scripts available in every post. I have not done it that way, for the following reasons:

  • Because my main page is limited to a table of contents, inserting the code in multiple posts will not cause it to be loaded multiple times on the main page.
  • By inserting the code only in the posts in which it is needed, I avoid any risk of interference with older posts that don't use MathJax.
  • If I want to see the equations while composing a post on the local hard drive, I need the scripts in the post itself; so I might as well leave them there.

N.B.: The above remarks are applicable to Blogger™ with “Classic” templates. They are not necessarily applicable to newer templates or other blogging platforms.

* Update (9 December 2013): For a more thorough demonstration, with automatically numbered equations referenced by labels, see “A self-contained derivation of Kepler's laws from Newton's laws”.


Creative Commons License         Return to Contents
comments powered by Disqus