Background

I need to show some mathematical expressions in my blog, LaTex is perfect and the styles are rich while a little hard to use. So how to get LaTeX‘s maths integrated into Octopress is necessary for me. I mainly referred to the blog.

Settings

I need to preview each post at local, so I installed kramdown first.

gem install kramdown

And add a following source code to my octopress system in ~/octopress/source/_includes/custom/head.html, which is an empty file for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
</script>

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>

<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

Ok, then I can type any mathematical depressions in .markdown files just like in .tex file. For example, I can input $y=x^2+\lambda*\beta$ as an inline formula like that $y=x^2+\lambda*\beta$. What’s more, a centered form can be presented like that:

$$\exp(-\frac{x^2}{2}),$$

by input $$\exp(-\frac{x^2}{2}),$$ . It is only different with the $ and $$.

Ok, job’s done!