# Update

The original answer fails on some mathjax expressions. So don’t use it. Currently changing marked.js works for me. Just use the method below. It works for me.

First introduce mathjax into our blog. Create a new file called mathjax.ejs in themes/hueman/layout/plugin, and add the following contents in it.

Then add the following line before the end of the last div tag in themes/hueman/layout/layout.ejs

The whole layout.ejs file looks like this:

Open ./node_modules/marked/lib/marked.js in your blog’s root directory

Replace

with

The above step is used to avoid the escaping of \\, \{, \}. Then replace

with

to remove the conversion of _

Then run the following command to deploy your blog

It should work now.

But today I found a new problem. You cannot write two successive curly braces.

I guess it’s because hexo tries to takes curly braces as part of a tag. I don’t have enough time to figure out how to let hexo accept it as a math expression rather than a tag. Currently I will just add a space between two curly braces. Just like { {. It works great. If you have better idea how to deal with it, you can leave it in the comment below.

Hexo doesn’t support mathjax by default. To make it work, we need to introduce mathjax to our theme. Take my current theme hueman as an example.

Create a new file called mathjax.ejs in themes/hueman/layout/plugin, and add the following contents in it.

Then add the following line before the end of the last div tag in themes/hueman/layout/layout.ejs

The whole layout.ejs file looks like this:

Then mathjax would be introduced into our blog. Our work should be done. But unfortunately this is not the case, because the default markdown rendering engine would accidently render some of our mathjax code, which would of course disturb the rendering of mathjax later on. To solve this problem, we need to replace hexo’s rendering engine as pandoc. First install pandoc on your system. I’m using arch, so the command is

Then install hexo-render-pandoc. Run the following command in your blog’s root directory.

OK, everything is done. Write a blog containing any mathjax formula and run the following command to deploy it to your server.

Share