LatexNotes

Text inside math mode in LaTeX

Text inside math mode is ordinary upright prose set within an equation; in LaTeX \text{...} produces it and requires the amsmath package.

LaTeX command

\text{for all } x

Not the symbol you meant? Draw it to find the command →

By default, letters in math mode are set in italic and multi-letter names are treated as products of single variables. To insert real words, wrap them in \text{...}, which sets them upright in the surrounding font and keeps any spaces you type. So \text{for all } x renders the words normally, with the trailing space preserved inside the braces.

For short upright fragments such as units or the differential d, \mathrm{...} gives an upright roman font. Use \mathrm{d}x for an upright differential or \mathrm{m/s} for units. Unlike \text, \mathrm does not preserve spaces and is intended for symbols rather than sentences.

For a named operator that should have proper spacing, like lcm or argmax, use \operatorname{...}. It sets the name upright and spaces it like \sin or \log, which \mathrm does not do. \text and \operatorname require amsmath; \mathrm is core LaTeX. All three are supported by KaTeX.

Other forms

\mathrm{d}xupright roman (units, d)
\operatorname{lcm}a named operator

Examples

$x > 0 \quad \text{for all } x \in S$

words set upright inside an equation

$5\,\mathrm{m/s}$

upright units with a thin space

$\operatorname{lcm}(a,b)$

a named operator with correct spacing

$f(x) = x \quad \text{if } x \geq 0$

a condition written as text

$\int f\,\mathrm{d}x$

an upright differential using \mathrm

Tips and common mistakes

Working from handwritten notes?

LatexNotes turns a photo or PDF of handwritten mathematics into clean, compilable LaTeX - graphs and all. Free to try, no sign-up.

Convert your maths to LaTeX →

FAQ

How do I put words inside an equation?

Wrap them in \text{...}, e.g. . Include a space inside the braces where you want one, since math mode ignores spaces outside \text. It needs amsmath.

How do I write upright units in math mode?

Use \mathrm, as in 5\,\mathrm{m/s}. The \mathrm keeps the units upright and the \, adds a thin space between the number and the unit.

How do I define a custom operator like argmax?

Use \operatorname{arg\,max}, or \operatorname*{argmax} if you want subscripts to sit underneath in display style. It spaces the name like a built-in operator, unlike \mathrm.

Why does my text look italic in an equation?

Math mode italicises letters and treats them as separate variables. Wrap real words in \text{...} to get upright prose with normal spacing.

See also