Latex is a great way to express mathematical expressions in a clear and readable way, just like what you see in textbooks. The setup is tedious, and the usage is even messier.
The following notes are what I usually use for writing posts. Hope it can help you master Latex without the need to go through all pains that I have experienced.
Installation
npm install hexo-math --save- In the folder that you need
MathJex, execute the commandhexo math install Add the following line in the
_config.ymlfile1plugins: hexo-mathIf you have multiple plugins, add
123plugins:- hexo-math- ...
Notice: if you work offline, the Latex won’t be rendered.
Usage of Latex code on Hexo
Inline
Only for very basic stuff, such as pure variables and formulas.
$a = b + c$ will be rendered as $a = b + c$.
Block
Render Latex code on a newline.
$$ velocity = \frac{distance}{time} $$ will be rendered as $$ velocity = \frac{distance}{time} $$
Rendering issue
Try this… $x_k = x_1 - [ ( a_1 + a2 + … + a{k - 1} ) - (k - 1) \times avg]$. It fails because of the markdown engine rendering priority issue.
So, instead of using $ ... $, use
The result will be very satisfying :)
$$\begin{aligned} x_k = x_1 - [ ( a_1 + a_2 + ... + a_{k - 1} ) - (k - 1) \times avg] \end{aligned}$$That’s why I mentioned basic stuff in the inline section. One hour wasted on this issue…
Latex code notes
Basics
Plain Text
Use \text{…} for plain text. You can use $$ within it.
\text{Hello World! $x^2 = y^3$} is $\text{Hello World! $x^2 = y^3$}$
Escape
Special characters used for MathJax interpreting can be escaped using the \ character
\$is $\$$\{is ${$\_is $_$
Spacing
This is a book becomes $This is a book$. So we need to specify the spacing by using:
\,for thin space\;for normal space
This\, is\; a\; book becomes $This\, is\; a\; book$
Superscripts and Subscripts
Use ^ for superscripts and _ for subscripts. e.g. x_i^2 is $x_i^2$
Notice: without {}, the ^ and _ only apply to the next character only.
Group
Superscripts, subscripts, and other operations apply only to the next “group” (use {} for grouping). For example, to represent 10 to the 10th power, you shouldn’t write…
10^10 $10^10$
You should write…
10^{10} $10^{10}$
Fraction
\frac abis $\frac ab$\frac{a+1}{b+1}is $\frac{a+1}{b+1}${a+1\over b+1}is ${a+1\over b+1}$
Special Letters and Symbols
Greek Letters
alpha \beta \delta \Delta \gamma \Gamma \omega \Omegais $\alpha \beta \delta \Delta \gamma \Gamma \omega \Omega$\epsilon \varepsilon \phi \varphiis $\epsilon \varepsilon \phi \varphi$
Special Symbol
\lt \gt \le \ge \neqis $\lt \gt \le \ge \neq$\times \div \pm \mp \cdotis $\times \div \pm \mp \cdot$\cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothingis $\cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing$\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapstois $\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto$\land \lor \lnot \forall \exists \top \bot \vdash \vDashis $\land \lor \lnot \forall \exists \top \bot \vdash \vDash$\star \ast \oplus \circ \bulletis $\star \ast \oplus \circ \bullet$\approx \sim \simeq \cong \equiv \prec \lhdis $\approx \sim \simeq \cong \equiv \prec \lhd$a\equiv b\pmod nis $a\equiv b\pmod n$\ldotsfor $a1, a2, \ldots, an$, and\cdotsfor $a1 + a2 + \cdots + an$\hat x \bar x \overline x \vec x \overrightarrow {xy}is $\hat x\; \bar x\; \overline x\; \vec x\; \overrightarrow {xy}$
Special Function: trigonometry, limit, sqrt, sum
- Trigonometry
\sin xis $\sin x$\cos xis $\cos x$\tan xis $\tan x$
- Limits
\lim_{x\to 0}is $\lim_{x \to 0}$
- Square root
\sqrt{\frac xy}is $\sqrt{\frac xy}$\sqrt[3]{\frac xy}is $\sqrt[3]{\frac xy}$
Summation
\sum_{i=0}^n i^2 = \frac{n(n+1)(2n+1)}{6}is $\sum_{i=0}^n i^2 = \frac{n(n+1)(2n+1)}{6}$For multiline subscripts
$$\sum_{\substack{ 0\le i\lt n\\ 0\le j\lt m} } i^2+j^3$$12345\sum_{\substack{0\le i\lt n\\0\le j\lt m}}i^2+j^3
Equations and Functions
System of Equations
|
|
Tagging Equations
|
|
P.S. & is the cell separator in tabulars and similar constructions. A single & means “go to the next cell of the alignment”, so && means “the next cell is empty, go to the following one”.
Check out here for notes on aligning.
Pairwise Functions
|
|
Matrix
Basic version.
|
|
Bracket matrix with exponent associated with it.
|
|
Two more kinds…
|
|
|
|