[Tex/LaTex] \mid or \vert in a conditional expectation or density function

delimiters

Which would you use to write a conditional density function $f(y|x)$ or a conditional expectation $E(y|x)$? There is an old question on this \mid, | (vertical bar), \vert, \lvert, \rvert, \divides, but it's unclear to me what the preferred form would be here.

Best Answer

The vertical bar produced by | or \vert has TeX math type "ordinary", meaning that no special meaning is attached to it. Quite often, though, it's necessary to inform TeX that the bar does have a special meaning.

  • If the bar acts as a separator between some expression and the conditioning event, as in "the conditional density of Y given x", you should use \mid: doing so generates a vertical bar with some whitespace around it.

  • If the bars act to enclose an expression, say as absolute value signs, it's helpful to assign status "math open" to the first bar (done automatically if you type \lvert) and "math close" to the second (by typing \rvert. This is important because it helps TeX figure out the correct spacing if unary operators occur at the start or end of the expression that's enclosed by the bars. Without the l and r helper information, the spacing around the - and + symbols will be what's appropriate for binary operators, which would be wrong in such cases.

  • The same discussion applies to double vertical bars, which are often used to denote the "norm" (however defined) of the enclosed expression.

enter image description here

\documentclass{article}
\usepackage{amsmath} % 
\begin{document}
$\begin{array}{cc}
\text{poor} & \text{good}\\[1ex]
f(y|x)        &  f(\,y\mid x\,) \\
\vert-x\vert  & \lvert-x\rvert  \\
\vert a+\vert & \lvert a+\rvert \\
\Vert+z\Vert  & \lVert +z\rVert \\
\end{array} $
\end{document}