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}
    1 A

    Double-struck 1. Works in MathJax; needs a font with blackboard digits in LaTeX.

  • \mathds{1}_{A}
    Text mode, no math preview

    Double-struck 1 from \usepackage{dsfont} (pdfLaTeX). Not available in MathJax.

  • \mathbbm{1}_{A}
    Text mode, no math preview

    Double-struck 1 from \usepackage{bbm} (pdfLaTeX). Not available in MathJax.

  • \mathbf{1}_{A}
    1 A

    Bold 1: works everywhere without packages.

  • \chi_{A}
    χ A

    Characteristic function with chi, common in analysis.

  • \mathbb{1}_{\{X > 0\}}
    1 { X > 0 }

    Indicator of an event, written as a set in the subscript.

  • \mathbb{I}(x \in A)
    I ( x ∈ 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.

Templates

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

    1 A ( x ) = { 1 x ∈ A 0 x ∉ A
    LaTeX
    \mathbb{1}_{A}(x) = \begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases}
  • Expectation of an indicator

    E [ 1 A ] = P ( A )
    LaTeX
    \mathbb{E}\left[ \mathbb{1}_{A} \right] = P(A)
  • Counting with indicators

    N = ∑ i = 1 n 1 { X i > t }
    LaTeX
    N = \sum_{i=1}^{n} \mathbb{1}_{\{X_i > t\}}
  • Bold 1 alternative

    1 A ∩ B = 1 A 1 B
    LaTeX
    \mathbf{1}_{A \cap B} = \mathbf{1}_{A} \, \mathbf{1}_{B}
  • Characteristic function

    χ [ 0 , 1 ] ( x ) = { 1 0 ≤ x ≤ 1 0 otherwise
    LaTeX
    \chi_{[0,1]}(x) = \begin{cases} 1 & 0 \le x \le 1 \\ 0 & \text{otherwise} \end{cases}
  • Empirical distribution function

    F ^ n ( t ) = 1 n ∑ i = 1 n 1 { X i ≤ t }
    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.

LaTeX
\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}_A
  • A plain 1 with a subscript reads like the number one, not a function.

    Instead of
    1_{A}
    Write
    \mathbf{1}_{A}

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    pdfLaTeX needs dsfont (\mathds{1}) or bbm (\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 dsfont and 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\}}.

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