Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mathjax to support LaTeX math formula #268

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ about_intro_height: 50

首先备份 archer 下所有你自定义过的文件(包括 _config.yml 和 source 文件夹下添加的文件等),然后删除 archer,再重新安装,最后将备份的文件替换到原来的位置即可。

## 关于LaTeX支持

已经内置mathjax.js,但是需要替换默认的渲染引擎来支持解析LaTeX语法。
```bash
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
```

然后就可以配置每篇文章(即.md文件)的头部的`mathjax: true`字段来实现在本篇文章中启用LaTex公式支持。

## License

MIT
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ copyright:
enable: true
# https://creativecommons.org/
license: '本文采用<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">知识共享署名-非商业性使用 4.0 国际许可协议</a>进行许可'

# MathJax Support
mathjax:
enable: true
cdn: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML
29 changes: 29 additions & 0 deletions layout/mathjax.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% if (theme.mathjax.enable){ %>
<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="<%- theme.mathjax.cdn %>"></script>
<% } %>
3 changes: 3 additions & 0 deletions layout/post.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<main class="main post-page">
<% if (page.mathjax == true){ %>
<%- partial('mathjax') %>
<% } %>
<article class="article-entry">
<%- page.content %>
</article>
Expand Down