在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/

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