# Difference between various methods for producing text in math mode

What is the difference between \text, \textrm, \textnormal, and \mbox (and possibly other commands commonly used to produce text in math mode)?

Various (La)TeX tutorials teach different methods, and I am sure that there is either a best one or there are subtly different usage scenarios.

-

Update: Example added without amstext to show the effect of this package on the other \text... commands.

Example file without package amstext (or amsmath):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tgpagella}

\newcommand*{\test}[1]{%
$\csname #1\endcsname{#1}^{\csname #1\endcsname{#1}}$%
}
\renewcommand*{\arraystretch}{1.5}

\begin{document}
\sffamily\bfseries\itshape Text mode: sans serif, bold, italics.

\bigskip
\begin{tabular}{@{}l@{}}
\test{mbox}\\
\test{textrm}\\
\test{textnormal}\\
\test{mathrm}
\end{tabular}

\end{document}

Example file with package amstext:

\documentclass{article}
\usepackage{amstext}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tgpagella}

\newcommand*{\test}[1]{%
$\csname #1\endcsname{#1}^{\csname #1\endcsname{#1}}$%
}
\renewcommand*{\arraystretch}{1.5}

\begin{document}
\sffamily\bfseries\itshape Text mode: sans serif, bold, italics.

\bigskip
\begin{tabular}{@{}l@{}}
\test{mbox}\\
\test{text}\\
\test{textrm}\\
\test{textnormal}\\
\test{mathrm}
\end{tabular}

\bigskip
$\textnormal{[a b c \"a \ss] becomes } \mathrm{[a b c \"a \ss]} \textnormal{ in mathrm}$

\end{document}

• \mbox uses the current text font. The size is constant and does not change in subscripts, superscripts, fractions, …

• \text of package amstext (or amsmath) uses the current text font, but adapt the size according to the current math style.

• \textrm uses the text roman font, but the other font parameters like encoding, shape and series are taken from the current text font. Font size is only adapted to the current math style if package amstext (or amsmath) is loaded.

• \textnormal uses \normalfont, the size is only adapted to the currrent math style if package amstext (or amsmath) is loaded.

• \mathrm uses the math roman font that might differ from the text roman font. Also the spacing is done according to math and the encoding differs from the text encoding.

For text in math I would load package amstext (or amsmath) and use \text or \textnormal. \text is shorter to type, but the dependency on the current text font might be sometimes an advantage, sometimes a disadvantage. For subscripts I would prefer \textnormal:

v_{\textnormal{car}} \ge v_{\textnormal{bicycle}}

But additional text might be better set in the current text font:

a \stackrel{\text{according to \dots}}{=} \frac{b}{c} \quad \text{for $c \ne 0$}
-
 The \text... commands behave properly in subscripts and superscripts provided amstext is loaded (usually via amsmath). – egreg Sep 8 '12 at 7:29 @egreg Thanks, I have updated the answer and added an example without amstext. – Heiko Oberdiek Sep 8 '12 at 7:42

I personally consider Herbert Voss' mathmode document one of the definitive guides to mathmode.

He covers the differences in Section 9, pg. 27

If you've installed TeX Live, you can access it on your machine using texdoc mathmode, in MiKTeX you will get it with texdoc voss-mathmode.

-
Actually \textrm doesn't force upright shape, it only sets the "roman family" attribute and leaves the others as they were (using those holding outside the formula, if it appears in math mode). So \textit{abc $\textrm{def}$} will print "def" in italics. – egreg Sep 8 '12 at 7:36

without using any package.

\documentclass{article}
\begin{document}

$Math - \mathrm{upright} - \textrm{upright} - \mbox{upright}$  \par\Large
$A^{\mathrm{text}}_{\mathrm{text}}$ \quad $A^{\textrm{text}}_{\textrm{text}}$\quad
$A^{\mbox{text}}_{\mbox{text}}$     \quad $A^{\textnormal{text}}_{\textnormal{text}}$

\end{document}

However, for text one should use amsmath and the \text command which uses the correct font size

-