8

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.

JPi
  • 13,595
  • 2
    If, when reading the formula out loud, you'd say "the density of Y given x", you should use \mid, as doing so will insert a bit of whitespace on either side of the vertical bar, whereas writing | or \vert does not. – Mico Aug 15 '15 at 18:50
  • Thank you. That's what I've in fact been doing, but it requires manual spacing correction if you have, say, $f(y \mid x) f(z\mid x)$, which looks odd: $f(y\mid x) ; f(z\mid x)$ looks better. – JPi Aug 15 '15 at 18:58
  • 1
    However, if you need to have a variable-sized vertival rule, you should use vert. You'll find an example of a macro for this in the documentation of mathtools, § 3.6, Paired Delimiters, p. 27. – Bernard Aug 15 '15 at 19:14
  • 1
    This question seems to solicit primarily opinion-based answers as it's asking about some form of preference (which may depend on the person, the use-case, or something else altogether). I've voted to close. – Werner Aug 15 '15 at 21:20
  • 2
    @JPi - Done. I've added a bit of information on why it's helpful to use \lvert and \rvert at times, instead of just \vert (or |). – Mico Aug 16 '15 at 06:59
  • 2
    I tend to provide a special syntax that provides the fences (here ()), plus an optional \given that provides the bar. Done right (using mathtools) \given will grow along side the outer fences. The advantage of the syntax is that code now make sense – daleif Aug 16 '15 at 07:17

1 Answers1

7

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}
Mico
  • 506,678