这个博客的主题定位为数量金融、统计与R语言,但一直以来我都没写什么金融和统计的文章,估计很多看官都误以为我是程序猿。最初我列了个书单,计划有哪些书要读要翻译的,包括Implementing Models in Quantitative Finance 、Statistics and Data Analysis for Financial Engineering 和Option Pricing and Estimation of Financial Models with R 。除了没时间开始以外,还有个原因是折腾完octopress之后也没去折腾如何在octopress中插入公式。估计ruby的程序猿很少会用到数学公式吧,对LaTeX 的支持很有限,但是我等数学文艺青年的博客里怎能没有数学公式呢?
热心网友Sinosmond推荐使用kramdown以尽量减少往markdown中插入html代码,接着我发现此物非常强大,连LaTeX 都支持。昨晚使用了一下,现在把心得记录于此。
先安装kramdown包
再把下面的代码插入<head>和</head>标签中间,如果你使用octopress,那就是添加到/source/_includes/custom/head.html文件里:
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>
在markdown里插入下面的代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$$
\begin {align * }
& \phi ( x,y ) = \phi \left ( \sum _{i = 1 }^n x_ie_i, \sum _{j = 1 }^n y_je_j \right )
= \sum _{i = 1 }^n \sum _{j = 1 }^n x_i y_j \phi ( e_i, e_j ) = \\
& ( x_ 1 , \ldots , x_n ) \left ( \begin {array}{ccc}
\phi ( e_ 1 , e_ 1 ) & \cdots & \phi ( e_ 1 , e_n ) \\
\vdots & \ddots & \vdots \\
\phi ( e_n, e_ 1 ) & \cdots & \phi ( e_n, e_n )
\end {array} \right )
\left ( \begin {array}{c}
y_ 1 \\
\vdots \\
y_n
\end {array} \right )
\end {align * }
$$
就会得到:
1
段内插入LaTeX代码是这样的:$ \exp (- \frac {x^ 2 }{ 2 } ) $ ,试试看看吧
可以得到:
段内插入LaTeX代码是这样的:$\exp(-\frac{x^2}{2})$,试试看看吧
详细介绍请见 http://kramdown.rubyforge.org/syntax.html#math-blocks
需要注意的问题
使用kramdown时,对markdown的语法要求似乎比用rdiscount时要严格,一些在rdiscount中支持的写法,在使用kramdown不能的得到预期的效果。
例如下面的代码,在```html之前必须留一行的空行。
(url-jump.html) download
1
2
3
```html
<meta http-equiv= "refresh" content= "0; url=http://mydomain2.com" >
```
再比如_italic_,前后必须留空格,否则不能得到斜体的效果。
以##这样的形式标记的标题之后不能有空行… 这意味着我之前写过的文章还必须检查一遍。
其他功能
用kramdown可以生成脚注、表格,设置标题的id…大大弥补了markdown不足,详细信息请见http://kramdown.rubyforge.org/syntax.html
参考资料
http://steshaw.org/blog/2012/02/09/hello-mathjax/ 解决了右键点击公式网页消失的问题。