[Tex/LaTex] Double vertical bar notation


A common notation used for information divergence is D(P||Q). I hope to get something like D(S||Q) where S=||P||/2. I wonder if it is possible to display it nicely ? In such a way that the middle double bar has the right height. I tried

$D \left( \frac{\|P\|}{2} \right| \left| Q \right)$

The above do not work as the middle bar are not of the same vertical height but its closest to what I hope to achieved. Using just \| instead of \right| \left| for the middle double bar results in a short middle double bar.

Does anyone has a good idea on how to achieve that. Thanks
Else, I could just create a new notation.

— Update —
I managed to find out how to do it with this useful operator \middle

$D \left( \frac{\|P\|}{2} \middle\| Q \right)$

Hope someone else may find this useful.

Best Answer

This double bar should be treated as a binary relation, so it will be distinguishable from other usages, such as a norm.

The simplest way to cope with the problem is to use mathtools facilities:




D\left(P \middle\| Q\right) \rlap{\quad\itshape WRONG!} \\
% normal size
\infdiv{P}{Q} \\
% fixed size delimiters
\infdiv[\bigg]{\frac{\norm{P}}{2}}{Q} \\
% extensible delimiters


enter image description here

Note that number 1 is wrong in two respects: there is an unwanted space between the "D" and the left parenthesis; the two bars are too near the symbols, making for ambiguity.