
More efficient than a long tutorial, MathJax / Tex equations examples.
Block mode | "Inline" mode | |
---|---|---|
Equation code writing | $$ Tex code $$
\[ Tex code \] |
$ Tex code $
## Tex code ##
\( Tex code \) |
Matrices
$$
\begin{pmatrix}
1 & 2 \\
3 & 4 \\
\end{pmatrix}
$$
$$
\begin{pmatrix}
1 & 2 \\
3 & 4 \\
\end{pmatrix}
$$
$$
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$
$$
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
\end{bmatrix}
$$
$$
\begin{Bmatrix}
1 & 2 \\
3 & 4 \\
\end{Bmatrix}
$$
$$
\begin{Bmatrix}
1 & 2 \\
3 & 4 \\
\end{Bmatrix}
$$
$$
\begin{vmatrix}
1 & 2 \\
3 & 4 \\
\end{vmatrix}
$$
$$
\begin{vmatrix}
1 & 2 \\
3 & 4 \\
\end{vmatrix}
$$
$$
\begin{Vmatrix}
1 & 2 \\
3 & 4 \\
\end{Vmatrix}
$$
$$
\begin{Vmatrix}
1 & 2 \\
3 & 4 \\
\end{Vmatrix}
$$
To omit entries :
$$
\begin{pmatrix}
1 & a_1 & \cdots & a_n \\
1 & b_1 & \cdots & b_n \\
\vdots & \vdots & \ddots & \vdots \\
1 & z_1 & \cdots & z_n \\
\end{pmatrix}
$$
$$
\begin{pmatrix}
1 & a_1 & \cdots & a_n \\
1 & b_1 & \cdots & b_n \\
\vdots & \vdots & \ddots & \vdots \\
1 & z_1 & \cdots & z_n \\
\end{pmatrix}
$$
To insert an horizontal separator : \hline
$$
\begin{vmatrix}
1 & 2 \\
\hline
3 & 4 \\
\end{vmatrix}
$$
$$
\begin{vmatrix}
1 & 2 \\
\hline
3 & 4 \\
\end{vmatrix}
$$
To insert a vertical separator : arrays
$$ \left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{array}
\right] $$
$$ \left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{array}
\right] $$
Inline matrices (smallmatrix) :
In matrice
$\bigl(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigr)$
, no numbers.
Fractions
dfrac (displaystyle) - Fractions that do not adjust to the line but to the overall style (opening, closing elements, etc.) :
$$
\begin{pmatrix}
\dfrac{1}{2} & 0 \\
0 & \dfrac{1}{2} \\
\end{pmatrix}
$$
$$
\begin{pmatrix}
\dfrac{1}{2} & 0 \\
0 & \dfrac{1}{2} \\
\end{pmatrix}
$$
cfrac - Continuous fractions :
$$
x = \cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+\dotsb}
}
}
$$
$$
x = \cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+\dotsb}
}
}
$$
Definitions by cases (piecewise functions)
$$ f(n) =
\begin{cases}
\dfrac{n+1}{2} &, \text{if $n$ is even} \\ \\
\dfrac{n}{2} &, \text{if $n$ is odd}
\end{cases}
\text{for all n} \in \mathbb N
$$
$$ f(n) =
\begin{cases}
\dfrac{n+1}{2} &, \text{if $n$ is even} \\ \\
\dfrac{n}{2} &, \text{if $n$ is odd}
\end{cases}
\text{for all n} \in \mathbb N
$$
Arrays
$$ \begin{array}{c|lcr}
n & \text{Left} & \text{Center} & \text{Right} \\
\hline
1 & 1 & 1 & 1 \\
2 & 10 & 100 & 10 \\
3 & 100 & 1000 & 100
\end{array} $$
$$
\begin{array}{c|lcr}
n & \text{Left} & \text{Center} & \text{Right} \\
\hline
1 & 1 & 1 & 1 \\
2 & 10 & 100 & 10 \\
3 & 100 & 1000 & 100
\end{array}
$$
Centering equations on the sign =
$$
\begin{align}
f(x) &= \frac{x+1}{x-2} \\
f'(x) &= \frac{(x-2) - (x+1)}{(x-2)^2} \\
&= - \frac{3}{x^2 - 4x + 4}
\end{align}
$$
$$
\begin{align}
f(x) &= \frac{x+1}{x-2} \\
f'(x) &= \frac{(x-2) - (x+1)}{(x-2)^2} \\
&= - \frac{3}{x^2 - 4x + 4}
\end{align}
$$
Equations systems :
$$ \left \{
\begin{align}
2x + y − 2z &= 3 \\
x − y − z &= 0 \\
x + y + 3z &= 12
\end{align}
\right.
$$
$$
\left \{
\begin{align}
2x + y − 2z &= 3 \\
x − y − z &= 0 \\
x + y + 3z &= 12
\end{align}
\right.
$$
Numbering equations (tag)
$$
\begin{align}
\cos 2\theta &= \cos^2 \theta - \sin^2 \theta \tag{2} \\
1 &= \cos^2 \theta + \sin^2 \theta \tag{3} \\
\end{align}
$$
$$
\begin{align}
\cos 2\theta &= \cos^2 \theta - \sin^2 \theta \tag{2} \\
1 &= \cos^2 \theta + \sin^2 \theta \tag{3} \\
\end{align}
$$
Tags and references (label, ref)
$$
\begin{align}
\cos 2x &= \cos^2x - \sin^2x \tag{4} \label{cos2x} \\
1 &= \cos^2x + \sin^2x \tag{5} \label{5} \\
\end{align}
$$
We deduce from the formulas \( \ref{cos2x} \) and \( \ref{5} \) :
$$
\begin{align}
\cos 2x &= \cos^2x + \sin^2x - \sin^2x - \sin^2x \\ \\
&= 1 - 2\sin^2x
\end{align}
$$
$$
\begin{align}
\cos 2x &= \cos^2x - \sin^2x \tag{4} \label{cos2x} \\
1 &= \cos^2x + \sin^2x \tag{5} \label{5} \\
\end{align}
$$
We deduce from the formulas $\ref{cos2x}$ and $\ref{5}$ :
$$
\begin{align}
\cos 2x &= \cos^2x + \sin^2x - \sin^2x - \sin^2x \\ \\
&= 1 - 2\sin^2x
\end{align}
$$
Highlighting equations (bbox)
$$ \bbox[8px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
$$ \bbox[8px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
$$ \bbox[#FFA,8px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
$$ \bbox[#FFA,8px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
CSS styles (class)
The syntax \bbox
to apply a style implies hard coded properties.
Using the syntax \class
, a stylesheet can be applied, easier for maintenance :
$$ \class{cmjx-highlight}
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
$$ \class{cmjx-highlight}
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
}
$$
.cmjx-highlight { border: 2px solid #DD4A68;
padding: 8px; margin-right: 4px; }
Another example which does not deal with highlighting equations :
$$
ax^2 + bx + c = 0 \\
x = \frac{-b \pm \sqrt{\Delta}}{2a} \class{cmjx-note} { \text{rem : } \Delta=b^2-4ac > 0 }
$$
$$
ax^2 + bx + c = 0 \\
x = \frac{-b \pm \sqrt{\Delta}}{2a}
\class{cmjx-note} { \text{rem : } \Delta=b^2-4ac > 0 }
$$
.cmjx-note {
transform: translate(100px);
font-size: 0.8em;
color: #DD4A68;
}
displaystyle, textstyle
Integral ##\int_{a}^{b} x^2 \,dx## inside text
Integral $ int_{a}^{b} x^2 \,dx $ inside text
Integral ##\displaystyle{ \int_{a}^{b} x^2 \,dx }## inside text using \displaystyle
Integral $ \displaystyle{ int_{a}^{b} x^2 \,dx } $ inside text
using \displaystyle
A sum inside block : $$ \sum_{n=1}^\infty \frac{1}{n^2} $$
$$ \sum_{n=1}^\infty \frac{1}{n^2} $$
A sum inside block in text mode using \textstyle : $$ \textstyle{ \sum_{n=1}^\infty \frac{1}{n^2} } $$
$$ \textstyle{ \sum_{n=1}^\infty \frac{1}{n^2} } $$