Sunday, March 18, 2012

Using MathJax with blogger

I work with Latex a lot with my job and I have not written anything about it here on my blog since it was difficult to get equations written. Recently though, I found MathJax on the web. But, they do not have any instructions for blogger that I could find.

The first website I could find that had some sort of instructions was:
http://tex.stackexchange.com/questions/13865/how-to-use-latex-on-blogspot

This is not optimal since it says to put the code in by editing the template, and that means you would need to keep modifying the template every time you wanted to change the look of the blog. Instead I added the scrip as a gadget on the side of the page with the title MathJax. It does not display anything; it just loads the script to display equations.


I then added a custom scrip to not use $ or $$ as delimiters and to only use \(  \) and \[  \]


If you have java script enabled these equations should show up as math

Inline:

\( x < x^2 \) if \(x>1\)

Centered:
\[ f(x) \]

You can make this work by adding the following text as a gadget as well:

<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js" type="text/javascript">
MathJax.Hub.Config({
 extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"],
 jax: ["input/TeX", "output/HTML-CSS"],
 tex2jax: {
     inlineMath: [ ['\\(','\\)'] ],
     displayMath: [ ["\\[","\\]"] ],
     processEscapes: true
 },
 "HTML-CSS": { availableFonts: ["TeX"] }
});
</script>

You can then turn it off by adding the tags: (how I wrote the code above)

<div class="tex2jax_ignore">
</div>

No comments:

Post a Comment