Indicator Function in LaTeX
The indicator function is usually a double-struck one: \mathbb{1}_{A}(x). MathJax accepts that, but in pdfLaTeX the amssymb blackboard font has capital letters only, so use \mathds{1} from the dsfont package or \mathbbm{1} from bbm there. \mathbf{1}_{A} and \chi_{A} work everywhere.
Indicator notation
\mathbb{1}_{A}Double-struck 1. Works in MathJax; needs a font with blackboard digits in LaTeX.
- Text mode, no math preview
\mathds{1}_{A}Double-struck 1 from
\usepackage{dsfont}(pdfLaTeX). Not available in MathJax. - Text mode, no math preview
\mathbbm{1}_{A}Double-struck 1 from
\usepackage{bbm}(pdfLaTeX). Not available in MathJax. \mathbf{1}_{A}Bold 1: works everywhere without packages.
\chi_{A}Characteristic function with chi, common in analysis.
\mathbb{1}_{\{X > 0\}}Indicator of an event, written as a set in the subscript.
\mathbb{I}(x \in A)Double-struck capital I, used in some statistics texts.
Try it live
Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.
Indicator function examples
Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.
Definition
LaTeX\mathbb{1}_{A}(x) = \begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases}Expectation of an indicator
LaTeX\mathbb{E}\left[ \mathbb{1}_{A} \right] = P(A)Counting with indicators
LaTeXN = \sum_{i=1}^{n} \mathbb{1}_{\{X_i > t\}}Bold 1 alternative
LaTeX\mathbf{1}_{A \cap B} = \mathbf{1}_{A} \, \mathbf{1}_{B}Characteristic function
LaTeX\chi_{[0,1]}(x) = \begin{cases} 1 & 0 \le x \le 1 \\ 0 & \text{otherwise} \end{cases}Empirical distribution function
LaTeX\hat{F}_n(t) = \frac{1}{n} \sum_{i=1}^{n} \mathbb{1}_{\{X_i \le t\}}
Why \mathbb{1} fails in pdfLaTeX
With \usepackage{amssymb}, \mathbb uses a blackboard-bold font that only has the capital letters A–Z. \mathbb{1} then prints a wrong glyph or nothing useful. MathJax uses its own fonts, so the same code looks right in a browser, which is why it often works in notes but breaks in the paper.
The usual fixes in Overleaf are the dsfont package (\mathds{1}) or bbm (\mathbbm{1}). With XeLaTeX or LuaLaTeX and the unicode-math package, \mathbb{1} works directly.
\usepackage{dsfont}
\newcommand{\1}{\mathds{1}}
% ...
\[ \1_{A}(x) \]Notation that works in both places
If the same formula has to render in Overleaf and on a website or in Markdown, use \mathbf{1}_{A} or \chi_{A}, which need no special font. Or define one macro per target, for example \newcommand{\ind}{\mathds{1}} in LaTeX and \ind mapped to \mathbb{1} in the MathJax configuration.
Common mistakes
amssymb’s blackboard font has no digits, so the 1 is not drawn as a double-struck one.
Instead of\mathbb{1}_A (pdfLaTeX with amssymb)Write\mathds{1}_A % with \usepackage{dsfont}MathJax and KaTeX do not know
\mathds; they do accept\mathbb{1}.Instead of\mathds{1}_A (in Markdown or on a web page)Write\mathbb{1}_AA plain 1 with a subscript reads like the number one, not a function.
Instead of1_{A}Write\mathbf{1}_{A}
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
pdfLaTeX needs
dsfont(\mathds{1}) orbbm(\mathbbm{1}) for a double-struck one;\mathbb{1}only works with fonts that include blackboard digits, such as unicode-math under XeLaTeX or LuaLaTeX.MathJax and KaTeX
MathJax accepts
\mathbb{1}; how the 1 looks depends on the fonts available to it. KaTeX’s issue tracker has reports of\mathbb{1}not rendering as expected, so\mathbf{1}is the safe fallback on the web.Microsoft Word
Word’s equation editor can show double-struck characters, but pasted LaTeX is not converted reliably. Write the indicator here and use Copy for Word to paste it as an editable equation.
Indicator function in LaTeX: questions
- How do I write the indicator function in LaTeX?
- Use a double-struck one with a subscript:
\mathbb{1}_{A}on the web,\mathds{1}_{A}(dsfont) or\mathbbm{1}_{A}(bbm) in pdfLaTeX. - Why does \mathbb{1} not work in Overleaf?
- The default amssymb blackboard-bold font has only capital letters. Load
dsfontand write\mathds{1}, or compile with XeLaTeX or LuaLaTeX and unicode-math. - Is \chi the same as the indicator function?
- Yes,
\chi_{A}(characteristic function) is the same function; which symbol you use is a convention of the field. - How do I write the indicator of an event?
- Put the condition in set braces in the subscript:
\mathbb{1}_{\{X > 0\}}.
Related LaTeX reference
- Real Number Symbol in LaTeXBlackboard bold number sets with \mathbb: ℝ, ℕ, ℤ, ℚ, ℂ, ℝⁿ, and why \R does not work out of the box.
- Piecewise Function in LaTeXThe cases environment: one line per piece, & before each condition, \text for words, dcases and rcases variants.
- Element of Symbol (∈) in LaTeX\in for ∈, \notin for ∉, \ni for ∋, and how ∈ differs from the Greek letter epsilon.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
Have the formula as a picture?
Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.
Convert an image to LaTeX