How to write factorial(!) symbol in LaTeX?

Let’s discuss how to write factorial symbols(!) using LaTeX. Displaying this symbol is very simple because there is no default command for it.

Where a factorial symbol is required, it is sufficient to directly insert an exclamation mark, which is present on your keyboard.

\documentclass{article}
\usepackage{amsmath} 
\begin{document}

\[ e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} \]
This series includes ! in the denominator and converges for all real numbers \( x \).

\[ \sin x = \sum_{n=0}^{\infty} (-1)^n \frac{x^{2n+1}}{(2n+1)!} \]
This series uses only odd powers of \( x \) and ! in the denominators.

\[ \cos x = \sum_{n=0}^{\infty} (-1)^n \frac{x^{2n}}{(2n)!} \]
This series uses only even powers of \( x \) and includes ! in the denominators, illustrating even symmetry.

\[ (1 + x)^n = \sum_{k=0}^n \binom{n}{k} x^k = \sum_{k=0}^n \frac{n!}{k!(n-k)!} x^k \]
This theorem uses ! to calculate the coefficients of the expansion, denoted by \( \binom{n}{k} \).

\[ \Gamma(x) = \int_0^\infty t^{x-1} e^{-t} \, dt \quad \text{(extends } (x-1)!\text{)} \]
This definition extends the ! function beyond positive integers.

\end{document}

Output :

This figure shows how the exclamation mark is used directly.

Many of you will think to use \! as a command instead of !. But, no. Because the \! command is used to create negative spacing. It is mainly used to reduce the space between two objects.

Spaces are added around factorial symbols

If you need extra space around this factorial symbol(!), there are several ways to handle that. These spacings make mathematical expressions more readable for ease of understanding.

LaTeX’s default settings usually provide enough space. After that, you can use spacing commands like \,, \;, \quad, and \qquad.

\documentclass{article}
\usepackage{amsmath}  
\begin{document}
\[ \text{Given the function } f(x) = \frac{(x+1)\,!}{x\;!}, \text{ simplify the expression and find its derivative.} \]
\[ f(x) = \frac{(x+1)\,\,!}{x\,\;!} = \frac{(x+1) \times x\,!}{x\;!} = x+1\]
\[ f'(x) = \frac{d}{dx}(x+1) = 1\]
\[ \text{Evaluate the integral } \int (x+2)! \, dx \]
\end{document}

Output :

Spaces are manually added around Python symbols.

For the same task, we’ll look at the use of a \oc command, part of small package, that specifies operator symbols, such as factorial symbols, with space formatting for displaying them in documents.

Proper spacing is added to the equation using \oc command, which usually gives better-formatted output than adding spaces manually.

\documentclass{article}
\usepackage{amsmath,cmll}
\begin{document}
 \[x=!n\]
 \[x=\,!n\]
 \[x=\oc n\]
 \[x=\;!n \quad \verb|like oc command| \] 
\end{document}

Output :

This figure show use of \oc command which represent ! symbol with space.

The \oc command usually displays the factorial symbol with appropriate space after = sign.

Defining a new command instead of this symbol

If you want to create a new command for the factorial symbol, use \newcommand to set up a simple command.

\newcommand{\fact}[1]{#1!}

Here, \fact{arg} is the name of a new command, and #1 is the parameter that will determine !.

If you prefer to have a small space between the number and factorial symbol (!), which is usually needed, you can use the code like this:

\newcommand{\fact}[1]{#1\, !}

Here, \, adds a small space which creates an appropriate distance between the number and factorial sign.

\documentclass{article}
\usepackage{amsmath}  % For advanced math formatting
\newcommand{\fact}[1]{#1!}
\newcommand{\facts}[1]{#1\,!}
\begin{document}
\[ f(x) = e^x = \sum_{n=0}^{\infty} \frac{x^n}{\fact{n}} = 1 + x + \frac{x^2}{\fact{2}} + \frac{x^3}{\fact{3}} + \cdots\]
\[ \text{Calculate } \int e^x \, dx \text{ using the power series expansion up to } x^3.\]
\[ \int e^x \, dx = \int \left(1 + x + \frac{x^2}{\facts{2}} + \frac{x^3}{\facts{3}}\right) \, dx = x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + C\]
\[ \text{If } g(x) = \frac{\facts{(2x+2)}}{\fact{2}}, \text{ simplify } g(x) \text{ and find } g'(x).\]
\[ g(x) = \frac{\facts{(2x+2)}}{\fact{2}} = \frac{(2x+2)(2x+1)x\,!}{x\,!} = (2x+2)(2x+1)\]
\end{document}

Output :

The above code creates a new command by newcommand which denotes '!' symbol.

Expressing multiple factorial symbols in LaTeX

To show multiple factorial symbols in LaTeX, add ! symbols after the number as needed. For example:

n!! or n!!! or n!!!!

For the double !!, there is a \Exclam command in stix package that you can use. For instance:

\documentclass{article}
\usepackage{stix}
\begin{document}
 \[ n\Exclam \quad n!! \]
 \[ m!\,!\,! \quad m\,!!! \]
 \[ n\,!\,!\,!\,! \quad n!!!! \]
\end{document}

Output :

This diagram shows how to use multi factorial in LaTeX.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

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