Difference between various methods for producing text in math mode
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 packageamstext
(oramsmath
) uses the current text font, but adapt the size according to the current math style. Therefore it needs\mathchoice
that has an efficiency impact that the text is set four times for all math styles and later, when TeX knows the math style, it chooses the right version.\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 packageamstext
(oramsmath
) is loaded.\textnormal
uses\normalfont
, the size is only adapted to the currrent math style if packageamstext
(oramsmath
) 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$}
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
.
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