3

啊?Hexo NexT 主题支持 MathJax 如此简单?

 8 months ago
source link: http://blog.tubumu.com/2024/01/14/hexo-next-mathjax-configure/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

曾好几次尝试在 Hexo 中使用 hexo-mathhexo-renderer-markdown-it-plus 等包以支持 LaTeX 皆不成功,要么不行要么错乱。刚刚了解到如果使用 NexT 主题的话则不需要手工安装任何包。本文是一篇备忘录。

hexo: 7.0.0
hexo-theme-next: 7.8.0

一、配置 NexT 主题

修改 themes/next/_config.yml,将 mathjax 启用,即:

mathjax:
enable: false
mathjax:
enable: true

来个完整点的代码视图:

# Math Formulas Render Support
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

# hexo-renderer-markdown-it-plus (or hexo-renderer-markdown-it with markdown-it-katex plugin) required for full Katex support.
katex:
enable: true
# See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
copy_tex: false

对于我个人来说没必要将 pre_page 设为 false 使得每页都加载不必要的 script。

二、配置 Post

给需要数学公式的 Post 的 front-matter 添加 mathjax 配置 mathjax: true

比如本文的是:

---
title: 啊?Hexo NexT 主题支持 MathJax 如此简单?
date: 2024-01-14 01:35:17
categories:
- Memo
tags:
- Memo
mathjax: true
---

1. 贝叶斯公式:独立

$$ P(A | B) = \frac{P(B | A) \cdot P(A)}{P(B)} $$

P(A|B)=P(B|A)⋅P(A)P(B)

2. 贝叶斯公式:行内

这是文本行中的 $ P(A | B) = \frac{P(B | A) \cdot P(A)}{P(B)} $,也是可以的。

这是文本行中的 P(A|B)=P(B|A)⋅P(A)P(B),也是可以的。

3. 高斯函数:独立

$$ f(x) = \exp(-γx^2) $$

f(x)=exp⁡(−γx2)

4. 高斯函数:行内

这是文本行中的 $ f(x) = \exp(-γx^2) $,也是可以的。

这是文本行中的 f(x)=exp⁡(−γx2),也是可以的。

5. 欧拉公式:独立

$$ e^{i \theta} = \cos(\theta) + i \sin(\theta) $$

eiθ=cos⁡(θ)+isin⁡(θ)

6. 欧拉公式:行内

这是文本行中的 $ e^{i \theta} = \cos(\theta) + i \sin(\theta) $,也是可以的。

这是文本行中的 eiθ=cos⁡(θ)+isin⁡(θ),也是可以的。

7. 一元二次方程的解:独立

$$ \Delta = b^2 - 4ac $$
$$ x = \frac{{-b \pm \sqrt{{b^2 - 4ac}}}}{{2a}} $$

Δ=b2−4ac
x1,2=−b±b2−4ac2a

多了一行?

8. 一元二次方程的解:行内

这是文本行中的 $ x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2a} $,也是可以的。

这是文本行中的 x1,2=−b±b2−4ac2a,也是可以的。

很多是过期了的。

Hexo-NexT 文档:配置MathJax
Hexo博客支持数学公式
hexo渲染Latex公式(最简单方法)_仅参考
结合MathType和MathJax在Hexo博客中插入数学公式


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK