To write math equations in my blog pages, I use Latex. Latex is a document preparation system which allows you to write professional-looking technical documents. For example, most of the scientific publications are written with Latex.
The line above is created by adding a code block below in my markdown file (source files of blog pages):
1 | $$ |
Dependencies
You need to install some dependencies to make your hexo project be able to render “LaTex code” correctly in markdown files. For the NexT theme (the theme I use), you can easily find the “math” block and update it to to below:
1 | math: |
Besides, you need to make sure you have installed hexo-renderer-kramed
:
1 | npm install hexo-renderer-kramed --save |
Syntax
Here I list some basic syntax rules, you can find the full document in LaTex Wikibooks.
Escaping block
There are two ways to include $\LaTeX$ code in markdown:
- use
$<latex expression>$
to insert $inline$ expression; - use
$$<latex expression>$$
to insert displayed expression:
Alignment
You can use &
to align different lines, and \\
to add a line break.1
2
3
4
5\begin {aligned}
A&=B \\
&=C \\
&=D
\end {aligned}
The rendered result is (note that I dismissed $$
):
Examples
Here are some math equations that we often use.
Case block
1 | sign(x)= |
Fraction
1 | \frac{1}{1+e^{-x}}\\ |
Matrix
1 | \begin{bmatrix} a & b \\ c & c \end{bmatrix} |