Octopress 默认不支持 LaTex 写数学公式需要更改配置才可以。
设置
需要使用kramdown来支持LaTex写数学公式
用kramdown替换rdiscount
安装kramdown
1
$ sudo gem install kramdown
修改
_config.yml配置文件,将所有rdiscount替换成kramdown- 修改
Gemfile,把gem 'rdiscount'换成gem 'kramdown'
添加MathJax配置
在/source/_includes/custom/head.html文件中,添加如下代码:
1 | <!-- mathjax config similar to math.stackexchange --> |
修复 MathJax 右击页面空白 bug
修改~/sass/base/theme.scss文件,如下代码变为:
1 | > div#main { |
随之出现的问题,以及解决方法
将rdiscount替换成kramdown之后,以前写的博客里面,很多内容都不能正确显示了,并且在rake generate时候,会报错,内容大约是:Error: Pygments can't parse unknown language: </p>
原生的语法高亮插件Pygments很强大,支持语言也很多,但是这时候报的错误让人一头雾水。
找出原因
报错部分代码在/plugins/pygments_code.rb文件中,
1 | def self.pygments(code, lang) |
修改一下代码,将出问题的代码高亮部分抛出来,
1 | raise "Pygments can't parse unknown language: #{lang}#{code}." |
Google了一下原因, 原来是因为最新版的pygments这个插件对于Markdown的书写要求更严格了:
- Some of my older blog posts did not contain a space between the triple-backtick characters and the name of the language being highlighted. Earlier versions of pygments did not care, but the current version is a stickler.
- pygments appears to want a blank line between any triple-backtick line and any other text in the blog post.
好吧,以后写文章要更细心一点了。:)
参考: