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
.
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:
You can remark that \text
command updates the font size to meet the subscript font size which is not the case with \mbox
.