skip to content
Sergio's Blog CS

Math with KaTeX

/ 2 min read

Math with KaTeX

This blog supports mathematical notation using KaTeX. You can use LaTeX syntax to render math equations.

Inline Math

You can write inline math by wrapping your equation in single dollar signs $.

For example, $E = mc^2$ renders as E=mc2E = mc^2.

Block Math

For larger equations that should be displayed on their own line, use double dollar signs $$.

$$
\int_{0}^{\infty} x^2 e^{-x} \, dx = 2!
$$

Renders as:

0x2exdx=2!\int_{0}^{\infty} x^2 e^{-x} \, dx = 2!

Common Notations Reference

Here is a quick reference for the most commonly used mathematical notations.

Roots and Exponents

NotationLaTeX CodeResult
Square Root\sqrt{x}x\sqrt{x}
Complex Root\sqrt{x^2 + y^2}x2+y2\sqrt{x^2 + y^2}
N-th Root\sqrt[3]{x}x3\sqrt[3]{x}
Superscriptx^2x2x^2
Subscriptx_ixix_i

Trigonometry

NotationLaTeX CodeResult
Sine\sin(x)sin(x)\sin(x)
Cosine\cos(x)cos(x)\cos(x)
Tangent\tan(x)tan(x)\tan(x)
Theta\thetaθ\theta
Identity\sin^2(\theta) + \cos^2(\theta) = 1sin2(θ)+cos2(θ)=1\sin^2(\theta) + \cos^2(\theta) = 1

Logarithms and Calculus

NotationLaTeX CodeResult
Logarithm\log(x)log(x)\log(x)
Natural Log\ln(x)ln(x)\ln(x)
Limit\lim_{x \to \infty}limx\lim_{x \to \infty}
Integral\int_{a}^{b}ab\int_{a}^{b}

Operators and Logic

NotationLaTeX CodeResult
Plus/Minus\pm±\pm
Multiply\times or \cdot×\times or \cdot
Divide\div÷\div
Approx\approx\approx
Not Equal\neq\neq
Infinity\infty\infty
For All\forall\forall
Exists\exists\exists

Boolean Logic

NotationLaTeX CodeResult
AND\land\land
OR\lor\lor
NOT\neg¬\neg
Implies\implies    \implies
Equivalent\iff    \iff
XOR\oplus\oplus
True\top\top
False\bot\bot

Example:

$(P \land Q) \implies R$ \rightarrow (PQ)    R(P \land Q) \implies R

Functions

You can define functions using standard algebraic notation.

Simple Function:

$f(x) = \sin(x) + \cos(x)$ \rightarrow f(x)=sin(x)+cos(x)f(x) = \sin(x) + \cos(x)

Piecewise Function:

$$
f(x) = \begin{cases}
x^2 & \text{if } x > 0 \\
-x & \text{if } x \le 0
\end{cases}
$$
f(x)={x2if x>0xif x0f(x) = \begin{cases} x^2 & \text{if } x > 0 \\ -x & \text{if } x \le 0 \end{cases}

Derivatives

Express derivatives using prime notation or Leibniz notation.

Prime Notation:

$f'(x) = 2x + 1$ \rightarrow f(x)=2x+1f'(x) = 2x + 1

Leibniz Notation:

$\frac{dy}{dx} = 3x^2$ \rightarrow dydx=3x2\frac{dy}{dx} = 3x^2

Limit Definition:

$$
\frac{df}{dx} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}
$$
dfdx=limh0f(x+h)f(x)h\frac{df}{dx} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}

Polynomials

Polynomials are straightforward to write using superscripts ^ for exponents.

General Form:

$P(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0$ \rightarrow P(x)=anxn+an1xn1++a1x+a0P(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0

Cubic Polynomial:

$y = 4x^3 - 2x^2 + 7x - 5$ \rightarrow y=4x32x2+7x5y = 4x^3 - 2x^2 + 7x - 5

Roots (Quadratic Formula):

$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ \rightarrow x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Matrices

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

Enjoy writing math in your posts!