(learn&think)

不浮躁,不自傲,学习,思考,总结

Octopress中使用Latex写数学公式

| Comments

Octopress 默认不支持 LaTex 写数学公式,这里修改 Octopress 使其支持。

测试

整段 LaTex 公式

1
2
3
4
5
6
7
$$
\begin{align}
\mbox{Union: } & A\cup B = \{x\mid x\in A \mbox{ or } x\in B\} \\
\mbox{Concatenation: } & A\circ B  = \{xy\mid x\in A \mbox{ and } y\in B\} \\
\mbox{Star: } & A^\star  = \{x_1x_2\ldots x_k \mid  k\geq 0 \mbox{ and each } x_i\in A\} \\
\end{align}
$$

内嵌 LaTex 公式

1
2
If $a^2=b$ and $b=2$, then the solution must be
either $a=+\sqrt{2}$ or $a=-\sqrt{2}$.

If $a^2=b$ and $b=2$, then the solution must be either $a=+\sqrt{2}$ or $a=-\sqrt{2}$.

设置

1.用 kramdown 代替 rdiscount

  • 安装
1
gem install kramdown
  • 修改_config.yml_config.yml中所有rdiscount替换成kramdown
1
2
3
4
5
6
7
8
9
10
11
12
13
--- a/_config.yml
+++ b/_config.yml
@@ -34,8 +34,8 @@ destination: public
 plugins: plugins
 code_dir: downloads/code
 category_dir: blog/categories
-markdown: rdiscount
-rdiscount:
+markdown: kramdown
+kramdown:
   extensions:
     - autolink
     - footnotes
  • Gemfile中把gem 'ridiscount'改成gem 'kramdown in Gemfile
1
2
3
4
5
6
7
8
9
10
11
12
diff --git a/Gemfile b/Gemfile
index cd8ce57..e1d8d30 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,7 +3,7 @@ source "https://rubygems.org"
 group :development do
   gem 'rake', '~> 0.9'
   gem 'jekyll', '~> 0.12'
-  gem 'rdiscount', '~> 2.0.7'
+  gem 'kramdown'
   gem 'pygments.rb', '~> 0.3.4'
   gem 'RedCloth', '~> 4.2.9'

2.添加 MathJax 配置在/source/_includes/custom/head.html文件里添加1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!-- mathjax config similar to math.stackexchange -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  jax: ["input/TeX", "output/HTML-CSS"],
  tex2jax: {
    inlineMath: [ ['$', '$'] ],
    displayMath: [ ['$$', '$$']],
    processEscapes: true,
    skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
  },
  messageStyle: "none",
  "HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] }
});
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"></script>

3.修复 MathJax 右击页面空白 bug2

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/sass/base/_theme.scss b/sass/base/_theme.scss
index c35136d..3ee3999 100644
--- a/sass/base/_theme.scss
+++ b/sass/base/_theme.scss
@@ -74,7 +74,7 @@ html {
   background: $page-bg image-url('line-tile.png') top left;
 }
 body {
-  > div {
+  > div#main {
     background: $sidebar-bg $noise-bg;
     border-bottom: 1px solid $page-border-bottom;
     > div {

更多信息

  1. http://www.idryman.org/blog/2012/03/10/writing-math-equations-on-octopress/

  2. http://luikore.github.com/2011/09/good-things-learned-from-octopress/

Comments