Probability Notation in LaTeX: P(A) and Conditional Events

The conditional bar that must be a command, how to keep P from reading as a product, and the notation for events, complements and distributions.

Probability notation is small and unforgiving: one bar decides whether the page reads correctly. Written as | the conditional bar loses its relation spacing and can be mistaken for a divider; written as \mid it behaves like the word "given". The rest is set algebra (Set Notation), and the argument of a distribution is a bracketed list — a Brackets question.

Which one to use

Situation Write this Because
A single event
P(A)
Italic P is common; \Pr is upright.
A conditional probability
P(A \mid B)
\mid gives relation spacing.
The complement
A^{c}, \bar{A}
Superscript c or a bar.
Union of events
P(A \cup B)
Set symbols inside probability.
Independence
A \perp B
\perp, not \bot in prose.
A distribution
X \sim N(0,1)
\sim for "is distributed as".

The commands

What Type this Renders as
Event probability A plain italic P is accepted in school texts; \Pr or \mathrm{P} is the formal operator spelling.
P(A) = 0.3
P(A) = 0.3
Conditional \mid gives the thin spaced bar. A literal | prints but sits too low and too tight.
P(A \mid B)
P(A \mid B)
Joint event Intersection reads as "and"; the multiplication form P(A)P(B) only holds when independent.
P(A \cap B)
P(A \cap B)
Union of events The general addition law, and the reason the intersection term must not be dropped.
P(A \cup B) = P(A) + P(B) - P(A \cap B)
P(A \cup B) = P(A) + P(B) - P(A \cap B)
Complement Prime and superscript c both appear; consistency matters more than the choice.
P(A^c) = 1 - P(A)
P(A^c) = 1 - P(A)
Independence test Written without any conditioning symbol, which is what makes it a statement about independence.
P(A \cap B) = P(A)P(B)
P(A \cap B) = P(A)P(B)
Random variable Uppercase for the variable, lowercase for the value it takes; both italic.
P(X = k)
P(X = k)
Distribution shorthand \sim reads "is distributed as". Put the distribution name in roman so it is not mistaken for a product.
X \sim B(n, p)
X \sim B(n, p)
Expectation Square brackets are conventional for expectation, parentheses for variance.
\mathbb{E}[X] = \sum_x x\,P(X=x)
\mathbb{E}[X] = \sum_x x\,P(X=x)
Variance of a variable An operator name built with \operatorname so it prints upright with correct spacing.
\operatorname{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}[X])^2
\operatorname{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}[X])^2

Worked examples

Bayes theorem

P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}
P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}

The thin space before P(A) stops the closing bracket of the previous factor running into it.

Two-stage experiment

P(A \cap B) = P(A)\,P(B \mid A)
P(A \cap B) = P(A)\,P(B \mid A)

Multiplication rule: the second factor carries the condition created by the first event.

Total probability

P(B) = \sum_{i} P(B \mid A_i)\,P(A_i)
P(B) = \sum_{i} P(B \mid A_i)\,P(A_i)

A partition of the sample space summed over, which is why the index sits on both factors.

Sample space of coin tosses

S = \{HH, HT, TH, TT\}
S = \{HH, HT, TH, TT\}

Multi-letter outcomes need braces around each element or they read as products of two variables.

Common mistakes

  • Writing P(A|B) with a literal pipe. It renders as a relation-height bar with no spacing, which is exactly where Markdown and MathJax pipelines disagree about what your expression means.
  • Setting out P(A ∩ B) as P(A and B). The word needs \text{ and }; unbraced it prints as four multiplied variables.
  • Using \sim for approximate equality inside a probability line, then wondering why the distribution statement reads as an approximation.
  • Leaving the outcome labels in italic products: HT is H times T. Sample points normally want \mathrm{HT} or a braced text form.

Questions about this notation

How do I write "given that" in LaTeX?
\mid inside the parentheses: P(A \mid B). For a display-sized bar use \left( A \,\middle|\, B \right), which grows with the content around it.
Should P be italic or roman?
School and exam texts set it italic as a function letter; formal probability sets it upright, usually via \Pr, because it is an operator rather than a variable. Either is defensible — mixing them within one document is not.
What is the difference between \Pr and P?
\Pr is a declared operator name, so it prints upright with the spacing maths mode gives functions. P is simply the italic letter, which reads as a variable called P applied to brackets.
How do I write conditional probability, or say that two variables are independent?
Conditional probability is P(A \mid B), where \mid carries the spacing; the operator form \Pr(A \mid B) keeps the P upright and out of the italics. Independence is conventionally written X \perp Y and, when you must distinguish perpendicular lines from statistical independence, X \perp\!\!\!\!\perp Y — core LaTeX has no four-bar symbol, hence the manual kerns.

Keep reading

Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.