$a b$ compiles identically to $ab$). To add horizontal space in math mode, use \, (thin, 3mu), \: (medium, 4mu), \; (thick, 5mu), \ (text word space), \quad (1em), \qquad (2em), or \! (-3mu negative thin space).
For paragraph indentation, line spacing, and vertical spacing in normal text, see Paragraph and line spacing.
Math spacing commands
TeX measures small math spaces inmu (math units), where 18mu equals 1em (one quad in the math symbol font). The table below compiles each command between vertical bars so you can compare the exact widths directly.
spacing.tex
Test this example live in your browser. Open a ready-to-compile LaTeX project with TeX Live 2026 preinstalled and zero local setup.Open starter article
Copy-ready summary of math spacing commands and their exact TeX definitions:
amsmath also defines \negmedspace (-4mu plus -2mu minus -4mu) and \negthickspace (-5mu plus -5mu). In current LaTeX (TeX Live 2026), \,, \!, \:, \;, \negmedspace, and \negthickspace are built into the LaTeX kernel and work in both math and text mode. For arbitrary widths, use \hspace{1cm} or \phantom{...} (which reserves the exact width of its argument without printing it).
Adding text inside math mode
Because math mode strips spaces and italicizes letters, wrap words or phrases inside an equation with\text{...} from amsmath. \text preserves normal spacing, matches the surrounding body font, and shrinks automatically inside subscripts and superscripts.
text-math.tex
\quad or \qquad around \text{...} to separate conditions from formulas cleanly, and keep any trailing or leading word spaces inside the braces of \text{for all }.
Built-in and custom math operators
Standard functions such as\sin, \cos, \tan, \log, \ln, \exp, \lim, \max, \min, \sup, \inf, \det, \gcd, and \Pr are predefined as math operators: LaTeX sets them upright and inserts automatic thin space between the operator and its argument (\sin x).
For operators that LaTeX does not predefine, amsmath provides two tools:
- One-off operator in the document body:
\operatorname{Var}(X)(subscripts/superscripts to the side) or\operatorname*{ess\,sup}_{x \in \Omega}(subscripts/superscripts above and below in display math). - Reusable operator command in the preamble:
\DeclareMathOperator{\Tr}{Tr}or\DeclareMathOperator*{\argmax}{arg\,max}.
operators.tex
Controlling limit placement (\limits and \nolimits)
Operators declared with * (such as \DeclareMathOperator*), along with \sum, \prod, and \lim, place subscripts and superscripts above and below in display math and to the side in inline math. Integrals (\int) place their limits to the side by default in both modes (unless you pass the intlimits option to amsmath).
To override the default on a single operator, place \limits (force above/below) or \nolimits (force to the side) directly after the operator and before _ or ^:
limits-placement.tex
Common mistakes
- Using
\DeclareMathOperatorinside\begin{document}:\DeclareMathOperatoris preamble-only and raises an error in the document body. Put it before\begin{document}, or use\operatornameinline. - Using
\mathrm{if x > 0}for prose:\mathrmswitches to upright math letters but still ignores spaces between words, producingifx > 0(the relation keeps its spacing, while the space afterifis lost). Use\text{if } x > 0instead. - Manually adding spaces around
+or=: TeX already inserts\medmuskiparound binary operators and\thickmuskiparound relations; adding\,or\:around them breaks standard math spacing. - Typing
sin xorargmaxwithout a command: Unmarked words render as products of italic variables (s,i,n,x) with no space before the argument.
Try it in the editor
LaTeX Cloud Studio runs TeX Live 2026 (full distribution), withamsmath and booktabs ready to use. Start from the Basic Article template in LaTeX Cloud Studio and replace main.tex with the complete spacing or operator example above.
