在Octopress中加入Latex支持

主要的方法是采用MathJax

1. 如果没有安装 kramdown,需要先安装,在终端输入:

gem install kramdown


2.在source/_includes/custom/footer.html加入如下代码:


<!-- MathJax -->
<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>


这样就引入了MathJax的JS包。

上面的代码也可以在source/_includes/custom/header.html里添加,不过这样会使得页面的加载速度变慢。还可以在source/_layouts/default.html里添加。


3. 在“_config.yml”文件中,用markdown: kramdown 替换 markdown: rdiscount。

这样之后,在公式前后加入$...$,或者$$...$$,就可以在Octopress中显示Latex公式了。

用Kramdown代替Rdiscount的问题是:kramdown的格式限制比rdiscount严格,所以段前段后的空格一定不能省。




参考:

http://www.yanjiuyanjiu.com/blog/20130402/

http://kqueue.org/blog/2012/01/05/hello-world/

http://blog.zhengdong.me/2012/12/19/latex-math-in-octopress

http://steshaw.org/blog/2012/02/09/hello-mathjax/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章