How to write prime “f′(x)” and double prime (x″) in LaTeX?
In LaTeX there are two ways to write the prime symbol above a character. In this tutorial, you will get all of these methods.
The table below lists the best methods for writing Prime, Double Prime, and Triple Prime in a LaTeX document.
| Name | Command | Output |
|---|---|---|
| Prime | x^{\prime} | |
| Double Prime | x^{\prime\prime} | |
| Triple Prime | x^{\prime\prime\prime} |
All of these commands work in LaTeX math mode.
\documentclass{article}
\begin{document}
$$ f^{\prime}(x) $$
$$ f^{\prime\prime}(x) $$
$$ f^{\prime\prime\prime}(x) $$
\end{document}Output:

Get the Prime symbol from keyboard
Your keyboard also has a prime symbol key ', which you can also use in LaTeX. But the recommended method is to use the \prime command.
\documentclass{article}
\begin{document}
$$ \verb|x'| \rightarrow x' $$
$$ f'(x) $$
$$ f''(x) $$
$$ f'''(x) $$
\end{document}Output:

Create custom commands for Prime
In LaTeX, you can create your custom commands with \newcommand to write less code for your document. Take a look.
\documentclass{article}
\newcommand{\dprime}{^{\prime\prime}}
\newcommand{\tprime}{^{\prime\prime\prime}}
\begin{document}
Prime symbol with custom commands:
$$ f^{\prime}(x) $$
$$ f^{\dprime}(x) $$
$$ f^{\tprime}(x) $$
\end{document}Output:

Prime symbol in LaTeX text mode
To write the prime symbol in LaTeX text mode you can use the \textprime command provided by the flexisym package.
\documentclass{article}
\usepackage{flexisym}
\begin{document}
\noindent Prime symbol in text mode:\\[6pt]
Prime: a\textprime\\[4pt]
Double Prime: a\textprime\textprime\\[4pt]
Triple Prime: a\textprime\textprime\textprime
\end{document}Output:

Also, you can use $^\prime$ in inline math mode, or with the \newcommand and \ensuremath{'} command you can create a custom command for every mode (text and math). The \ensuremath command does only switch to math mode if math mode is not already active.
\documentclass{article}
\newcommand{\allmodeprime}{\ensuremath{'}}
\begin{document}
Prime symbol in inline math mode: $a^\prime$
Prime symbol in inline math mode: $a\allmodeprime$
Prime symbol in text mode: a\allmodeprime
Prime symbol in display math mode:
$$a\allmodeprime$$
\end{document}Output:

Prime symbol with stix package
The stix package also provides some commands to get prime, double prime, and triple prime symbols in LaTeX.
| Name | Command | Output |
|---|---|---|
| Prime | $f^{\prime}(x)$ | |
| Double Prime | $f^{\dprime}(x)$ | |
| Triple Prime | $f^{\trprime}(x)$ | |
| Quadruple Prime | $f^{\qprime}(x)$ |
Leave a Reply