Skip to content

Base Syntax

TIP

LATEX is a professional typesetting system used for creating high-quality scientific documents, academic papers, books, and reports. It also handles complex mathematical formulas. This guide focuses on writing mathematical formulas.

Note

This site uses the MathJax rendering engine by default, so the following syntax is written according to MathJax. The Katex syntax is mostly similar to MathJax, with only a few differences. In case of errors, consult the official documentation of both.

LATEX offers two ways to write formulas: inline formulas, wrapped in a pair of $, and display formulas, wrapped in a pair of $$.

  • Inline Formula:

    Example of an inline formula: E=mc2, written as $E=mc^2$.

  • Display Formula:

    i=0ni2=(n2+n)(2n+1)6

    Written as:

    $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$

Greek Letters

DisplayInputDisplayInput
α A\alpha Aν N\nu N
β B\beta Bξ Ξ\xi \Xi
γ Γ\gamma \Gammao Oo O
δ Δ\delta \Deltaπ Π\pi \Pi
ϵ ε E\epsilon \varepsilon Eρ ϱ P\rho \varrho P
ζ Z\zeta Zσ Σ\sigma \Sigma
η H\eta Hτ T\tau T
θ ϑ Θ\theta \vartheta \Thetaυ Υ\upsilon \Upsilon
ι I\iota Iϕ φ Φ\phi \varphi \Phi
κ K\kappa Kχ X\chi X
λ Λ\lambda \Lambdaψ Ψ\psi \Psi
μ M\mu Mω Ω\omega \Omega

Superscripts and Subscripts

Use ^ for superscripts and _ for subscripts. For example, x_i^2: xi2, and \log_2 x: log2x.

By default, superscripts and subscripts only apply to the next character or group enclosed in {}. For example, 10^10 gives 1010, while 10^{10} gives 1010.

Curly braces can also help avoid ambiguity. For instance, x^5^6 would result in an error, so you need to use braces to clarify as in {x^5}^6$: x56, or x^{5^6}: x56.

Be mindful of the difference between

x_i^2: xi2 and x_{i^2}: xi2.

You can also use \sideset to have superscripts and subscripts on both sides of a symbol, such as \sideset{^1_2}{^3_4}\bigotimes: 4321.

Brackets

  • Parentheses and Square Brackets

    Use () and [] as they are. For example, (2+3)[4+4]: (2+3)[4+4].

  • Curly Braces

    Since curly braces {} are used for grouping, you need to use \{ and \} to display them. Alternatively, you can use \lbrace and \rbrace. For example, \{a*b\} or \lbrace a*b \rbrace will display as {ab}.

  • Angle Brackets

    Use \langle and \rangle to represent left and right angle brackets, respectively. For example, \langle x \rangle: x.

  • Ceil

    Use \lceil and \rceil for the ceiling function. For example, x.

  • Floor

    Use \lfloor and \rfloor for the floor function. For example, x.

Note

Original parentheses do not scale with formula size.

For example, (\frac12) renders as (12). You can use \left( ... \right) to automatically adjust the size of the parentheses. For example, \left( \frac12 \right) renders as (12).

It is clear that the parentheses in the second formula have been scaled.

Summation and Integration

Use \sum for the summation symbol. The upper and lower limits of the summation are specified by subscripts and superscripts. For example, \sum_1^n: 1n.

Use \int for the integral symbol, with limits represented similarly. For example, \int_1^\infty: 1.

Other similar symbols include \prod: , \bigcup: , \bigcap: , \iint: .

Fractions and Roots

There are two ways to write fractions:

  1. Use \frac ab, where \frac operates on the two groups a and b, yielding ab. If the numerator or denominator consists of more than one character, use {} for grouping.

  2. Use \over to split the expression into two parts, as in {a+1\over b+1}: a+1b+1.

Roots are written using \sqrt[a]b, where the value in square brackets represents the root index. If omitted, it represents a square root. For example, \sqrt[4]{\frac xy}: xy4, \sqrt{x^3}: x3.

Fonts

  • Use \it to display italics (the default font for formulas)

    \it{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathbb or \Bbb to display blackboard bold (blackboard font)

    \mathbb{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathbf or \bf to display bold

    \mathbf{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathtt or \tt to display typewriter font

    \mathtt{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathrm or \rm to display Roman font

    \mathrm{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathsf or \sf to display sans-serif

    \mathsf{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathcal or \cal to display calligraphic font

    \mathcal{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathscr or \scr to display script font

    \mathscr{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mathfrak or \frak to display Fraktur (old German) font

    \mathfrak{ABCDEFGHIJKLMnopqrstuvwxyz}

    ABCDEFGHIJKLMnopqrstuvwxyz

  • Use \mit to display italicized numbers

    \mit{1234567890}

    1234567890

Special Functions and Symbols

  • Relational Operators

    InputDisplayInputDisplayInputDisplayInputDisplay
    \pm±\mp\times×\div÷
    \mid\nmid\circ\bullet
    \cdot\ast\odot\bigodot
    \otimes\bigotimes\oplus\bigoplus
    \lt<\gt>\leq\geq
    \neq\approx\equiv\sim
    \simeq\cong\prec\lhd
    \sum\prod\coprod
  • Set Operators

    InputDisplayInputDisplayInputDisplayInputDisplay
    \emptyset\varnothing\in\notin
    \subset\supset\cup\cap
    \subseteq\supseteq\subsetneq\supsetneq
    \bigcup\bigcap\bigvee\bigwedge
    \uplus\biguplus\sqcup\bigsqcup
  • Logarithmic Operators

    InputDisplayInputDisplayInputDisplay
    \loglog\lglg\lnln
  • Trigonometric Operators

    InputDisplayInputDisplayInputDisplay
    \bot\angle30^\circ30
    \sinsin\coscos\tantan
    \cotcot\secsec\csccsc
  • Calculus Operators

    InputDisplayInputDisplayInputDisplay
    \prime\int\iint
    \iiint\iiiint\oint
    \limlim\infty\nabla
  • Logical Operators

    InputDisplayInputDisplayInputDisplayInputDisplay
    \because\therefore\forall\exists
    \not\lnot¬\vdash\vDash
    \land\lor\top\bot
  • Arrow Symbols

    InputDisplayInputDisplayInputDisplayInputDisplay
    \uparrow\downarrow\rightarrow(\to)\leftarrow
    \Uparrow\Downarrow\Rightarrow\Leftarrow
    \longrightarrow\longleftarrow\Longrightarrow\Longleftarrow
    \mapsto
  • Use {n+1 \choose 2k} or \binom{n+1}{2k} to denote combinations: (n+12k).

  • Use \pmod to indicate modular arithmetic, such as a\equiv b\pmod n: ab(modn).

  • Use \ldots and \cdots for ellipses. The difference between them is the position of the dots. ldots is slightly lower, as in a_1,a_2\ldots,a_n: a1,a2,an; cdots is centered, as in a_1+a_2+\cdots+a_n: a1+a2++an.

  • Use \overline and \underline to denote overlines and underlines, such as \overline{a+b+c+d}: a+b+c+d, and \underline{x+y+z}: x+y+z.

  • Other special characters include \star: , \aleph_0: 0, \partial: , \Im: , \Re: .

  • Some Greek letters have variant forms, such as \epsilon \varepsilon: ϵε, and \phi \varphi: ϕφ.

  • Note that some special characters can be escaped to their original meanings using \, such as \$ representing $, and \_ representing _.

Spaces

When writing formulas, no matter how many spaces are entered between "a" and "b", the output will always be "ab". To insert a small space between them, you can add \, between "a" and "b", as in a\,b: ab; \; increases the space more, as in a\;b: ab; \quad and \qquad create even larger spaces, such as a \quad b: ab, and a \qquad b: ab.

Top Symbols

For single characters, you can use \hat x: x^. For multiple characters, you can use \widehat {xy}: xy^.

Other similar symbols include \check x: xˇ, \breve x: x˘, \bar x: x¯, \overline {xyz}: xyz, \vec x: x, \overrightarrow x: x, \overleftrightarrow {xyz}: xyz, \dot x: x˙, and \ddot x: x¨.