Skip to main content
v2026.11,986 entries · CC-BY 4.0

Big O Notation in LaTeX: Commands, Macro and Examples

How to typeset Big O in LaTeX with a plain or calligraphic O, a reusable macro, and the related Omega, Theta and little-o symbols.

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

  1. Write it inline. In math mode type $O(n \log n)$. The TeXblog tutorial also shows a variant written as $O(n\log{}n)$.
  2. Use the calligraphic O if your venue prefers it. Type $\mathcal{O}(n \log n)$. Overleaf lists \mathcal among the capital-letters-only math font styles, so it is intended for capitals such as O (Overleaf, Mathematical fonts, read 2026-11-12).
  3. Add the amsmath package in the preamble if you want to declare operators: \usepackage{amsmath}.
  4. 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.
  5. Do not redefine \O. LaTeX already uses \O for the letter Ø, so overwriting it with \renewcommand changes that symbol everywhere; choose a new name such as \bigO instead (this pitfall is raised in reader comments on the TeXblog tutorial, read 2026-11-12).
  6. Declare operators for terms like log. The standard \log is 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).
  7. Compile with your usual LaTeX engine and check the output.
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)

Related: lambda in LaTeX, superset symbols in LaTeX.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Big O Notation in LaTeX: Commands, Macro and Examples

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →