Two flavours of maths
Inline maths sits inside a sentence, between $…$ or \(…\). Display maths gets its own centred line, between \[…\] or inside the equation environment. The notation is identical; the typesetting changes — display style is taller and fractions do not shrink.
It is worth being exact about what "the same source" means here, because the two flavours are not two dialects. Everything that exists inline also exists in a display, with one exception: a display is the only place an alignment or a number can live, so &, \\, \tag and a blank line mean something there that they do not mean between dollars. Every other difference is size and placement, decided by a single parameter called the style.
That style is inherited, not chosen. A display opens in displaystyle; an inline formula opens in textstyle; a sub- or superscript drops one step to scriptstyle and one more to scriptscriptstyle. Dropping a step shrinks the glyphs and tightens the clearances around fraction rules and operator bounds at the same time, which is why the same three characters can look correct in one place and unreadable in another. The full ladder is what most "make it bigger" requests are actually about, and it has its own section below.
This site renders its preview boxes in display mode, which is why a formula that looks perfect here can come out flatter once you paste it into a sentence in your own document.
The area is $A = \pi r^2$ and the volume is $V = \frac{4}{3}\pi r^3$.
\[
A = \pi r^2 \qquad \text{or} \qquad V = \tfrac{4}{3}\pi r^3
\]
Five ways to open a formula, and what each one buys
There are exactly two maths modes and two notations for each of them, so the choice is smaller than the syntax suggests. Inline is $…$ or, identically, \(…\), which is the shorthand for the math environment. Display is \[…\] or the displaymath environment, plus equation, which is a display that owns a counter. Numbered multi-line blocks belong to the alignment lesson; what matters here is that only one of these five choices adds a number, and a number is what makes a formula citable.
The $ form is older and shorter, and it is what every Markdown flavour, chat client and issue tracker that pretends to know LaTeX accepts. The \(…\) form exists for one specific failure: $ is also a currency sign, so a sentence like "the fee is $5 and the grant is $10, so net" silently turns "5 and the grant is " into italic variables and a cascade of errors. A stray $ is invisible to the eye and to grep in a way that an unbalanced \( is not, and it is the single most common cause of "my document was fine until page 3".
The one form to stop using is $$…$$. It is Plain TeX, not LaTeX, and it never enters LaTeX's display machinery: the vertical space comes from TeX's own registers instead of the ones your class set, so it disagrees with every other display on the page, and amsmath's numbering and \tag have no slot to attach to. Mixed forms are worse than either alone — a display opened with $$ and closed with \] is reported as Bad math environment delimiter, and the fix is to pick one family and stay in it.
Whichever you choose, choose it for the whole project. Mixed delimiters do not break compilation; they break search-and-replace, they break the automatic conversion tools you will eventually run over the source, and they make a reviewer wonder what else is inconsistent.
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\title{Every way to open a formula}
\author{A. Student}
\date{\today}
\begin{document}
\maketitle
\section{Two inline forms, one meaning}
The radius $r$ is positive, and so is \(r\). The two notations produce
identical output; the second one cannot be mistaken for a currency sign,
which is the only reason to prefer it.
\section{Three display forms, two different jobs}
An unnumbered display, as shorthand and as the environment that shorthand
expands to:
\[
\int_{0}^{1} x^{2} \, dx = \frac{1}{3},
\]
\begin{displaymath}
\int_{0}^{1} x^{2} \, dx = \frac{1}{3}.
\end{displaymath}
A numbered display is a different object, because it owns a counter and
therefore can be cited:
\begin{equation}
\label{eq:cube}
V = \frac{4}{3} \pi r^{3}.
\end{equation}
Equation~\eqref{eq:cube} exists only because line above used
\texttt{equation}; \verb|\[| has nothing to point at.
\section{The one form to stop using}
Plain \TeX's \texttt{\$\$\dots\$\$} still compiles in a LaTeX source, but it
never enters LaTeX's display machinery: it sets its own vertical gaps
instead of the ones the class configured, and it has no slot for a
number, so \texttt{\textbackslash tag\{\}} and the \texttt{amsmath}
error-recovery both fail inside it. Use \verb|\[| for unnumbered and
\texttt{equation} for numbered, and let the two do different jobs.
\end{document}
Spaces do not exist in math mode
Inside maths, LaTeX ignores the spaces you type: a+b and a + b come out identical, because spacing between operators is a typographic decision the engine makes for you. To force a gap use the spacing commands: \, thin, \: medium, \; thick, \quad and \qquad widest.
What TeX is actually doing is classifying every symbol into an atom — ordinary, relation, binary operator, punctuation, opening and closing fence — and then consulting a table of glue for each pair of adjacent classes. The relation = earns thick space on both sides; two ordinary symbols touching, like ab, earn none, because in maths juxtaposition means multiplication. That is the whole reason a b and ab look the same, and it is also the reason "spaces vanish" is a misleading complaint: the space bar is not being ignored, it simply is not the tool that controls the gap.
Because the space bar carries no weight, source layout inside maths is entirely free. You can break a long formula across lines in the file, indent it, or write it as one unwrapped line and the output is unaffected — a property that makes maths much easier to keep in version control than prose, and which is why this site can hand you a formula with real newlines in it and expect it to compile. The exceptions are the characters that end a line for other reasons: % still comments out the rest of the line, and a blank line is still a paragraph token, which maths does not know what to do with.
The measurement of each of those commands, the negative space \! and the cases where the automatic glue is too generous are the subject of the maths spacing lesson; the commands you need are \,, \;, \quad, \qquad and \!. The one to learn first is what happens when you type nothing at all and expect a gap.
a + b \qquad \text{(spaced apart)}
Words inside formulas: \text
Letters in math mode are variables, so they come out italic and squashed together: Profit renders as if it were the product of seven one-letter quantities. Real words go inside \text{…}, from amsmath, which re-enters text mode for its argument and sets it upright with normal inter-word spacing. \text also honours the spaces you type inside it, which is the practical difference between \text{a b} and \mathrm{ab}.
The reason to reach for \text rather than the older \mbox or a hand-rolled \mathrm is inheritance. \text asks the surrounding context two questions — what font is the running text here, and how big is the maths it sits in — and answers both. Put \text{cases} in a subscript and it shrinks with the subscript; put it in a caption, a footnote or a bold heading and it takes that face. \mbox takes the text font too but does not track the maths style, which is why it stays stubbornly full-size in a subscript and produces the loudest typography error in a formula. The trade-off is that \text is text: in a theorem environment, where the running prose is italic, \text{if} comes out italic. If you want the word upright regardless, ask for \textrm{…} or \textnormal{…}.
Labels that are not words want a different tool. A unit, a two-letter operator name or a roman subscripts tag is not prose: \mathrm{kg}, \mathrm{d} and x_{\mathrm{in}} keep the maths font family and are not affected by the surrounding italic, while \text{kg} silently inherits whatever the sentence is doing. Function names are a third case, and the spacing lesson owns them, because the interesting question there is not the font but the atom class — \operatorname{argmin} behaves like an operator around limits. The rule of thumb: if a copy editor would mark it as a word, use \text; if they would call it a symbol, use \mathrm.
Two mechanical consequences bite people. First, inside \text{…} you are back in text mode, so the characters that maths forgives are dangerous again: \text{50%} starts a comment and eats the rest of the line, and \text{t_max} raises Missing $ inserted. Write \text{50\%} and \text{t\_max}. Second, \text builds one unbreakable box, so a long clause inside an inline formula cannot end up at the end of a line — it overflows instead. Break the sentence around the maths rather than the maths around the sentence.
\text{Profit} = \text{Revenue} - \text{Cost}
x_{\text{max}} — the braces keep the whole word as one subscript, and \text reduces it to the right size for you.\text{\textit{provided }} x \ne 0 \qquad \operatorname{rank}(AB) \le \operatorname{rank}(A)
The one-token rule
A command like _ or ^ takes exactly one token after it unless you wrap the argument in braces. This single rule explains most mis-rendered formulas beginners produce.
A token is one control sequence or one character. So x^2 is x squared, x^\pi is x to the pi, and x_12 is x-sub-one followed by an ordinary 2 sitting on the baseline — which is exactly what makes the error so easy to ship and so hard to see in the source. Everything longer than one token needs braces, and the braces cost nothing when they are not needed: x^{2} and x^2 are the same document. The same rule runs through \frac{1}{x+1} (write \frac1{x+1} and the +1 has escaped the denominator), \sqrt[3]{x}, \text{…} and every macro you will define later.
Braces also decide where a style switch stops and where a maths list stops being ambiguous. \{\displaystyle …\} confines the enlargement to one box; unwrapped, it applies to the end of the current group, which inside an align row means "until the line ends". Two constructs are exceptions and people try to brace them anyway: \left is not a group but a sizing request that must be completed by a matching \right in the same maths list, so a bracket that opens inline and closes in a display fails; and \lim, \sum and friends take their bounds as sub- and superscripts, not as arguments, which is why \lim_{x \to 0} has braces and \sin x does not.
x_1 + x_2 \qquad v = \pi r^2 h
v = \pi r^2 h works because ^2 grabs only the 2; but x_12 would subscript only the 1. When in doubt, brace it.
Choosing inline or display, on purpose
The choice is not cosmetic. A displayed formula breaks the line, gets centred, gains vertical space above and below, and switches to the tall style: limits sit over and under \sum, fractions keep their full height. Inline maths does none of that — it must fit the line you are already in, so \sum puts its bounds to the side and \frac compresses.
So ask what the reader has to do with the expression. If the sentence reads straight through it — "for $0 < \delta < 1$ the bound holds" — it belongs inline, and forcing it onto its own line would strand a fragment of a sentence with nothing to say. If the reader has to come back to it, cite it, or compare the next line against it, display it and give it a number, because an unnumbered display cannot be referenced later.
There is a middle case people get wrong in both directions. A long derivation that you display without numbering is invisible to the rest of the document; a short ratio buried mid-paragraph costs the reader a re-read. And punctuation is part of the formula, not an afterthought: \[ x = 1, \] and $x = 1$. both end the sentence properly, while a display that swallows a comma the sentence still needs reads as a typo in the proof.
The cost side is worth naming too. A display is a two-line interruption: TeX must close the current line, lay out a box of its own, and resume. Stack three of them in a paragraph and you get a page of holes, which is a typesetting problem, not a maths one — the fix is to prose-ify two of the three ("where $a$ is the damping and $b$ the stiffness") and let one carry the weight. If a formula is short enough to be read as a phrase, inline is nearly always the better answer.
x = \frac{-b \pm \sqrt{b^{2} - 4ac}}{2a}, \qquad \text{so that } b^{2} \ge 4ac
\textstyle behaviour and gets it for free; if you find yourself typing \dfrac inside a sentence to rescue a height problem, that is the formula telling you it belongs on its own line.Four maths styles, and \displaystyle in a table cell
A size step in maths is not a font change — it is a switch to a different font and a different set of spacing rules. That is why \scriptstyle material looks squashed rather than merely small, and why \sum changes the position of its bounds as well as their height. The four styles are display, text, script and scriptscript, and every formula you write inherits one from its surroundings, so the interesting question is never "how do I make this bigger" but "which context is setting this size for me".
Style switches are declarations, not wrappers: \displaystyle, \textstyle, \scriptstyle and \scriptscriptstyle apply to the rest of the current group. Inside a display, {\textstyle \frac{1}{2}} gives you the inline rendering of that one ratio and stops there; written without the braces it quietly flattens the remainder of the line, which is how a stray \textstyle at the start of an align row makes half a derivation look wrong and the source look fine.
The context that surprises most people is a table. A tabular cell is text mode, so the maths in it is a fresh inline formula whatever the table is doing on the page: fractions come out compact and summation bounds sit at the side, and writing \[ inside a cell just gets you an error, because a display cannot start inside the box a cell lives in. The clean repair is the array package's column prefix — >{$\displaystyle}l<{$} — which opens a formula and the style you want around every cell in that column, so the intent is recorded once instead of in \dfrac on every row.
The other two places size is decided for you: inside cases, array and matrix cells, where amsmath typesets text style even inside a display, and inside a sub- or superscript, where you are always one step down. Enlarging those is a real decision with a real cost — taller boxes collide with the surrounding rows — and the fraction-level detail of it is on the fractions lesson; what belongs here is the diagnosis. Before you reach for \displaystyle, know that a table of stacked fractions also buys you a table of tall rows, and row spacing is a separate lever.
\int_{0}^{1} \frac{dx}{1+x^{2}} \qquad {\textstyle \int_{0}^{1} \frac{dx}{1+x^{2}}} \qquad {\scriptstyle \int_{0}^{1} \frac{dx}{1+x^{2}}}
\everymath{\displaystyle} in the preamble forces every inline formula on the page tall. It is a one-line way to wreck a document: the lines break unevenly, paragraphs open holes, and the displays stop looking special.\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{array} % gives you the >{\dots}<{\dots} column prefixes
\usepackage{booktabs}
\title{What style does a table cell get?}
\author{A. Student}
\date{\today}
\begin{document}
\maketitle
\section{A cell is text mode, so every formula in it is a fresh inline one}
Whatever the paragraph around the table was doing, a \verb|tabular| cell
starts over: \verb|$...|$ inside it is text style, which means a
two-storey fraction prints compact and a summation keeps its bounds to
the side.
\begin{center}
\begin{tabular}{ll}
\toprule
Source & What you get \\
\midrule
$\frac{n+1}{2}$ & compact rule, tight clearances \\
$\sum_{k=1}^{n} k$ & limits at the side, not above and below \\
\bottomrule
\end{tabular}
\end{center}
\section{One prefix per column, not one command per cell}
The \texttt{array} package lets a column carry its own opening and closing
material, so the whole column can be wrapped in \verb|\displaystyle|:
\begin{center}
\begin{tabular}{>{$\displaystyle}l<{$}l}
\toprule
Source & What you get \\
\midrule
\frac{n+1}{2} & full-height fraction, no \$ needed in the cell \\
\sum_{k=1}^{n} k & bounds stacked over and under the operator \\
\bottomrule
\end{tabular}
\end{center}
Recording the intent once per column is what keeps the rows you add next
month consistent with the rows you already shipped. Pay attention to the
price: stacked bounds make rows taller, and the row height and the rule
spacing belong to \verb|\arraystretch| and \texttt{booktabs}, not to the
formula.
\end{document}
What math mode will not do
Maths mode is a different parser, and everything that is not a symbol or a maths command either fails or means something else. A blank line inside $…$ starts a new paragraph inside the maths and produces LaTeX Error: Bad math environment delimiter or a stray-dollar cascade; \textbf{}, \emph{} and \underline{} throw errors because they belong to text mode; \vspace and \hspace are ignored inside the maths, which is why hand-spacing a formula never behaves.
The escape hatches are narrow on purpose. Words go through \text{…} (from amsmath), which re-enters text mode for its argument — so \text{\emph{if}} is legal even though bare \emph is not. Roman, non-italic labels that are not words — function names, unit abbreviations — want \mathrm{…} or a proper operator declaration instead, because \text{ } also inherits the surrounding font size and will change appearance between a caption and a display.
Vertical space around a display is controlled by the length registers \abovedisplayskip and \belowdisplayshortskip, or locally by \\[6pt] at the end of a row in an aligned block — never by stacking empty lines, which is the reflex that produces the paragraph error above. Learn the boundary once and half of your future error messages disappear: if it is not a maths object, it does not belong between the dollar signs.
Two border cases are worth knowing because they generate endless confused questions. Insertions do not belong inside the box that maths builds: a \footnote typed inside $…$ or inside a \text{} argument either vanishes or reports that it is not in outer par mode, and the conventional repair is to close the formula, place the footnote after the closing delimiter, and put the footnote mark where the reader expects it. And maths does not cross a \par: an inline formula left open across a paragraph break is not "continued", it is an error, because TeX closes the maths list at the paragraph token and reports the mismatch on a line you are not looking at.
Lesson cheat sheet
One key line of code from each section — jump to it or copy it straight from here.
The area is $A = \pi r^2$ and the volume is $V = \frac{4}{3}\pi r^3$.
\documentclass[11pt,a4paper]{article}
a + b \qquad \text{(spaced apart)}
\text{Profit} = \text{Revenue} - \text{Cost}
x_1 + x_2 \qquad v = \pi r^2 h
x = \frac{-b \pm \sqrt{b^{2} - 4ac}}{2a}, \qquad \text{so that } b^{2} \ge 4ac
Common mistakes
- Using a single
$on one side. Every$needs its pair; an odd number of them shifts the whole rest of the document into maths mode and produces baffling errors —! Missing $ inserted.will be reported many lines from the real cause, so count dollars per paragraph before you trust the line number. - Typing spaces and expecting them to appear. Use
\,…\qquad, or put the words in\text{}. - Writing multi-letter names bare:
maxin maths is m·a·x in italic. Wrap it:\text{max}or\mathrm{max}. - Forgetting the braces in
x^{10}—x^10prints x¹0, because^takes exactly one token. - Stacking two scripts:
x^2^3orx_1_2stops the run with! Double superscript script.(and! Double subscript script.). TeX will not guess whether you meantx^{2^3}orx^{2}3; write the braces and the ambiguity is gone — and if you meant a subscript and a superscript on the same symbol,x_1^2is already legal, so the error means you repeated a kind. - Reaching for a text command inside maths:
\textbf{vec a},\emph{if}or\underline{u}between dollar signs stops with! LaTeX Error: Command \textbf invalid in math mode.The maths equivalents are\mathbf{a},\text{\emph{if}}and\underline{u}, which is defined for maths — the ones that fail are the ones that change the font family or the paragraph shape. Text mode has its own boundary inside\text{…}:\text{50%}comments out the rest of the line and\text{t_max}reopens maths, so write\text{50\%}and\text{t\_max}.
Questions about this lesson
Should I use $...$ or \(...\) for inline maths in LaTeX?
Why should I not use $$...$$ for a display equation in LaTeX?
\abovedisplayskip family your class configured, which is why a $$ block sits at a different height from the \[ ... \] blocks around it; it also has no slot for a number, so \tag and amsmath's error recovery have nothing to attach to. Use \[ ... \] for an unnumbered display and equation for a numbered one. If you inherit an old source full of $$, replacing them is a mechanical and genuinely useful cleanup.Why does LaTeX ignore the spaces I type inside an equation?
\quad \qquad, or \! to tighten) or put real words in \text{}, which restores normal text spacing inside its argument.What does "Missing $ inserted" mean and how do I find the cause?
&, # or a blank line where a paragraph token landed inside a formula — and inserted an opening $ to cope, which is why the reported line is often several lines past the real problem. Read the message as a direction, not a verdict: if line 214 is reported, look back for an unescaped _ in a file name or a \textbf-like command between dollars, and check whether a previous display was left unclosed. The three commonest repairs are \_ for a literal underscore in text, \& for an ampersand, and closing the maths you opened.Why is my \text{} word italic inside a theorem, and different sizes in a caption?
\text inherits from the surrounding running text, not from the maths. In a theorem environment the body is italic, so \text{if} comes out italic; in a caption or a heading it takes that context's size and family. That inheritance is a feature where a word is genuinely part of the sentence and a nuisance where it is a label: force the upright roman shape with \textrm{} or \textnormal{}, or use \mathrm{} for a non-word such as a unit or a subscript tag, since \mathrm keeps the maths font family and never picks up surrounding italics.How do I make fractions or summation limits full size inside a LaTeX table?
\sum keeps its bounds to the side. Wrap the column instead of patching the cells — with the array package write >{$\displaystyle}l<{$} as the column specification, and each cell of that column is opened in display style, so \frac and \sum behave as they would in a display. Do it once per column rather than putting \dfrac in every row, and expect taller rows: that is the real cost, and it is adjusted with row spacing, not with the maths.Live playground: edit the LaTeX, see it render
The preview updates as you type — break it on purpose to see how errors look.
Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.