The Problem of Subscript in Hexo with Mathjax
Problem
When writing equations with hexo, there are a lot of problems with its math engine. The specific problem that I came across is that the inline formula of
1 | $\{P_sa\}$ |
will not render correctly.
Test
LaTeX
The formula was rendered correctly on $\LaTeX$. So I did not make it wrong in the formula.
Mathjax
Then I thought the problem might be with mathjax
. However, when I tested the same formula directly written in html, it worked perfectly.
Hexo
When I checked the html page generated by hexo, I found out that the formula was rendered as:
1 | <p>$\{P<em>sa\}$......<\em> |
The problem is, markdown will use not only *asterisks*
for emphasis, but also _underscores_
. What an stupid interesting design!
Solution
In the file of node_modules/marked/lib/marked.js
:
1 | link: /^!?\[(inside)\]\(href\)/, |
Change the line
1 | em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, |
to
1 | em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, |
This will disable the effort of trying to match _
for the regular expression engine.
Now it works.