Subfactorial in LaTeX (!n)

!n!n
LaTeX command
!n
Package
No package needed: built into LaTeX
Mode
Text and math mode

Try Subfactorial in a real LaTeX document

Open a ready-to-compile document that already uses !n, with the right packages loaded. Edit it and see the PDF, no install needed.

Where it is used

Subfactorial of n, a prefix-exclamation notation for the number of derangements of n objects.

!n equals D_n, the count of permutations with no fixed points: !4 = 9 and !n = \left\lfloor n!/e + 1/2 \right\rfloor for n \geq 1. The prefix exclamation is compact but easy to misread, especially after a variable, where m!n looks like m factorial times n. Writing D_n, or adding explicit grouping, prevents this. In TeX the exclamation mark belongs to the closing class, so after a binary relation like = it typesets with no extra space, as you want. Some authors use the inverted exclamation or n\text{¡}, but that notation is rare.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

!n=n!∑k=0n(−1)kk!,!4=9!n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}, \quad !4 = 9
\documentclass{article}
\begin{document}
Subfactorial: $!n$

\[ !n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}, \quad !4 = 9 \]
\end{document}

Related symbols

All التوافقيات →

Frequently asked questions

How do I write Subfactorial in LaTeX?
Type !n in math mode, for example $!n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}, \quad !4 = 9$. It works in plain LaTeX without loading any package.
Which package do I need for !n?
None. !n is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use !n in text mode, or only in math mode?
Both. !n compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.
Math poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث