Mathjax/Katex顯示測試

溯言|Rhett Caen Lv4

testing for mathjax, for katex. The reason that I tried to use katex instead of mathjax is related to the Next theme. If I tried to use next theme with markdown-it render, I should also use markdown-it-katex instead of the mathjax.

Latex中的數學表達式

The Gamma function satisfying $\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N$ is via the Euler integral

$$
x = {-b \pm \sqrt{b^2-4ac} \over 2a}.
$$

$$
\Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt,.
$$

1
$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$

${\sum_{i=0}^n i^2}$

$\theta^{n+1}=\theta^n-\eta\nabla C\left( \theta^n\right)$

如果是在字裡行間的話可以這樣$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$

簡單講把你要的東西用$ $包起來,就可以拉!

更多關於 LaTeX 數學表達式 ^5

手把手使用Katex做渲染的方式

以Next的主題爲例,如果要用Katex作為渲染,必須要將預先安裝的markdown渲染器hexo-renderer-marked改為hexo-renderer-markdown-it。[^3]

換好之後,再安裝markdown-it-katex[^4]

記得修改系統跟佈景主題中的_config.yml!(以下只列出需要修改的部分。)

themes/next/_config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Math Equations Render Support
math:
enable: true

#engine: mathjax
engine: katex

katex:
# Use 0.7.1 as default, jsdelivr as default CDN, works everywhere even in China
#cdn: //cdn.jsdelivr.net/npm/katex@0.7.1/dist/katex.min.css
# CDNJS, provided by cloudflare, maybe the best CDN, but not works in China
cdn: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css
# Bootcss, works great in China, but not so well in other region
#cdn: //cdn.bootcss.com/KaTeX/0.7.1/katex.min.css

_config.yml

1
2
3
markdown:
plugins:
- markdown-it-katex

Mathjax

這是舊版的支援方式,不選擇的使用原因是速度相對慢。下面的連結作為紀念用,表示以前有努力過。有興趣用Mathjax的人可以參考看看
您可以使用 MathJax 語法 來產生 LaTeX 數學表達式^1

有關使用MathJax在Hexo中可以參考必富客的網誌^2

[^3]: Chris 技術筆記-換Hexo的markdown渲染器

[^4]: Chris 技術筆記-hexo 加上數學式 MathJax; Hexo 博客支持 KaTeX(回爐版); Hexo 書寫 LaTeX 公式時的一些問題及解決方法

  • 標題: Mathjax/Katex顯示測試
  • 作者: 溯言|Rhett Caen
  • 撰寫於 : 2018-03-29 11:46:21
  • 更新於 : 2018-03-30 11:46:21
  • 連結: https://fractalrhythm.vercel.app/2018/03/29/hexo-test-math-katex/
  • 版權宣告: 本作品採用 CC BY-NC-SA 4.0 進行許可。