Write Text inside Math Mode: Tips + Examples


In LaTeX math mode, spaces are overlooked, and letters are rendered in italics. Hence, in order to add normal text, we need special commands such as \text, \textrm, \mbx and \textnormal. This post discusses these methods and highlight the difference through illustrative examples.


In this article, three different type of methods to add text in LaTeX in math mode will be explained: Text, Textrm and mbox.

  1. Method 1: \text{} command
  2. Method 2: \textrm{} command
  3. Method 3: \mbox{} command

Method 1: \text{} command

In LaTeX, the command \text{} with package amsmath is used to add normal text in math in LaTeX. Here is an example:

% Method 1 using \text command
\documentclass{article}
% Required package
\usepackage{amsmath}

\begin{document}
$\text{Let } x=\text{Countries participated in the marathon}. $
\end{document}

Output:

From the above example, the command \text{} is used to print Let and Countries participated in the marathon in normal text in math mode in LaTeX

Method 2: \textrm{} command

The command \textrm forces the roman font style for text and keeps font parameters from the current text font. It should be noted that font size is the same as the current math style if the package amsmath is loaded. Check the following code:

% Method 2 using \textrm command
\documentclass{article}
% Required package
\usepackage{amsmath}

\begin{document}
$\textrm{Let } x=\textrm{Countries participated in the marathon}. $
\end{document}

Method 3: \mbox{} command

In LaTeX, the command \mbox{} can be used to add normal text in math environment in LaTeX. \mbox{} command creates a box to hold the text and uses the current text font. It should be noted that the font size is constant and does not change, e.g. in subscripts, superscripts, and fractions. Here is an illustrative example:

% Method 3 using \mbox command
\documentclass{article}
% Required package
\usepackage{amsmath}

\begin{document}
$ \mbox{Let } x_{\mbox{countries participated in the marathon}.} $
\end{document}

Output:

Obtained using \mbox command, part of text is added as a subscript
Obtained using \text command, part of text is added as a subscript

You can remark that \text command updates the font size to meet the subscript font size which is not the case with \mbox.

Summary

\text{} command is equivalent to \textrm and \mbox with the exceptions that \textrm always uses the roman font and \mbox does not change font size in the case of subscripts, superscripts, fractions. More details can be found in the documentation Math Mode, section 37, page 69.

Recent Posts