解决GitHub Pages无法显示markdown数学公式的问题

Posted by tofucurd on June 28, 2022

如果你使用的是Jekyll(GitHub默认),那么可以在需要的markdown文档前面的YAML内添加mathjax:true

再在_config.yml中添加:

1
2
3
4
5
6
7
8
9
markdown: kramdown
kramdown:
  input: GFM                            # use Github Flavored Markdown !important
  syntax_highlighter_opts:
    span:
      line_numbers: false
    block:
      line_numbers: true
      start_line: 1

再在_include/下的mathjax_support.html(没有的话就加在head.html中,也有可能是其他名字,但只要意思是”head”就可以,但优先加mathjax...),添加:

1
2
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>

这样做应该可以解决。