Showing posts with label MathJax. Show all posts
Showing posts with label MathJax. Show all posts

Tuesday, January 22, 2013

Defining Macros in MathJax

In case of malfunction of other methods, one needs to include macros' configurations separately from another environment configuration. Also use "\\" instead of "\" to escape. For instance,

<script type="text/x-mathjax-config;executed=true">
MathJax.Hub.Config({
  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
MathJax.Hub.Config({
  TeX:{
      Macros: {
        p :'{\\mathcal{P}}',
        np :'{\\mathcal{NP}}'
      }
  }
});
</script>

Test

$$\p =? \np$$

Effectively Enable MathJax on Blogger

The Cause

Simply adding the javascript code in the template may not work for all bloggers, at least not for me. The reason is that Blogger filters the code one adds into the template and some of configurations are encoded in html entities, thus not functioning at all.

The Working Method

Go to the console, select layout and add a gadget "HTML/Javascript", put the following code inside.

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

Make sure this gadget is available globally.

Demo Test

$$\cos x = \frac{e^{ix}+e^{-ix}}{2}$$