NexT provides two render engines for displaying Math Equations.

If you choose to use this feature, you don't need to manually import any JS or CSS. You just need to turn on `enable`

of `math`

and define a render engine in theme config file for it.

### Settings

# Math Formulas Render Support |

Don't forget to keep up double spaces indents!

`true`

→ turn on Math Equations render.→ totally disable Math Equations render.`false`

Only turning on `enable`

of `math`

cannot let you see the displayed equations correctly.

You need to install the corresponding Hexo Renderer to fully support the display of Math Equations.

The corresponding renderers per engine will be provided below.

This option is to control whether to render Math Equations every page.

→ Equations will be processed on demand. It will only render those posts which have`true`

`mathjax: true`

in their Front-matter.`false`

→ Equations will be processed on every page. Even if they not exists on one or another page.

**Examples with true option **

<!-- This post will render the Math Equations --> |

<!-- This post will NOT render the Math Equations --> |

<!-- This post will NOT render the Math Equations either --> |

### Render Engines

For now, NexT provides two Render Engines: MathJax and KaTeX.

**Render Choosing**

If you use MathJax to render Math Equations, you can choose one of renderers below:

- hexo-renderer-kramed
- hexo-renderer-pandoc

**Installation**

Need to uninstall the original renderer

`hexo-renderer-marked`

and install one of selected by you renderer:$ npm un hexo-renderer-marked --save

$ npm i hexo-renderer-kramed --save # or hexo-renderer-pandocIn theme config file, turn on

`enable`

option of`math`

and choose`mathjax`

as render engine.math:

enable: true

...

mathjax:

enable: trueRun standard Hexo generate, deploy process or start the server:

$ hexo clean && hexo g -d

# or hexo clean && hexo s

The KaTeX engine is a much faster math render engine compared to MathJax. And it could survive without JavaScript.

But, for now KaTeX support less things than MathJax. Here is a list of TeX functions supported by KaTeX.

**Render Choosing**

If you use KaTeX to render Math Equations, you can choose one of renderers below:

- hexo-renderer-markdown-it-plus
- hexo-renderer-markdown-it

If you use `hexo-renderer-markdown-it`

, you also need to add `markdown-it-katex`

as its plugin:

`$ npm i markdown-it-katex --save`

And then in site config file you need to add `markdown-it-katex`

as a plugin for `hexo-renderer-markdown-it`

:

# config of hexo-renderer-markdown-it |

**Installation**

Need to uninstall the original renderer

`hexo-renderer-marked`

and install one of selected by you renderer:$ npm un hexo-renderer-marked --save

$ npm i hexo-renderer-markdown-it-plus --save # or hexo-renderer-markdown-itIn theme config file, turn on

`enable`

option of`math`

and choose`katex`

as render engine.math:

enable: true

...

katex:

enable: trueRun standard Hexo generate, deploy process or start the server:

$ hexo clean && hexo g -d

# or hexo clean && hexo s

**Known Issues**

- Firstly, please check Common Issues of KaTeX.
- Displayed Math (i.e.
`$$...$$`

) needs to started with new clear line.

In other words: you must not have any characters (except of whitespaces)**before the opening**(comment #32).`$$`

and after the ending`$$`

- Don't support Unicode (comment #32).
- Inline Math (..
`$...$`

) must not have white spaces**after the opening**(comment #32).`$`

and before the ending`$`

- If you use math in Heading (i.e.
`## Heading`

).

Then in corresponding TOC item it will show the related LaTex code 3 times (comment #32). - If you use math in your post's title, it will not be rendered (comment #32).

We currently use KaTeX 0.7.1, some of those bugs might be caused by the outdated version of KaTeX we use.

But, as what is described in the beginning, the render of Math Equations relies on Hexo Renderer. Currently, KaTeX-related renderers only support KaTeX version until 0.7.1.

We will continuously monitor the updates of corresponding renderers, if there is a renderer which supports newer version of KaTeX, we will update the KaTeX we use.

### Plugins

NexT also integrates some plugins for MathJax and KaTeX. You can easily configure them by setting the CDN URLs.

`mhchem`

is a third-party extension for MathJax, it's a tool for writing beautiful chemical equations easily. More infomation: MathJax/mhchem Manual.

Copy-tex extension for KaTeX modifes the copy/paste behavior in any browser supporting the Clipboard API so that, when selecting and copying whole KaTeX-rendered elements, the text content of the resulting clipboard renders KaTeX elements as their LaTeX source surrounded by specified delimiters. More infomation: Copy-tex extension.

### Examples

For examples below (and for all other examples in this domain) NexT uses `hexo-renderer-kramed`

renderer with `mathjax`

engine.

In some cases, the syntax of Markdown and TeX will conflict. For example, an underscore (`_`

) may be interpreted as the start of italic text in Markdown, or subscripted mark in TeX. To avoid syntax errors, please use escape characters (`\_`

) instead.

#### Numbering and referring equations in MathJax

In the new version of NexT, we have added feature to automatic equation numbering with opportunity to make reference to that equations. We briefly describe how to use this feature below.

In general, to make the automatic equation numbering work, you have to wrap your LaTeX equations in `equation`

environment. Using the plain old style (i.e., wrap an equation with two dollar signs in each side) will not work. How to refer to an equation? Just give a `\label{}`

tag and then in your later text, use `\ref{}`

or `\eqref{}`

to refer it. Using `\eqref{}`

is preferred since if you use `\ref{}`

, there are no parentheses around the equation number. Below are some of the common scenarios for equation numbering.

#### Simple Equation

For simple equations, use the following form to give a tag,

$$\begin{equation} |

Then, you can refer to this equation in your text easily by using something like:

The famous matter-energy equation $\eqref{eq1}$ proposed by Einstein... |

The famous matter-energy equation $\eqref{eq1}$ proposed by Einstein...

#### Multi-line Equation

For multi-line equations, inside the `equation`

environment, you can use the `aligned`

environment to split it into multiple lines:

$$\begin{equation} |

Equation $\eqref{eq2}$ is a multi-line equation. |

Equation $\eqref{eq2}$ is a multi-line equation.

#### Multiple Aligned Equations

We can use `align`

environment to align multiple equations. Each of these equations will get its own numbers.

$$\begin{align} |

There are three aligned equations: equation $\eqref{eq3}$, equation $\eqref{eq4}$ and equation $\eqref{eq5}$. |

There are three aligned equations: equation $\eqref{eq3}$, equation $\eqref{eq4}$ and equation $\eqref{eq5}$.

Since `align`

in and of itself is a complete equation environment (read here about the difference between `aligned`

and `align`

in LaTeX). You do not need to wrap it with `equation`

environment.

#### Exclude equations from numbering

In the `align`

environment, if you do not want to number one or some equations, just use `\nonumber`

right behind these equations. Like the following:

$$\begin{align} |

#### Use `\tag`

to tag equations

Sometimes, you want to use more «exotic» style to refer your equation. You can use `\tag{}`

to achieve this. For example:

$$x+1\over\sqrt{1-x^2} \tag{i}\label{eq_tag}$$ |

Equation $\eqref{eq_tag}$ use `\tag{}` instead of automatic numbering. |

Equation $\eqref{eq_tag}$ use `\tag{}`

instead of automatic numbering.