There are many commands for including text in equations. Text and mathrm commands are popular among them.
Let’s take a look at each command’s syntax and usage below for better understanding.
Use text command from amsmath
\text
command is part of the amsmath package and allows you to insert text within math mode.
\documentclass[12pt]{article}
\usepackage{amsmath,lipsum}
\begin{document}
\begin{align*}
x &= \text{some text} + y \\
x &= \text{Velocity} \times \text{Time} \\
&= v \cdot t
\end{align*}
\lipsum[1][1-4]
\begin{align*}
a &= \frac{2}{3} \times 5 \\
&= \text{two-thirds of five} \\
&= \text{approximately} \, 3.33
\end{align*}
\end{document}
Output :
Use mathrm command for insert text in equation
\mathrm
command is used to set text in roman font within math mode. It is often used for labeling variables or constants.
\documentclass[12pt]{article}
\usepackage{amsmath,lipsum}
\begin{document}
Let \( f(x) = \mathrm{sin}(x) + \mathrm{cos}(x) \) be a function.
\begin{align*}
F &= m \cdot a \\
&= \mathrm{mass} \times \mathrm{acceleration} \\
&= \mathrm{kg} \cdot \mathrm{m/s}^2 \\
&= \mathrm{Newton}
\end{align*}
\lipsum[2][1-4]
\begin{align}
E &= m \cdot c^2 \\
&= \mathrm{mass} \times \mathrm{speed~of~light}^2 \\
&= \mathrm{kg} \cdot (\mathrm{m/s})^2 \\
&= \mathrm{Joule}
\end{align}
\end{document}
Output :
Use mbox command
\mbox{}
is commonly used within mathematical environments (e.g., equation, align, etc.) to include descriptive text or labels within mathematical expressions.
This command does not add any additional space around the included text. You may need to manually add spacing commands (such as \quad
or \,
) if required.
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
x &= \mbox{Initial position} + \mbox{Velocity} \times \mbox{Time} \\
&= x_0 + v \cdot t \\[8pt]
v &= \frac{\mbox{Total displacement}}{\mbox{Total time}} \\
&= \frac{x_f - x_i}{t} \\[8pt]
F &= \mbox{Mass} \times \mbox{Acceleration} \\
&= m \cdot a
\end{align}
\end{document}
Output :
Use textnormal command
The \textnormal{arg}
command in LaTeX is used to typeset text in its normal font style, outside of math mode.
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= \textnormal{Initial position} + \textnormal{Velocity} \times \textnormal{Time} \\
&= x_0 + v \cdot t
\end{align*}
\begin{align*}
\textnormal{Given the function} \quad f(x) &= x^2 + 3x - 2 \\
\textnormal{Find the derivative:} \quad f'(x) &= \frac{d}{dx}(x^2 + 3x - 2) \\
&= \frac{d}{dx}x^2 + \frac{d}{dx}(3x) - \frac{d}{dx}(2) \\
&= 2x + 3 \\
\\
\textnormal{Given the function} \quad g(x) &= \sin(x) + \cos(x) \\
\textnormal{Find the derivative:} \quad g'(x) &= \frac{d}{dx}(\sin(x) + \cos(x)) \\
&= \frac{d}{dx}\sin(x) + \frac{d}{dx}\cos(x) \\
&= \cos(x) - \sin(x) \\
\\
\textnormal{Given the function} \quad h(x) &= e^x \cdot \ln(x) \\
\textnormal{Find the derivative:} \quad h'(x) &= \frac{d}{dx}(e^x \cdot \ln(x)) \\
&= \frac{d}{dx}(e^x) \cdot \ln(x) + e^x \cdot \frac{d}{dx}(\ln(x)) \\
&= e^x \cdot \ln(x) + \frac{e^x}{x} \\
\end{align*}
\end{document}
Output :