# Automatically make three brackets the same size

I would like to do something like left[ and right], but with an additional | in between which automatically has the same size as the left/right. This comes from the way I denote conditional expectations. I wish to define a command which produces

E[ (first argument) | (second argument) ]

where [ , | and ] are all automatically of the same size (i.e. such that the "larger" of 1st/2nd argument determines the size of all three of them.

The minimal working example that follows contains two tries I did so far: \Econd, which does not scale | at all (just to show what I do not want), and \Econd2, a solution I came up with after searching for similar questions. It uses \vphantom to force 1st/2nd argument to be the same size and a left. so that the left and right match up in pairs. This is pretty much what I want but because of right/left I now get an additional space after the "|". Of course I could insert a \! there (which looks almost like what I want), but I was wondering if there was some more elegant solution to this?

The MWE shows a standard case, then the left argument is a bit bigger so that "|" is a bit too small, and then an extreme example I made up.

MWE:

\documentclass{scrartcl}
\usepackage{amsmath} % math. Symbole
\usepackage{dsfont} %\mathds{P} Wahrscheinlichkeit-Symbol; E für Erwartungswert

\newcommand{\Econd}[2]{\mathds{E}\!\left[#1|#2\right]}
\newcommand{\Econdtwo}[2]{\mathds{E}\!\left[#1 \vphantom{#2} \right|\left. #2 \vphantom{#1} \right]}

\begin{document}

Some examples are
\begin{align*}
&\Econd{X_t}{X_s}\\ %normal look
&\Econd{X_t^2}{X_s}\\ %tiny bit too small
&\Econd{\left(\left(\frac{fra}{ction}\right)^{po} X_t\right)^{wer}}{X_s} %extreme case
\end{align*}

The same examples with the second command
\begin{align*}
&\Econdtwo{X_t}{X_s}\\ %normal look
&\Econdtwo{X_t^2}{X_s}\\ %tiny bit too small
&\Econdtwo{\left(\left(\frac{fra}{ction}\right)^{po} X_t\right)^{wer}}{X_s} %extreme case
\end{align*}

\end{document}


Picture of MWE:

• \left[...\middle|...\right\] – David Carlisle Jan 27 '16 at 16:46
• Wow. You should post that as an answer as it is so simple and beautiful ;-) – Manuel Jan 28 '16 at 9:21

\left[....\middle|....\right\]


A standard application of \DeclarePairedDelimiterX:

\documentclass{article}

\usepackage{mathtools,amssymb}

\newcommand{\Econd}{\operatorname{\mathbb{E}}\EcondX}
\DeclarePairedDelimiterX{\EcondX}[2]{[}{]}{%
#1\nonscript\;\delimsize|\nonscript\;#2%
}

\begin{document}

Some examples are
\begin{align*}
&\Econd{X_t}{X_s}\\ %normal look
&\Econd[\big]{X_t^2}{X_s}\\ %slightly bigger
&\Econd*{\left(\left(\frac{fra}{ction}\right)^{po} X_t\right)^{wer}}{X_s} %extreme case
\end{align*}

\end{document}


Note that the second line should have normal size brackets.