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
P(A)\Pr is upright.P(A \mid B)\mid gives relation spacing.A^{c}, \bar{A}P(A \cup B)A \perp B\perp, not \bot in prose.X \sim N(0,1)\sim for "is distributed as".The commands
\Pr or \mathrm{P} is the formal operator spelling. P(A) = 0.3
\mid gives the thin spaced bar. A literal | prints but sits too low and too tight. P(A \mid B)
P(A \cap B)
P(A \cup B) = P(A) + P(B) - P(A \cap B)
P(A^c) = 1 - P(A)
P(A \cap B) = P(A)P(B)
P(X = k)
\sim reads "is distributed as". Put the distribution name in roman so it is not mistaken for a product. X \sim B(n, p)
\mathbb{E}[X] = \sum_x x\,P(X=x)
\operatorname so it prints upright with correct spacing. \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)}
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)
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)
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\}
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)asP(A and B). The word needs\text{ and }; unbraced it prints as four multiplied variables. - Using
\simfor approximate equality inside a probability line, then wondering why the distribution statement reads as an approximation. - Leaving the outcome labels in italic products:
HTis 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?
\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?
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.