Basic LaTeX for math

Basic LaTeX for math

latex for equations

Tools

2020.10.28

👣 #latex #md

In markdown notes, it’s easy to insert simple mathematical formulas with plain LaTeX\LaTeX. However, I’m always forget some basic characters for equations. So, let’s take a short review basic on the note LaTeX\LaTeX math for undergrads1. Note that the render engine is KaTeX\KaTeX on this web page.

Common constructs

plainLaTeX\LaTeX output
x^2x2x^2
x_{i, j}xi,jx_{i, j}
\sqrt{2}, \sqrt[n]{3}2,3n\sqrt{2}, \sqrt[n]{3}
frac{2}{3}, 2/323,2/3\frac{2}{3}, 2/3

Calligraphic letters

Use \mathcal{A}:

ABXYZ\mathcal{A} \mathcal{B} \mathcal{XYZ}

Greek

plainLaTeX\LaTeX outputplainLaTeX\LaTeX output
\alphaα\alpha\xi, \Xiξ,Ξ\xi, \Xi
\betaβ\betaooo
\gamma, \Gammaγ,Γ\gamma, \Gamma\pi, \Piπ,Π\pi, \Pi
\delta, \Deltaδ,Δ\delta, \Delta\varpiϖ\varpi
\epsilonϵ\epsilon\rhoρ\rho
\varepsilonε\varepsilon\varrhoϱ\varrho
\zetaζ\zeta\sigma, \Sigmaσ,Σ\sigma, \Sigma
\etaη\eta\varsigmaς\varsigma
\theta, \Thetaθ,Θ\theta, \Theta\tauτ\tau
\varthetaϑ\vartheta\upsilon, \Upsilonυ,Υ\upsilon, \Upsilon
\iotaι\iota\phi, \Phiϕ,Φ\phi, \Phi
\kappaκ\kappa\varphiφ\varphi
\lambda, \Lambdaλ,Λ\lambda, \Lambda\chiχ\chi
\muμ\mu\psi, \Psiψ,Ψ\psi, \Psi
\nuν\nu\omega, \Omegaω,Ω\omega, \Omega

Sets and logic

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
\cup\cup\mathbb{R}R\mathbb{R}\forall\forall
\cap\cap\mathbb{Z}Z\mathbb{Z}\exists\exists
\subset\subset\mathbb{Q}Q\mathbb{Q}\neg¬\neg
\subseteq\subseteq\mathbb{N}N\mathbb{N}\vee\vee
\supset\supset\mathbb{C}C\mathbb{C}\wedge\wedge
\supseteq\supseteq\varnothing\varnothing\vdash\vdash
\in\in\emptyset\emptyset\models\models
\ni\ni\aleph\aleph\Rightarrow\Rightarrow
\notin\notin\setminus\setminus\nRightarrow\nRightarrow
\not\in∉\not\in\equiv\equiv  

Negate an operator, as in ⊄\not\subset, with \not\subset. Get the set complement AcA^{\mathsf{c}} with A^{\mathsf{c}}, get AA^{\complement} with \A^{\complement}, or get Aˉ\bar{A} with \bar{A}.

Decorations

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
f'ff'\dot{a}a˙\dot{a}\tilde{x}x~\tilde{x}
f''ff''\ddot{a}a¨\ddot{a}\bar{x}xˉ\bar{x}
\Sigma^{*}Σ\Sigma^{*}\hat{x}x^\hat{x}\vec{x}x\vec{x}

If the decorated letter is ii or jj then some decorations need \imath or \jmath, as in vec{\imath}. If you need boldface for vectors: \boldsymbol{x}.

Entering \overline{x+y} produces x+y\overline{x+y}, and \widehat{x+y} gives x+y^\widehat{x+y}.

Dots

Use low dots in a list {0,1,2}\{0,1,2\,\ldots\}, entered as \{0,1,2\,\ldots\}. Use entered dots in a su or product 1++1001+\cdots+100, entered as 1+\cdots+100. You can also get vertical dots \vdots and diagonal dots \ddots.

Roman names

Enter \tan{x}, with a backslash, instead of tan{x}. These get the same treatment:

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
\sinsin\sin\sinhsinh\sinh\arcsinarcsin\arcsin
\coscos\cos\coshcosh\cosh\arccosarccos\arccos
\tantan\tan\tanhtanh\tanh\arctanarctan\arctan
\secsec\sec\cothcoth\coth\minmin\min
\csccsc\csc\detdet\det\maxmax\max
\cotcot\cot\dimdim\dim\infinf\inf
\expexp\exp\kerker\ker\supsup\sup
\loglog\log\degdeg\deg\liminflim inf\liminf
\lnln\ln\argarg\arg\limsuplim sup\limsup
\lglg\lg\gcdgcd\gcd\limlim\lim

Other symbols

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
<<<\angle\angle\cdot\cdot
\leq\leq\measuredangle\measuredangle\pm±\pm
>>>\ell\ell\mp\mp
\geq\geq\parallel\parallel\times×\times
\neq\neq45^{\circ}4545^{\circ}\div÷\div
\ll\ll\cong\cong\ast\ast
\gg\gg\ncong\ncong\mid\mid
\approx\approx\sim\sim\nmid\nmid
\asymp\asymp\simeq\simeqn!n!n!
\equiv\equiv\nsim\nsim\partial\partial
\prec\prec\oplus\oplus\nabla\nabla
\preceq\preceq\ominus\ominus\hbar\hbar
\succ\succ\odot\odot\circ\circ
\succeq\succeq\otimes\otimes\star\star
\propto\propto\oslash\oslash\surd\surd
\doteq\doteq\upharpoonright\upharpoonright\checkmark\checkmark

Variable-sized operators

The summation j=03j2\sum_{j=0}^3 j^2 using \sum_{j=0}^3 j^2 and the integral x=03x2dx\int_{x=0}^3 x^2\,dx with \int_{x=0}^3 x^2\,dx.

These do the same:

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
\int\int\iiint\iiint\bigcup\bigcup
\iint\iint\oint\oint\bigcap\bigcap

Arrows

plainLaTeX\LaTeXplainLaTeX\LaTeX
\rightarrow, \to,\rightarrow, \to\mapsto\mapsto
\nrightarrow\nrightarrow\longmapsto\longmapsto
\longrightarrow\longrightarrow\leftarrow\leftarrow
\Rightarrow\Rightarrow\leftrightarrow\leftrightarrow
\nRightarrow\nRightarrow\downarrow\downarrow
\Longrightarrow\Longrightarrow\uparrow\uparrow
\leadsto\leadsto\updownarrow\updownarrow

The right arrows in the first column have matching left arrows, such as \nleftarrow, and there are some other matches for down arrows, etc.

Fences

plainLaTeX\LaTeXplainLaTeX\LaTeXplainLaTeX\LaTeX
()()()\langle\rangle\langle \rangle| || |
[][][]\lfloor\rfloor\lfloor\rfloor\| \|| |
{}{}\lceil\rceil\lceil\rceil  

They will grow with the enclosed formula using \left and \right.

\left\langle i, 2^{2^i} \right\rangle
i,22i\left\langle i,2^{2^i} \right\rangle

Every \left must match a \right and they must end on the same line in the output. For a one-sided fence put a period \left. or \right. on the other side.

\left.\frac{df}{dx}\right|_{x_0}
dfdxx0\left.\frac{df}{dx}\right|_{x_0}

Fix the size with \big, \Big, \bigg, or \Bigg.

\Big[\sum_{k=0}^n e^{k^2}\Big]
[k=0nek2]\Big[\sum_{k=0}^n e^{k^2}\Big]

Array, matrices

Make an array of mathematical text as you make a table of plain text.

\begin{array}{rcl}
	0 &\leftrightarrow &0 \\
	1 &\leftrightarrow &1 \\
	2 &\leftrightarrow &4 \\
	\vdots &           &\vdots
\end{array}
001124\begin{array}{rcl} 0 &\leftrightarrow &0 \\ 1 &\leftrightarrow &1 \\ 2 &\leftrightarrow &4 \\ \vdots & &\vdots \end{array}

Definition by cases is an array with two columns.

f_n=
\begin{cases}
    a   &\text{if \(n=0\)} \\
    r\cdot f_{n-1}  &\text{else}
\end{cases}
fn={aif n=0rfn1elsef_n= \begin{cases} a &\text{if \(n=0\)} \\ r\cdot f_{n-1} &\text{else} \end{cases}

A matrix is another array variant. With this abbreviation you need not specify column alignments.

\begin{pmatrix}
    a   &b \\
    c   &d
\end{pmatrix}
(abcd)\begin{pmatrix} a &b \\ c &d \end{pmatrix}

For the determinant use |A| inline and vmatrix in display.

Spacing in mathematics

plainLaTeX\LaTeXplainLaTeX\LaTeX
\rightarrow\,\leftarrow\rightarrow\,\leftarrow\rightarrow\quad\leftarrow\rightarrow\quad\leftarrow
\rightarrow\:\leftarrow\rightarrow\:\leftarrow\rightarrow\qquad\leftarrow\rightarrow\qquad\leftarrow
\rightarrow\;\leftarrow  \rightarrow\;\leftarrow\rightarrow\!\leftarrow ⁣\rightarrow\!\leftarrow

The left column spaces are in ratio 3:4:53:4:5. The last in the right column is a negative space, opposite to \,. Get arbitrary spaces as in \hspace{0.5cm}.

Calculus examples

f\colon\mathbb{R}\to\mathbb{R}
f ⁣:RRf\colon\mathbb{R}\to\mathbb{R}
9.8~\text{m}/\text{s}^2
9.8 m/s29.8~\text{m}/\text{s}^2
\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
limh0f(x+h)f(x)h\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
int x^2\,dx=x^3/3+C
x2dx=x3/3+C\int x^2\,dx=x^3/3+C
\nabla=\boldsymbol{i}\frac{d}{dx}+\boldsymbol{j}\frac{d}{dy}+\boldsymbol{k}\frac{d}{dz}
=iddx+jddy+kddz\nabla=\boldsymbol{i}\frac{d}{dx}+\boldsymbol{j}\frac{d}{dy}+\boldsymbol{k}\frac{d}{dz}

Discrete mathematics examples

There are four modulo forms: mmodnm\bmod n is from m\bmod n, and ab(modm)a\equiv b\pmod m is from a\equiv b\pmod m, and abmodma\equiv b\mod m is from a\equiv b\mod m, and ab(m)a\equiv b\pod m is from a\equiv b\pod m.

For combinations the binomial symbol (nk)\binom{n}{k} is from \binom{n}{k}. This resizes to be bigger in a display.

For permutations use nrn^{\underline{r}} from n^{\underline{r}}.

Statistics examples

\sigma^2=\sqrt{\sum (x_i-\mu)^2/N}
σ2=(xiμ)2/N\sigma^2=\sqrt{\sum (x_i-\mu)^2/N}
E(x)=\mu_X=\sum (x_i-P(x_i))
E(x)=μX=(xiP(xi))E(x)=\mu_X=\sum (x_i-P(x_i))

The probability density of the normal distribution 12σ2πe(xμ)22σ2\frac{1}{\sqrt{2\sigma^2\pi}}\,e^{-\frac{(x-\mu)^2}{2\sigma^2}} comes from this:

\frac{1}{\sqrt{2\sigma^2\pi}}\,e^{-\frac{(x-\mu)^2}{2\sigma^2}}

For more

See more comprehensive LaTeX\LaTeX symbols list at http://mirror.ctan.org/info/symbols/comprehensive.

  1. Jim Hefferon, Saint Michael’s College, VT USA 2017-Jan-10 

THE END
Ads by Google

林宏

Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.

YOU MAY ALSO LIKE

Using Liquid in Jekyll - Live with Demos

Web Notes

2016.08.20

Using Liquid in Jekyll - Live with Demos

Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.

Setup an IKEv2 server with strongSwan

Tutorials

2020.01.09

Setup an IKEv2 server with strongSwan

IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunnelling between networks. It is developed by Microsoft and Cisco (primarily) for mobile users, and introduced as an updated version of IKEv1 in 2005. The IKEv2 MOBIKE (Mobility and Multihoming) protocol allows the client to main secure connection despite network switches, such as when leaving a WiFi area for a mobile data area. IKEv2 works on most platforms, and natively supported on some platforms (OS X 10.11+, iOS 9.1+, and Windows 10) with no additional applications necessary.