使用Mathjax新增对数学公式的支持 (#88)

* 新增数学公式配置选项

* add

* add mathjax.ejs

* Update _config.yml

* Update mathjax.ejs

Co-authored-by: xaoxuu <16400144+xaoxuu@users.noreply.github.com>
This commit is contained in:
Heyya 2022-06-01 16:23:40 +08:00 committed by GitHub
parent 3d4800458b
commit e2b3b8901e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -84,7 +84,6 @@ article:
auto_cover: true # 如果没有封面就根据 tags 作为关键词搜索封面,开了此项将不会自动从文章中提取首张图片作为封面了。
######## Comments ########
comments:
service: # beaudar, utterances, valine, twikoo, waline
@ -303,6 +302,13 @@ plugins:
enable: false
css: https://unpkg.com/heti/umd/heti.min.css
js: https://unpkg.com/heti/umd/heti-addon.min.js
# MathJax
# 需在Markdown文件开头加入mathjax: true
# 推荐使用Pandoc: npm uninstall hexo-renderer-marked --save & npm install hexo-renderer-pandoc --save
mathjax:
enable: false
cdn: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML
style:

29
layout/mathjax.ejs Executable file
View File

@ -0,0 +1,29 @@
<% if (theme.plugins.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.plugins.mathjax.cdn %>"></script>
<% } %>

View File

@ -19,6 +19,9 @@ if (theme.plugins.heti && theme.plugins.heti.enable) {
heti = ' heti';
}
%>
<% if (page.mathjax == true){ %>
<%- partial('mathjax') %>
<% } %>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='content<%- heti %> md <%- post.layout %><%- post.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %>