# 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.

• I'd rather recommend not using auto scaling unless it is absolutely necessary. Try you construction as part of the text, using P^2 instead of P. The fences will become too large. Dec 31, 2013 at 23:11

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:

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX{\infdivx}[2]{(}{)}{%
#1\;\delimsize\|\;#2%
}
\newcommand{\infdiv}{D\infdivx}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}

\begin{gather}
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
\infdiv*{\frac{\norm{P}}{2}}{Q}
\end{gather}

\end{document}


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.

• Out of curiosity, wouldn't one want to use \operatorname{D}? May 6, 2020 at 10:51
• @jhin Not necessarily. It mostly depends on what “D” represents. May 6, 2020 at 14:41

In MathJax use $\lVert$ and $\rVert$. The capital v gives you double bars while the lower case v in $\lvert$ gives you single vertical bars. But it's not clear to me what to you is the "right" height.

Also, you have $\vert$ and $\Vert$.

Since you mention using a vertical bar as a binary relation, you may want $\mid$ which is kerned to sit midway between its neighbours. But that has no double-bar version so finally, you have the option of $\mathrel{\Vert}$ which is both double-bar and kerned to the centre.

• I don't think your last edit is correct. \vert and \Vert are declared as \mathord, not \mathbin. Dec 23, 2020 at 11:52
• @campa thanks, you may be right because I don't fully understand your comment. What aspect of what I put is untrue? The part about the kerning? This might be wrong. Also I started out thinking of $\mid$ and then changed when I realsed there is no $\Mid$. Dec 23, 2020 at 18:14
• The bit about spacing is incorrect. \mid has the spacing of a binary relation, but \vert is an ordinary symbol. And as you say there is indeed no Mid. (I was wrong too, I wrote \mathbin but actually meant \mathrel.) Bottom line: \vert and \Vert are not kerned. \mid is, and for thr double bar you must either do \mathrel{\Vert}, or insert spacong manually (as egreg did) or define your own macro \Mid. Dec 23, 2020 at 18:37
• THanks @campa . Is that all accurate now? IF so I will prune these comments. Dec 23, 2020 at 18:55

Using \parallel gives a nice result. ￼ Latex code:D_{KL}(q(z|x,\phi)\parallel p(z))

• This is bad advise as \parallel cannot be scaled and thus the auto scaled version the OP shows last will not work. Mar 22 at 9:45

An alternative is to use \Big\|. And instead of \Big one can use \big or \bigg, etc. depending on how much length you want.