5

The braket package has convenient commands like \Braket and \Set, where | are automatically expanded vertically. This allows to easily typeset expressions like

\documentclass{minimal}
\usepackage{braket}
\begin{document}
$$\Braket{\psi |i\hbar\frac{\partial}{\partial t}|\phi}$$ 
\end{document}

I'd like to do the same thing with other delimiters, for example to typeset conditional probabilities like $P(A=\frac12|B)$.

Edit to clarify the question I'm interested to cases where I don't know which size of the |-sign is the biggest. An example could be $P(A=\frac12|B=2^{2^2})$.

3
  • 4
    Remember to never use $$ in LaTeX documents.
    – egreg
    Commented Nov 27, 2011 at 21:01
  • Why ? Because it is more difficult to balance than '[]' ? The latter involve 6-times more keystrokes on my (French) keyboard, so I'm wondering whether the reason is really compelling ? Commented Nov 28, 2011 at 10:25
  • 2
    See tex.stackexchange.com/questions/503/why-is-preferable-to
    – egreg
    Commented Nov 28, 2011 at 10:40

2 Answers 2

14

Use \middle|

$P\left( A = \frac{1}{2} \middle| B \right)$
5
  • 5
    One should note that \middle| doesn't add space around the bar and so \;\middle|\; should be used. Even better, \nonscript\;\middle|\nonscript\; if this is used in a macro for something that can go into subscripts or superscripts.
    – egreg
    Commented Nov 27, 2011 at 20:21
  • 1
    @egreg: I usually use \,\middle\, in macros, but \; is better.
    – Aditya
    Commented Nov 27, 2011 at 20:38
  • 1
    isn't \middle e-tex specific ? If yes wouldn't that h-complicate the exchanges of documents with colleagues ? Commented Nov 28, 2011 at 10:35
  • 3
    @FrédéricGrosshans Only very old distributions don't use by default an e-TeX enabled engine for LaTeX
    – egreg
    Commented Nov 28, 2011 at 10:41
  • 2
    OK. Then I'll try this and come back when I encounter an overconservative colleague :-) Thanks. Commented Nov 28, 2011 at 10:50
0

One could also use \vert as an additional nested bracket like in:

$P\left( \left. A = \frac{1}{2} \,\right\vert B \right)$
1
  • 1
    This would only work as expected if B in your example isn't awkwardly big. Otherwise \right\vert won't scale to the appropriate length. In such a case \right\vert and \right) won't have the same height.
    – Werner
    Commented Aug 17, 2016 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .