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.

NameCommandOutput
Primex^{\prime}x^{\prime}
Double Primex^{\prime\prime}x^{\prime\prime}
Triple Primex^{\prime\prime\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:

all prime symbols.

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:

prime symbol from keyboard.

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 with custom commands.

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:

prime symbol in text mode.
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 in all mode.

Prime symbol with stix package

The stix package also provides some commands to get prime, double prime, and triple prime symbols in LaTeX.

NameCommandOutput
Prime$f^{\prime}(x)$f^{\prime}(x)
Double Prime$f^{\dprime}(x)$f^{\dprime}(x)
Triple Prime$f^{\trprime}(x)$f^{\trprime}(x)
Quadruple Prime$f^{\qprime}(x)$f^{\qprime}(x)

Leave a Reply

Your email address will not be published. Required fields are marked *