顯示具有 mathjax 標籤的文章。 顯示所有文章
顯示具有 mathjax 標籤的文章。 顯示所有文章

2016年1月31日 星期日

[ipython] jupyter 數學公式的寫法(還有顯示 $ 錢字號 dollar sign)

目前查到的有兩種方法。一種是用 ipython.display 的功能,一個是使用 mathjax。

使用 ipython.display
ipython.display 提供非常豐富的顯示方式,這種方式是靠 code cell 執行程式處理。
像是:
來源[1]

來源[1]





使用 mathjax
基本上 jupyter 已經是使用 mathjax 處理數學公式。而且它整合在 markdown cell 裡。
所以只要把建立一個 markdown cell,把 latex 的表示的前後加上 $ 這個符號,像這樣:
$c = \sqrt{a^2 + b^2}$

再按下 cell 的執行按鈕,就會畫出公式了。
來源[2]

因為錢字號現在被視為語言關鍵字,在文章中要顯示 $ 的方法,可以看以下文章:http://codebeta.blogspot.tw/2016/01/blogspot-blogger-latex.html


參考:
[1]http://nbviewer.jupyter.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb

[2]http://jupyter-notebook.readthedocs.org/en/latest/notebook.html#markdown-cells

[mathjax]在 blogspot / blogger 網誌裡顯示 latex

要在網頁上顯示公式,現在查到的主流方法是用 latex 語法,函式庫是用 Mathjax。總之時代進步了,就這個樣子。

查到的方式是,在網頁範本裡的 head 區加入定義好的 script。有人已經好心處理好了。

blogspot 的範本是在這裡開啟:



按下去之後就是:



在 </head> 之上插入以下的程式碼:

<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> 
存檔,然後寫個網誌來試試,像這樣:$$ \sum_a^b x^2 $$ $$ \sum_a^b x^2 $$

現在要顯示錢字號,就要包在 <span class="tex2jax_ignore">$</span> 裡面。有沒有更方便的方式,我暫時不知道。

參考:
http://tex.stackexchange.com/questions/13865/how-to-use-latex-on-blogspot

https://blogueun.wordpress.com/2014/01/04/escaping-in-mathjax/