LaTeX Basics for Math Formulas: A Practical Primer
LaTeX is the standard way to write mathematics in plain text. Papers, theses, many wikis, note-taking apps and online forums use it, and once you know a few dozen commands you can type almost any formula you’ll meet in coursework or technical documents.
This primer covers the commands you’ll use most, with examples you can paste straight into an editor. A quick note on Imagte first: our formula to LaTeX page is a manual editor with a live KaTeX preview. You type LaTeX and see the rendered formula update as you go. It does not automatically recognize formulas from images; Tesseract, the OCR engine Imagte uses, reads text, not mathematical layout. So the skills below are exactly what you need to transcribe a formula from a photo or textbook yourself.
Inline and display math
LaTeX math lives between delimiters.
- Inline math sits inside a sentence:
$E = mc^2$or\(E = mc^2\). - Display math gets its own centered line:
$$E = mc^2$$or\[E = mc^2\].
In the Imagte editor you type the formula itself, without delimiters, and the preview renders it. When you paste it into a document, add the delimiters your destination expects.
Spaces you type in math mode are ignored. LaTeX decides the spacing between symbols itself.
Superscripts and subscripts
Use ^ for superscripts and _ for subscripts. If the script is more than one character, wrap it in braces.
x^2 \qquad x_i \qquad x_{i,j} \qquad e^{-x^2} \qquad a_{n+1}^{2}
A common mistake is writing e^-x^2, which puts only the minus sign in the exponent. Braces fix it: e^{-x^2}.
Fractions
\frac{numerator}{denominator} creates a stacked fraction.
\frac{1}{2} \qquad \frac{a+b}{c-d} \qquad \frac{\partial f}{\partial x}
Fractions can nest, but deep nesting gets hard to read. For inline use, a slash is often clearer: (a+b)/(c-d). Inside display math, \dfrac forces full size and \tfrac forces small size.
Roots
\sqrt{} gives a square root; an optional argument in square brackets sets the index.
\sqrt{2} \qquad \sqrt{x^2 + y^2} \qquad \sqrt[3]{27} \qquad \sqrt[n]{a}
Greek letters and common symbols
Greek letters are their names with a backslash. Lowercase and uppercase differ by the first letter.
\alpha \beta \gamma \delta \epsilon \theta \lambda \mu \pi \sigma \phi \omega
\Gamma \Delta \Theta \Lambda \Pi \Sigma \Phi \Omega
Some uppercase Greek letters look identical to Latin ones (Alpha is just A), so there is no \Alpha. Variant forms exist for a few letters: \varepsilon, \vartheta, \varphi.
A handful of operators and relations you’ll use constantly:
\times \cdot \pm \div \leq \geq \neq \approx \equiv \infty \to \in \subset \partial \nabla
Function names should be upright, not italic. Use the built-in commands so sin doesn’t render as the product s·i·n:
\sin x \quad \cos \theta \quad \log_2 n \quad \ln x \quad \lim_{x \to 0} \quad \max_{i} a_i
Brackets that grow
Plain parentheses stay one size. Prefix them with \left and \right to make them stretch around tall content.
\left( \frac{a}{b} \right)^2 \qquad \left[ 0, 1 \right] \qquad \left\{ x \mid x > 0 \right\}
Curly braces must be escaped as \{ and \} because bare braces group code in LaTeX. For absolute values, \lvert x \rvert or \left| x \right| both work.
Sums, products and integrals
Limits go in subscripts and superscripts.
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\prod_{k=1}^{n} k = n!
\int_{0}^{\infty} e^{-x}\,dx = 1
\iint_{D} f(x,y)\,dA \qquad \oint_{C} \mathbf{F} \cdot d\mathbf{r}
The \, adds a thin space before dx, which is the conventional look. In display math, sum and product limits appear above and below the symbol; inline, they sit to the side to save line height.
Matrices
The matrix family of environments arranges entries in rows and columns. Separate columns with & and end rows with \\. The prefix sets the brackets.
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\qquad
\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
\qquad
\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
pmatrixuses parentheses,bmatrixsquare brackets,vmatrixvertical bars (determinants), and plainmatrixno brackets.- For long matrices,
\cdots,\vdotsand\ddotsgive horizontal, vertical and diagonal dots.
Piecewise functions
The cases environment handles definitions by cases.
|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}
\text{} switches back to normal upright text so words like “if” don’t render as italic variables.
Aligning multi-line equations
To line up a derivation on its equals signs, use aligned inside display math. Put & just before the symbol you want to align and \\ at the end of each line.
\begin{aligned}
(a+b)^2 &= (a+b)(a+b) \\
&= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2
\end{aligned}
In a full LaTeX document with the amsmath package, the align environment does the same job at the top level and numbers each line; align* skips the numbers. KaTeX supports these environments too, but aligned is the most portable choice when you’re pasting into web tools, because it works anywhere display math works. The KaTeX project maintains a list of supported functions if a command doesn’t render.
Transcribing a formula from an image
Since automatic recognition isn’t available, here’s a reliable manual method:
- Open the image next to the formula to LaTeX editor.
- Identify the outermost structure first: is it an equation, a fraction, a sum? Type that skeleton, such as
\frac{}{}or\sum_{}^{}. - Fill in each part from the inside out, checking the preview after each piece.
- Compare the rendered preview with the original symbol by symbol, paying attention to subscripts versus superscripts and to which terms sit inside each fraction or root.
- Copy the finished LaTeX into your document.
If the surrounding page also has normal text, run that through the image to text tool and handle only the formulas by hand.
Common errors and what they mean
- Only the first character is raised or lowered: missing braces after
^or_. - “Undefined control sequence”: a typo in a command name, such as
\farcfor\frac. - Missing or extra brace: count
{and}; every opening brace needs a match. - Words look italic and squashed: wrap them in
\text{}. - Function names italic: use
\sin,\log,\liminstead of plain letters.
LaTeX formula checklist
- Multi-character scripts wrapped in braces.
- Fractions use
\frac{}{}with the right terms on top and bottom. - Function names use built-in commands.
- Tall content uses
\leftand\right. - Words inside formulas use
\text{}. - Multi-line derivations aligned with
&inaligned. - Preview compared with the original, symbol by symbol.
Most formulas you’ll ever write use only the commands on this page. Learn these, keep the preview open, and transcribing even a dense equation becomes a matter of minutes.
Try it: Formula to LaTeX — LaTeX editor with live preview. Automatic recognition is not offered yet.