Use MathJax in Jekyll

Two things need to be done.

info

This page is rendered by Docusaurus; however, the syntax is for Jekyll.

  1. Config inline mode, so we can use $$

    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    tex2jax: {
    inlineMath: [ ['$','$'], ["\\(","\\)"] ],
    processEscapes: true
    }
    });
    </script>
  2. Import MathJax: make sure use https

    <script type="text/javascript"
    src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
  3. Two ways to put the latex code

    1. User latex delimiters

      \\(...\\) or $ ... $ for inline and

      \\[...\\] or $$ ... $$ for block

    2. Put the code in {% raw %}{%{% endraw %} raw {% raw %}%}{% endraw %}{% raw %}{%{% endraw %} endraw {% raw %}%}{% endraw %}

      {% raw %}{%{% endraw %} raw {% raw %}%}{% endraw %}
      $$ put MathJax here $$
      {% raw %}{%{% endraw %} endraw {% raw %}%}{% endraw %}

Style Examples

  • Inline

    a2+b2=c2a^2 + b^2 = c^2 --> note that all equations between these tags will not need escaping!

    $a^2 + b^2 = c^2$ --> note that all equations between these tags will not need escaping!
  • Block

    • Correct way:

      some text before

      a2+b2=c2a^2 + b^2 = c^2

      some text after.

      some text before
      $$a^2 + b^2 = c^2$$
      some text after.
    • Wrong way 1:

      some text before a2+b2=c2a^2 + b^2 = c^2 some text after.

      some text before $$a^2 + b^2 = c^2$$ some text after.
    • Wrong way 2:

      some text before a2+b2=c2a^2 + b^2 = c^2 some text after.

      some text before
      $$a^2 + b^2 = c^2$$
      some text after.

Examples:

  • Special symbols

    1. {}\\\{\\\}

      $\\\{\\\}$
    2. \|\|

      $\|\|$
  • Indent (did not work with Docusaurus)

    1. Must contain 0:

      0____:104_0___:104__0__:104___0_:104____0:104}=5×104\left. \begin{array}{l} 0\quad \_\quad \_\quad \_\quad \_:&10^4\\ \_\quad 0\quad \_\quad \_\quad \_:&10^4\\ \_\quad \_\quad 0\quad \_\quad \_:&10^4\\ \_\quad \_\quad \_\quad 0\quad \_:&10^4\\ \_\quad \_\quad \_\quad \_\quad 0:&10^4 \end{array} \right\} =5\times10^4
      • How about 0001200012, it was counted three times.
      • 1059510^5 - 9^5: 959^5 is who does not contain 00.
    2. Must contain 0 and 1: 1059595+8510^5-9^5-9^5+8^5

    3. Must contain 0:

      0____:104_0___:104__0__:104___0_:104____0:104}=5×104\left. \begin{array}{l} 0\quad \_\quad \_\quad \_\quad \_:&10^4\\ \_\quad 0\quad \_\quad \_\quad \_:&10^4\\ \_\quad \_\quad 0\quad \_\quad \_:&10^4\\ \_\quad \_\quad \_\quad 0\quad \_:&10^4\\ \_\quad \_\quad \_\quad \_\quad 0:&10^4 \end{array} \right\} =5\times10^4
      • How about 0001200012, it was counted three times.
      • 1059510^5 - 9^5: 959^5 is who does not contain 00.
    4. Must contain 0 and 1: 1059595+8510^5-9^5-9^5+8^5