LaTeX Space in Equation: quad, Thin Space and Text
November 11, 2026 · 11 min read
LaTeX Space in Equations: quad, Thin Spaces, and Text in Math
Adding a LaTeX space in equation mode takes a command, because the space bar does nothing there. Use \, for a thin gap, \; for a thicker one, and \quad or \qquad for wide ones. For words, wrap them in \text{...} and put the spaces inside the braces. All of these work in KaTeX-based Markdown math.
Why LaTeX Ignores the Spaces You Type in Math Mode
TeX treats a formula as a row of symbols, not a sentence. It throws away the spaces you type and sets every gap itself, based on what each symbol is: a variable, an operator like +, a relation like =, or punctuation. The LaTeX2e reference manual gives the classic case: type y=m x and the m still lands right next to the x.
That's why a phrase typed straight into math collapses into one long italic word:
$$
f(x) = 0 if x is negative
$$
It renders like this:
Each letter becomes its own italic variable, so "if x is negative" turns into a run of products. The automatic spacing is right most of the time. You only step in for two jobs: changing a gap, and putting real words into a formula. If you need a refresher on the $ and $$ delimiters themselves, start with our Markdown equation guide.
How Do You Add a LaTeX Space in Equation Mode?
Pick a command from the spacing scale below. The four small LaTeX equation space commands also have long forms, which are easier to read in source files. The widths use the math unit mu, where 1 mu is 1/18 of an em, so every space grows and shrinks with the font size. These values come from the reference manual and the KaTeX support table.
| Command | Long form | Width | Typical use |
|---|---|---|---|
\! | \negthinspace | -3 mu | Pull two symbols closer |
\, | \thinspace | 3 mu | Before dx, between a number and a unit |
\: or \> | \medspace | 4 mu | A slightly wider gap, rarely needed |
\; | \thickspace | 5 mu | Around a separator inside set notation |
\ (backslash, space) | none | One normal word space | A short word gap inside a formula |
\quad | none | 1 em (18 mu) | Before a condition such as "for all x" |
\qquad | none | 2 em (36 mu) | Between two formulas on one line |
In a LaTeX document, the medium and thick spaces are flexible. The medium space can stretch or shrink, and the thick one can stretch, so treat 4 mu and 5 mu as nominal widths. KaTeX sets them at fixed widths.
The two spaces you'll use most are the thin space and the quad:
$$
\int_0^1 f(x)\,dx \qquad x^2 \ge 0 \quad \text{for all real } x
$$
In the output, the \, opens a small gap between f(x) and dx. The \qquad splits the two statements, and the \quad sets the condition apart from the inequality. Negative space fixes the opposite problem. The classic trick \int\!\!\int pulls two integral signs together, though \iint now does that for you.
Exact Widths and Invisible Space: hspace, mkern and phantom
Sometimes the scale doesn't have the width you need. Three commands cover the rest, and each one works in both LaTeX and KaTeX.
\hspace{1cm}inserts an exact width in any TeX unit, such ascm,ptorem.\mkern9mutakes math units, so it scales inside subscripts. The amsmath command\mspace{9mu}does the same in a LaTeX document, but KaTeX doesn't define\mspace.\phantom{...}reserves the width and height of its content without printing it.\hphantom{...}reserves only the width.
A phantom is handy for a fill-in blank on a worksheet:
$$
3 + \underline{\phantom{00}} = 10
$$
That gives you an underlined gap exactly two digits wide. Spacing between the cells of a matrix is a separate topic, covered in our Markdown matrix guide.
How Do You Write Text Inside an Equation? The text Command
Wrap the words in \text{...}. It comes from the amsmath package in LaTeX, and KaTeX has it built in. Inside the braces you're back in text mode, so spaces count again. It's the standard fix whenever LaTeX text in equation lines runs together.
The catch is that the space has to sit inside the braces. Compare these two:
$$
\text{for}x \qquad \text{ for } x
$$
The first prints "forx" because nothing separates the word from the variable. The second prints "for x" with a normal word space on each side. Writing \quad\text{for }x works too, and it's a common way to attach a condition.
Text in subscripts shrinks automatically. Write T_{\text{max}} for an upright "max" at subscript size. Plain T_{max} gives three italic variables multiplied together.
You can also drop math back inside the text with dollar signs, as in \text{if $x$ is even}. The amsmath user guide notes one more detail: \text uses the font of its surroundings, so inside an italic theorem it turns italic. Use \textnormal when the words must stay upright. \textrm won't do it, because it only switches the font family and keeps the italic shape.
text vs mathrm vs operatorname: Picking the Right Upright Style
Several commands print upright letters, and they aren't interchangeable. The difference shows up in spaces and in the gap around the word.
| Command | Keeps your spaces | Adds operator spacing | Use it for |
|---|---|---|---|
\text{...} | Yes | No | Words and short phrases |
\textnormal{...} | Yes | No | Words that must stay upright in italic surroundings |
\mathrm{...} | No | No | Single upright letters: the d in \mathrm{d}x, unit symbols |
\operatorname{...} | No | Yes | Function names with no built-in command, such as sgn or rank |
Try \mathrm{for all} and you'll get "forall", because \mathrm stays in math mode and drops the space. For function names, skip \text and use \operatorname{sgn}(x), which spaces the name like \sin or \log.
In a LaTeX document you can define the name once with \DeclareMathOperator{\sgn}{sgn} in the preamble. KaTeX doesn't support \DeclareMathOperator, so in Markdown math you write \operatorname each time. Check for a built-in first, because \max, \det, \ker and \gcd already exist.
Writing a Where Clause Under an Equation
To format a LaTeX equation where the variables need defining, add a "where" clause. There are three ways to write it, and the right one depends on how many definitions you have.
Pattern A, same line. For one short definition, keep it in the display with a quad and \text:
$$
E = mc^2, \quad \text{where } c \text{ is the speed of light}
$$
Notice the space after "where" and before "is" inside the braces. Without them, the words touch the c.
Pattern B, prose after the display. End the math block and carry on in a normal sentence:
$$
F = G\frac{m_1 m_2}{r^2}
$$
where $G$ is the gravitational constant, $m_1$ and $m_2$ are the masses, and $r$ is the distance between their centers.
We prefer pattern B whenever there's more than one variable. The sentence wraps on a phone screen, while a long display formula doesn't, and the variables stay inline where readers expect them.
Pattern C, between aligned rows. In a LaTeX document, \intertext drops a line of prose between the rows of an align environment and keeps the alignment. It has to come right after a \\. The mathtools package adds \shortintertext, which uses less vertical space. The star in align* below turns off the row numbers, which our LaTeX equation numbering guide covers.
\begin{align*}
F &= G\frac{m_1 m_2}{r^2} \\
\intertext{where}
r &= \text{the distance between the centers}
\end{align*}
KaTeX supports neither command, so in Markdown you fall back on pattern B.
Putting Text Under or Over Part of an Equation
When you need LaTeX text under equation symbols, such as a reason under an equals sign or a label under a run of terms, use a stacking command.
\underset{\text{factor}}{=}puts small text under a symbol, and\overset{\text{def}}{=}puts it above. Both come from amsmath.\stackrel{\text{def}}{=}is the older LaTeX command for text over a relation.\underbrace{...}_{\text{label}}draws a brace under a group with a label below it, and\overbrace{...}^{\text{label}}does the same on top.\substackstacks two lines of limits under a sum, as in\sum_{\substack{1 \le i \le n \\ i \text{ odd}}}.
$$
\underbrace{1 + 1 + \cdots + 1}_{n\ \text{terms}} = n
$$
That draws a brace under the row of ones with "n terms" written beneath it. The \ before \text keeps "n" and "terms" apart. Text on top of an arrow uses \xrightarrow{\text{...}}, which works the same way.
Which Spacing and Text Commands Work in Markdown Math?
Most Markdown editors render math with KaTeX or MathJax. KaTeX covers a subset of LaTeX, so some document-only commands fail. We ran every command in this post through KaTeX 0.16.33:
| Works in KaTeX | Fails in KaTeX | Use instead |
|---|---|---|
\, \: \> \; \! \quad \qquad | \mspace | \mkern or \hspace |
\thinspace \medspace \thickspace \enspace | \mbox | \text |
\hspace \kern \mkern \hskip \phantom | \intertext and \shortintertext | Prose between two $$ blocks |
\text \textnormal \mathrm \operatorname | \DeclareMathOperator | \operatorname |
\underset \overset \stackrel \underbrace \substack | \thinmuskip and friends | Individual spacing commands |
The \thinmuskip row is the real limitation. In a LaTeX document you can widen every automatic gap at once, but KaTeX gives you no global setting, so you adjust spacing one formula at a time.
Our editor renders math with KaTeX, using $ for inline math and $$ for display math. An unsupported command doesn't break the page. The preview prints that command's name in red instead. Edit the demo below and watch each gap change:
For single formulas you want to export as an image, the LaTeX equation editor runs in your browser with KaTeX 0.16, has a symbol palette, and exports PNG or SVG.
Getting each LaTeX space in equation blocks right comes down to two habits. Pick each gap from the scale instead of the space bar, and keep words inside \text with their spaces. Paste any of the $$ examples from this page into the editor and the preview renders it on the right as you type. When you're deciding whether a document needs full LaTeX at all, our Markdown vs LaTeX comparison walks through the tradeoffs.