摘选自在Hugo中使用MathJax
本站在添加MathJax时,把所有修改写成了一个layouts/partials/mathjax.html文件:
<script type="text/javascript"
async
src="https://cdn.bootcss.com/mathjax/2.7.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
displayMath: [['$$','$$'], ['\[\[','\]\]']],
processEscapes: true,
processEnvironments: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
TeX: { equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js"] }
}
});
MathJax.Hub.Queue(function() {
// Fix <code> tags after MathJax finishes running. This is a
// hack to overcome a shortcoming of Markdown. Discussion at
// https://github.com/mojombo/jekyll/issues/199
var all = MathJax.Hub.getAllJax(), i;
for(i = 0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<style>
code.has-jax {
font: inherit;
font-size: 100%;
background: inherit;
border: inherit;
color: #515151;
}
</style>
这里,把官网的三处修改合并成一个partial。 此外,还把MathJax的CDN从cdnjs.cloudflare.com替换成了cdn.bootcss.com,更好地支持国内。 因为个人的一些写作习惯,还替换了区块公式的第二标志,从中括号[]换成双中括号。
把这个partial模板添加到中,即可正常工作。
{{ partial "mathjax.html" . }}
其他可能有用的:
使用Hugo生成支持数学公式渲染的静态站
MathJax Support
Hugo 静态博客中迄今为止最佳数学公式支持-利用 MathJax & MMark
另外typora需要在偏好设置里打开内联公式