在应用frame主题时,按照作者在文档中的提示,将mathjax_enable: false改为mathjax_enable: true后:

1
2
3
# mathjax setting
# note: need to install the hexo plugin for math: https://github.com/hexojs/hexo-math
mathjax_enable: true

发现作者提供的方法可以渲染如下所示的独立公式:
$$
E = mc^2
$$
但无法渲染$E = mc^2$这种通过 $$ 符号表示行内公式,在网上查找了一番后发现$$ 符号表示行内公式可能并表示标准的数学公式表达形式,无奈基本上所有markdown笔记基本上都是用$$ 符号表示行内公式的,在结合GPT的帮助后成功实现了渲染

  1. 到GitHub安装hexojs/hexo-math: A hexo plugin that uses MathJax to render math equations.,在命令行中输入以下指令,并将上文提到的themes\frame\文件夹下_config.ymlmathjax_enable: false改为mathjax_enable: true

    1
    npm i hexo-math --save
  2. themes\frame\layout文件夹下layout.ejs的内容改为以下内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <!DOCTYPE html>
    <html lang="<%= config.language %>">
    <head>
    <%- partial('partials/head') %>
    <script type="text/javascript" async
    src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML">
    </script>
    <script>
    window.MathJax = {
    tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']]
    }
    };
    </script>
    </head>
    <body>
    <div class="mask-border"></div>

    <div class="wrapper">
    <%- partial('partials/header') %>

    <div class="main">
    <div class="flex-container">
    <%- body %>
    </div>
    </div>

    <%- partial('partials/footer') %>
    </div>
    </body>
    </html>
  3. 重新编译部署hexo,可以发现公式渲染全部正常