Gangmax Blog

Enable Hexo Mathematics Formula Rendering

From here.

To make Hexo be able to render the math formula written in TeX/LaTeX notation, we need to add the “hexo-filter-mathjax” plugin.

First, update the “pacakge.json” file by adding the following line in the “dependencies” section:

1
"hexo-filter-mathjax": "^0.9.0",

Then run “npm install” to install it.

Second, update the “_config.yaml” file to add the corresponding configuration:

1
2
3
4
5
6
7
8
9
mathjax:
tags: none # or 'ams' or 'all'
single_dollars: true # enable single dollar signs as in-line math delimiters
cjk_width: 0.9 # relative CJK char width
normal_width: 0.6 # relative normal (monospace) width
append_css: true # add CSS to pages rendered by MathJax
every_page: false # if true, every page will be rendered by MathJax regardless the `mathjax` setting in Front-matter
packages: # extra packages to load
extension_options: {}

The last step is to add the following “front-matter” line into the post which contains the math formula written in TeX/LaTeX notation:

1
mathjax: true

After that in the post you can write the formula like below:

1
2
# https://en.wikibooks.org/wiki/LaTeX/Mathematics
$x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$

The rendered result looks like:

Done.

Comments