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.
1 Answers
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 thelandrhelper 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.
\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}
- 506,678

\mid, as doing so will insert a bit of whitespace on either side of the vertical bar, whereas writing|or\vertdoes not. – Mico Aug 15 '15 at 18:50vert. You'll find an example of a macro for this in the documentation ofmathtools, § 3.6, Paired Delimiters, p. 27. – Bernard Aug 15 '15 at 19:14\lvertand\rvertat times, instead of just\vert(or|). – Mico Aug 16 '15 at 06:59\giventhat provides the bar. Done right (using mathtools)\givenwill grow along side the outer fences. The advantage of the syntax is that code now make sense – daleif Aug 16 '15 at 07:17