Hexo中添加MathJax
本文介绍怎么在Hexo中添加MathJax支持及MathJax示例
通过添加MathJax的js可以实现
如何添加
如果您使用的主题由jade文件构成,那么您需要在主题的
\layout\partial\scripts.jade
中添加如下代码12345678script(type='text/javascript', src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML', async)script(type='text/x-mathjax-config').MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) },tex2jax: { inlineMath: [ ["$", "$"], ["\\\(","\\)"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno",skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']},TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } },messageStyle: "none"});如果您使用的主题配置文件是ejs文件,那么您需要在
\layout\_partial\after-footer.ejs
中添加1234567<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) },tex2jax: { inlineMath: [ ["$", "$"], ["\\(","\\)"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno",skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']},TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } },messageStyle: "none"});</script>
MathJax示例
这是行内公式$E=mc^2$,下面是独立的公式
$$
\begin{aligned}
a=\sum_{i=1}^n i=\frac{n(1+n)}{2}
\end{aligned}
$$
防止marked解析markdown出错,我们还需要
请在Hexo的\node_modules\marked\lib\marked.js
中做如下修改1escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
改为1escape: /^\\([`*\[\]()# +\-.!_>])/,
另外,1em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
改为1em:/^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,