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 } xNot the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
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 operatorExamples
$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
\textneeds amsmath; include the space inside the braces, as in\text{for all }, because math mode drops spaces outside.- Use
\mathrmfor units and the upright differential d (\mathrm{d}x), not for whole sentences. - For a custom operator use
\operatorname{argmax}; it spaces the name correctly, whereas\mathrmdoes not. - Inside
\text, the surrounding text font is used and spaces are literal; outside it, math mode ignores your spaces. - Never write a multi-letter function name as bare letters; sin becomes s times i times n. Use
\sinor\operatorname.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
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.