Of all the small decisions that shape a formula, the two you reach for most are scripts (super- and subscripts) and spacing. Scripts take just two characters, ^ and _, yet a single pair of braces changes the result. Spacing is how you nudge the gaps that TeX inserts automatically, using commands like \,. This page covers the rules for both — and the reason behind each — keeping to facts that can be verified.
Superscripts and subscripts
In math mode ^ makes a superscript and _ makes a subscript. So x^2 sets a small 2 at the upper right of x, and a_n sets n at the lower right of a. These two characters have no special meaning in ordinary text, so scripts always go inside math mode — $ ... $, \[ ... \], and so on.
There is one rule to internalize: ^ and _ attach to only the single token that follows — a token being one character or one command. To raise or lower more than one character, you must **group them into a single unit with braces { }**.
$x^{10}$ % 10 全体が上付き:x の右肩に「10」
$x^10$ % 1 だけが上付き、0 は本行の大きさ:x¹0
$a_{ij}$ % ij をまとめて下付き
$2^{n+1}$ % n+1 全体が指数So x^{10} makes the whole “10” an exponent, whereas dropping the braces in x^10 raises only the “1,” leaving the “0” at full size on the baseline (it reads like x¹0). It is not an error and compiles silently, which makes it an easy trap. Get into the habit of bracing any script that is more than one character.
A single symbol can carry both a superscript and a subscript. Whether you write x_i^2 or x^2_i, LaTeX stacks them correctly regardless of order. Scripts can also be nested, but each level still needs braces: x^{y^z} makes z the exponent of y and the whole y^z the exponent of x. Omitting the braces — x^y^z — raises a “Double superscript” error and halts. The same goes for nested subscripts such as x_{i_0}.
To put scripts before a symbol — the left super/subscripts of isotope notation, say — use an **empty pair of braces {}** as an anchor. Writing {}_{Z}^{A}X lets the leading {} serve as an empty element for the scripts to attach to, placing A and Z at the upper and lower left of X.
The prime ′ of derivatives is written simply with an apostrophe '. f'(x) sets a prime at the upper right of f, and f''(x) sets two. It is shorthand for ^{\prime}, so f^{\prime} gives the same result. Because a prime is automatically a superscript, you do not add your own ^ — never write f^'.
\limits and \nolimits — script placement on big operators
On big operators — the sum \sum, integral \int, limit \lim, product \prod — a choice arises for the scripts you attach with ^ and _: they can sit above and below the symbol, or to its right. The scripts above and below a sum give its bounds, so this position is called the limits position.
The default depends on the math style. In display style, the scripts of \sum_{i=1}^{n} sit centered directly above and below the symbol. Inline (text style) — $\sum_{i=1}^{n}$ — the same scripts move to the right, set small, so they do not push the surrounding lines apart. Most operators, including \lim, behave this way.
\int is the exception: its definition has **\nolimits built in, so even in display style its scripts go to the right** (limits stacked above and below an integral look stretched out). Two commands override the default. \limits forces the scripts of the preceding operator above and below; \nolimits forces them to the right.
\[ \sum_{i=1}^{n} i % display:i=1 が下、n が上に中央配置\]
\[ \int_{0}^{1} f(x)\,dx % \int は既定で 0,1 を右側に\]
\[ \int\limits_{0}^{1} f(x)\,dx % 0,1 を上下に置く\]
$\displaystyle\sum_{i=1}^{n} i$ % 本文中でも上下配置を強制You can also switch the style itself. To get stacked limits inline, write $\displaystyle\sum_{i=1}^{n}$; to push them to the side in a display, prefix \textstyle. The difference: \limits / \nolimits target that one operator, whereas \displaystyle / \textstyle change the overall style of the math that follows.
Spacing in math, and the mu
In math mode TeX inserts spacing automatically according to what each symbol is (an operator, a relation, and so on). The gaps around the + in a+b, or around the = in a=b, are not something you typed. Still, the automatic spacing is sometimes too little or too much, and spacing commands let you adjust it by hand.
These widths are defined in mu (math units). One mu is 1/18 em, where the em is taken from the current math-symbol font (roughly the width of a capital M). Hence 1 em = 18 mu. Because it is a relative unit tied to the font size, the spaces grow in proportion when you enlarge the type. The main commands and their widths:
| Command | Width | Where to use it |
|---|---|---|
\, | 3 mu (thin space, = 1/6 em) | The most-used nudge: before dx, separating \sqrt{2}\,x, etc. |
\: | 4 mu (medium space) | A slightly wider gap (same as \medspace) |
\; | 5 mu (thick space) | A wider separation (same as \thickspace) |
\! | −3 mu (negative thin space) | Pulls things closer — the exact opposite of \, |
\quad | 18 mu (= 1 em) | A large gap, e.g. between a formula and its side condition |
\qquad | 36 mu (= 2 em) | Twice a \quad; an even larger gap |
The one you reach for most is the thin space \,. The classic case is the gap **between the integrand and dx**: \int f(x)\,dx sets f(x) slightly apart from dx for legibility (without \,, f(x)dx reads as one run). \quad and \qquad suit larger gaps, such as separating a formula from a side condition (“the formula (for n ≥ 1)”).
Its inverse, \!, is a negative space that pulls things together — used, for example, in a double integral \int\!\!\int to bring the two integral signs closer. Separately, a backslash followed by a space, \ (control space), inserts a normal interword space, the same width as in running text, even inside math.
\phantom and \mathstrut — aligning with invisible boxes
Typesetting often needs the adjustment “reserve the space but show nothing in it.” That is the job of the \phantom family. \phantom{...} makes an invisible, empty box with the same height, depth, and width as its argument set normally. Nothing prints, but exactly that much room is held open.
There are versions that take just one dimension. \hphantom{...} keeps only the width, with zero height and depth. \vphantom{...} is the opposite: only the height and depth, with zero width. So \vphantom is for “I want to claim the vertical extent but take up no horizontal room.”
For a concrete case, consider nested scripts whose heights disagree. Place the two summands below side by side and the right one carries a tall tower of exponents, 3^{3^{3^j}}; TeX drops the body of that sum to make room, so the two \sum signs no longer line up vertically. Putting \vphantom{3^{3^{3^j}}} in the left summand reserves the same height while staying invisible, and the two sums align.
\[
\sum_{j \in \{0,\ldots,10\} \vphantom{3^{3^{3^j}}}}
\sum_{i \in \{0,\ldots,3^{3^{3^j}}\}} i \cdot j
\]A close cousin, \mathstrut (“math strut”), is a dedicated invisible strut defined as \vphantom(. That is, it has the **height and depth of an open parenthesis (** and zero width. It takes no argument: just place it and it reserves one parenthesis’ worth of vertical room there. When you set items of differing height side by side — \sqrt{a} next to \sqrt{a^2} — putting a \mathstrut at the start of each argument levels the radical heights so the row looks even.
$\sqrt{\mathstrut a}\;\sqrt{\mathstrut a^2}\;\sqrt{\mathstrut b}$
% 各 \sqrt の中身が同じ高さになり、根号の天井がそろうIn short: **to match widths use \hphantom, to match heights use \vphantom or \mathstrut, and for both use \phantom**. All of them rest on the same idea — manipulating dimensions alone, through an invisible box.