美文网首页Hexo
Hexo中的数学公式

Hexo中的数学公式

作者: 洗洗睡吧i | 来源:发表于2020-05-27 10:07 被阅读0次

    0. 官方文档

    Next 介绍了两种方案: mathjax / katex 。

    https://theme-next.js.org/docs/third-party-services/math-equations

    这里用的是 mathjax。

    1. mathjax配置

    1.1 正文 Front-matter

    ---
    title: Hexo中的数学公式
    date: 2020-04-25 01:46:39
    mathjax: true
    ---
    

    1.2 Next主题配置

    math:
      # Default (true) will load mathjax / katex script on demand.
      # That is it only render those page which has `mathjax: true` in Front-matter.
      # If you set it to false, it will load mathjax / katex srcipt EVERY PAGE.
      per_page: true
    
      # hexo-renderer-pandoc (or hexo-renderer-kramed) required for full MathJax support.
      mathjax:
        enable: true
        # See: https://mhchem.github.io/MathJax-mhchem/
        mhchem: false
    

    1.3 替换插件(貌似可以不换,默认的也能用)

    先卸载 hexo-renderer-marked, 再安装 hexo-renderer-pandoc

    npm un hexo-renderer-marked
    npm i hexo-renderer-pandoc
    

    2. 坑

    遇到了公式无法正常显示的问题。

    • 公式:
      RMSE = 1 - \dfrac{\sum_{i=1}^n (y_i - \hat{y}_i)^2} {\sum_{i=1}^n (y_i - \bar{y})^2}

    • Hexo显示如下(上面是错误的样子,下面是修改后的效果):

    hexo-math-error.png
    • 安装hexo-renderer-pandoc插件也无法解决;

    • 换 katex 方案也不行。


    最后发现是 \hat{y}_i 这里出了问题,原因不明。

    \hat{y}_i 下标符号 _ 前加了一个反斜杠 \ ,搞定。

    # 显示错误
    $RMSE = 1 - \dfrac{\sum_{i=1}^n (y_i - \hat{y}_i)^2} {\sum_{i=1}^n (y_i - \bar{y})^2}$
    
    # 修改后的公式
    $RMSE = 1 - \dfrac{\sum_{i=1}^n (y_i - \hat{y}\_i)^2} {\sum_{i=1}^n (y_i - \bar{y})^2}$
    

    相关文章

      网友评论

        本文标题:Hexo中的数学公式

        本文链接:https://www.haomeiwen.com/subject/orgiahtx.html