Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 34 down vote accepted

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}

Differences without amstext

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}

Differences with amstext

  • \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. 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 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$}
share|improve this answer
    
In my \text can be noticeably slower than \hbox/\mbox. Is this so? Of course, when proper scaling is needed, choosing \text might simply be necessary. –  Lover of Structure Jun 7 '13 at 21:45
    
@LoverofStructure: Yes, thanks, there is an efficiency impact, because \text needs the service of \mathchoice to get the right math style. I have updated the answer. –  Heiko Oberdiek Jun 7 '13 at 22:00
    
You wrote that \textrm and \textnormal will produce correctly sized text in math mode if amstext or amsmath is loaded. Which other font commands (\textit, \textsf, \texttt, \emph, ...) will have been size-corrected as well? –  Lover of Structure Jul 4 '13 at 11:49
1  
@LoverofStructure: Package amstext contains \let\nfss@text\text. Thus all commands that use \nfss@text work with correctly sized text in math, e.g. all commands defined via \DeclareTextFontCommand. –  Heiko Oberdiek Jul 4 '13 at 12:56
1  
And in latex.ltx the following commands are defined using \DeclareTextFontCommand: \textrm, \textsf, \texttt, \textnormal, \textbf, \textmd, \textit, \textsl, \textsc, \textup, \emph –  Lover of Structure Dec 26 '13 at 18:46

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

He covers the differences in Section 9, pg. 27

enter image description here

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.

share|improve this answer
3  
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}

enter image description here

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.