Tx · LaTeX & TikZ

How to Typeset Expected Value in LaTeX Math Mode

Published By the 9to5Science editorial team

At a glance

  1. 1. Load the package

    Include amssymb in the preamble to make the blackboard-bold E available.

  2. 2. Enter math mode

    Use dollar signs for inline math or a display environment for a centered equation.

  3. 3. Write the notation

    Put the random variable in brackets after the expectation symbol.

The usual notation for the expected value of a random variable XX is a blackboard-bold E followed by XX in brackets. In LaTeX, write \mathbb{E}[X] in math mode. The \mathbb command requires the amssymb or amsfonts package.

Minimal working example

This complete example compiles with standard LaTeX:

\documentclass{article}
\usepackage{amsmath,amssymb}

\begin{document}
The expected value of $X$ is $\mathbb{E}[X]$.

For a discrete random variable with probability mass function $p_X$, when the sum is absolutely convergent,
\[
  \mathbb{E}[X] = \sum_x x\,p_X(x).
\]
\end{document}

The amssymb package provides \mathbb, which creates the blackboard-bold E. The amsmath package provides useful mathematical typesetting tools; it is included here as a standard companion. The dollar signs put the expression into inline math mode, while \[ ... \] creates a centered display equation.

Inline and displayed notation

Use inline math when the expectation appears in a sentence: $\mathbb{E}[X]$. Use a display when you want the expression to stand out on its own:

\[
  \mathbb{E}[X]
\]

You can also write conditional expectation in the same way:

\[
  \mathbb{E}[X \mid Y]
\]

Here \mid produces a properly spaced vertical bar. The brackets are conventional delimiters, but parentheses are also understood: \mathbb{E}(X). For a random variable with a density fXf_X, if ∫−∞∞∣x∣fX(x) dx<∞\int_{-\infty}^{\infty} |x| f_X(x)\,dx < \infty, then

E[X]=∫−∞∞xfX(x) dx.\mathbb{E}[X] = \int_{-\infty}^{\infty} x f_X(x)\,dx.

The notation is the same whether the expected value is defined by a sum or an integral; the distribution determines how you calculate it.

Alternatives to blackboard bold

Some styles or publications prefer an upright roman E rather than a blackboard-bold one. With amsmath, you can write \operatorname{E}[X]. The simpler \mathrm{E}[X] is another option. Follow a journal, instructor, or thesis style guide if it specifies a convention; otherwise, \mathbb{E}[X] is widely used.

Avoid typing a plain italic E if you want the expectation operator to be visually distinct from a variable. Also, \mathbb{E} is not a built-in command in a bare LaTeX document: load amssymb or amsfonts first.

Common mistakes

  • Leaving math mode: \mathbb{E}[X] belongs inside $...$ or a display-math environment. In ordinary text, LaTeX may report that it is missing math mode.
  • Omitting the package: If LaTeX says \mathbb is undefined, add \usepackage{amssymb} to the preamble, before \begin{document}.
  • Using a text command for math: Write \mathbb{E}, not \text{E}, when you want the blackboard-bold symbol.
  • Confusing notation with calculation: Typesetting \mathbb{E}[X] labels an expectation; it does not evaluate it. You still need the probability distribution and the appropriate sum or integral.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.