First post of blogs

Recently I am gonna migrate my blog to hexo, and I am gonna explore hexo with more intersting things, from the start, I may just use the default hexo theme – landscape.

Still, the first things I should do is to make Mathjax work compatibly with Hexo. Let’s take the equations below for an example.

G=argminGmax_D[E_xp_data(logD(x))+E_zp_zlog(1D(G(z)))] G^{*} = \arg \min_{G} \max\_{D} \left[ \mathbb{E}\_{x \sim p\_{data}} (\log D(x)) + \mathbb{E\_{z \sim p\_{z}}} \log( 1 - D(G(z))) \right]

The following steps are based on hexo-markdown-rendered render and mind I have changed it to hexo-renderer-markdown-it-plus, So it would be out of date.

Tips for using Mathjax in Hexo

Use hexo-math plugins for convenience.

Several Steps:

  1. npm install hexo-math --save to download it.

  2. No need hexo math install for hexo-math newer than 1.0.6.

  3. Specify the configuration in _config.yml using Mathjax

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# MathJax Support
math:
engine: 'mathjax'
mathjax:
src: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js
config:
# MathJax config
tex2jax:
inlineMath: [ ['$','$'], ["\\(","\\)"] ]
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
processEscapes: true
TeX:
equationNumbers:
autoNumber: "AMS"
extensions: ["tex2jax.js"]
jax: ["input/TeX", "output/HTML-CSS"]
  1. Make sure that every post that you want to use Mathjax with the header:
1
mathjax: true

And the whole things will be down! But we would discuss later about how to deal with
compatability between Mathjax and Markdown parser. Because you have to use \ to
convert _ or * to avoid parse the equation errorly.

Discuss Later

We will modify the marked.js file to escape from parsing some codes in equations, such as:

  • two _ in equations would be parsed as <em></em>
  • \{,\\,\} would not be parsed.

Let’s take the equations below as an example.

G=argminGmaxD{Expdata(logD(x))+Ezpzlog(1D(G(z)))} G^{*} = \arg \min_{G} \max_{D} \left\{ \mathbb{E}_{x \sim p_{data}} (\log D(x)) + \mathbb{E_{z \sim p_{z}}} \log( 1 - D(G(z))) \right\}

Most ways on web I searched have already out of date because hexo-render-marked has updated its regluar expression to parse em and escape. And I simply updated the ways below:

  • modify escape in inline to:
1
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]^_`|~])/, // \{ \} \\
  • modify em in inline to:
1
em: /^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*[?^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
  • modify br in inline to:
1
br: /^( {2,})\n(?!\s*$)/,

Use hexo clean to clean the cache and restart the server, things will be fine! 😃

Note:

  • the version of marked I tested is 0.7.0.
  • After the modification, some of the features may not be used:
    • \\ for a new line
    • double _ for italic (use double * instead).

Other Modification

With The clear theme landscape, I feel much better. Further modification would be adapted.

A bunch of features that I would need further:

  • [ ] Content index of each post.
  • [ ] Much fluently compatible with original LaTeX codes, so I can transfer between them easily.
  • [ ] Self-introduction item in the side bars.