Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Short answer: in LaTeX math mode, type $O(n \log n)$ for a plain Big O, or $\mathcal{O}(n \log n)$ for the calligraphic form many papers use. Neither needs an extra package. This page is for researchers and analysts who write algorithm complexity into papers, theses and reports and want one reusable macro instead of retyping it.
What it is used for in research
Big O notation states an upper bound on how a quantity, usually running time or memory, grows with input size. Methods sections, algorithm descriptions and supplementary material use it to report complexity such as O(n log n). LaTeX has no dedicated Big O command, so you build the expression from the letter O, parentheses and math-mode operators. The related Bachmann-Landau symbols (Omega, Theta, little o, little omega) are typeset the same way. For the concept itself, see computational complexity.
Install or access (official source only)
The plain and calligraphic forms below need no extra package. The optional operator commands (\DeclareMathOperator) need amsmath, which CTAN describes as the principal package of the AMS-LaTeX distribution, maintained by the LaTeX Project Team, released under the LaTeX Project Public License 1.3c and part of the LaTeX required distribution (CTAN, ctan.org/pkg/amsmath, read 2026-11-12). Load it in the preamble with \usepackage{amsmath}. Overleaf’s documentation also loads amssymb in its calligraphic-font example, so adding it is a safe habit if a math font does not appear (Overleaf, Mathematical fonts, read 2026-11-12).
Step-by-step: typeset Big O and define a reusable macro
- Write it inline. In math mode type
$O(n \log n)$. The TeXblog tutorial also shows a variant written as$O(n\log{}n)$. - Use the calligraphic O if your venue prefers it. Type
$\mathcal{O}(n \log n)$. Overleaf lists\mathcalamong the capital-letters-only math font styles, so it is intended for capitals such as O (Overleaf, Mathematical fonts, read 2026-11-12). - Add the amsmath package in the preamble if you want to declare operators:
\usepackage{amsmath}. - Define a macro with a new name. Put this in the preamble:
\newcommand{\bigO}[1]{\mathcal{O}\left(#1\right)}. Then write$\bigO{n \log n}$in the text. Changing the definition in one place restyles every occurrence. - Do not redefine
\O. LaTeX already uses\Ofor the letter Ø, so overwriting it with\renewcommandchanges that symbol everywhere; choose a new name such as\bigOinstead (this pitfall is raised in reader comments on the TeXblog tutorial, read 2026-11-12). - Declare operators for terms like log. The standard
\logis already an operator. For a custom one use\DeclareMathOperator{\polylog}{polylog}; its first argument is the new command name and the second is the displayed text, and the starred form\DeclareMathOperator*places subscripts as limits (Overleaf, Operators, read 2026-11-12). - Compile with your usual LaTeX engine and check the output.
Related notations
| Notation | Source for the command | LaTeX |
|---|---|---|
| Big O | TeXblog; no package required | $O(n)$ or $\mathcal{O}(n)$ |
| Big Omega | TeXblog; Overleaf symbol list has \Omega |
$\Omega(n)$ |
| Big Theta | TeXblog; Overleaf symbol list has \Theta |
$\Theta(n)$ |
| Little o | TeXblog | $o(n)$ |
| Little omega | TeXblog; Overleaf symbol list has \omega |
$\omega(n)$ |
Sources: TeXblog, “Big-O and related notations in LaTeX” (2014, a personal blog, so treat it as a secondary reference); Overleaf, List of Greek letters and math symbols; both read 2026-11-12. The same conventions apply in the algorithm environments you may use to present the code being analysed.
Output and how to read it
The plain form prints an upright capital O followed by the argument in parentheses. The \mathcal form prints a script-style O. Both are set in math mode, so the argument follows math spacing rules. Pick one style and keep it for the whole document; mixing O and calligraphic O in a paper reads as two different symbols. If your macro uses \left( and \right), the parentheses grow with tall contents such as fractions. For other script letters see calligraphic letters in LaTeX.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Undefined control sequence on \bigO |
The \newcommand is missing or placed after \begin{document} |
Define it in the preamble before first use |
| A slashed O (Ø) appears | You typed or redefined \O |
Use O or \mathcal{O}, and name any macro \bigO |
Command \bigO already defined |
Another package or class uses that name | Pick a different macro name |
\DeclareMathOperator is undefined |
amsmath not loaded |
Add \usepackage{amsmath} to the preamble |
| Calligraphic O does not render | Used outside math mode | Wrap it in $ ... $ |
The error names above are the standard messages LaTeX produces for these conditions; the causes are editorial guidance from the commands documented above.
Free alternatives
| Option | What it gives you for this task | Source |
|---|---|---|
| Overleaf documentation | Reference pages for operators, math fonts and Greek symbols, with examples to copy | overleaf.com/learn/latex |
| A local LaTeX installation | amsmath is part of the LaTeX required distribution, so the optional operator commands are available without a separate download | ctan.org/pkg/amsmath |
FAQ
How do I write Big O in LaTeX?
Use $O(n \log n)$ in math mode. For the calligraphic variant use $\mathcal{O}(n \log n)$. No additional package is required for either (TeXblog, read 2026-11-12).
Is there a built-in Big O command?
No. Define your own, for example \newcommand{\bigO}[1]{\mathcal{O}\left(#1\right)}, and avoid the name \O, which LaTeX already uses for Ø.
How do I write Big Theta and Big Omega?
Use \Theta and \Omega in math mode, for example $\Theta(n^2)$.
Do I need amsmath?
Not for typing O or \mathcal{O}. You need it for \DeclareMathOperator (Overleaf, Operators).
Sources (official docs)
- CTAN, amsmath package page, ctan.org/pkg/amsmath, read 2026-11-12.
- Overleaf, Operators, overleaf.com/learn/latex/Operators, read 2026-11-12.
- Overleaf, Mathematical fonts, overleaf.com/learn/latex/Mathematical_fonts, read 2026-11-12.
- Overleaf, List of Greek letters and math symbols, overleaf.com/learn/latex/List_of_Greek_letters_and_math_symbols, read 2026-11-12.
- TeXblog, Big-O and related notations in LaTeX (secondary), texblog.org, read 2026-11-12.
Related: lambda in LaTeX, superset symbols in LaTeX.







