Since \mid
does not make much sense then you read \Exp{A \mid B}
(and cannot be scaled), I suggest hiding the |
inside a specially crafted macro giving us a macro that support conditionals including scaling.
\documentclass[a4paper]{memoir}
% requires 2014 edition of mathtools
\usepackage{amsmath,amssymb,mathtools,bm,etoolbox}
\providecommand\given{}
\DeclarePairedDelimiterXPP\Aver[1]{\mathbb{E}}{[}{]}{}{
\renewcommand\given{ \nonscript\:
\delimsize\vert
\nonscript\:
\mathopen{}
\allowbreak}
#1
}
\begin{document}
\begin{align*}
\Aver{A}
\\
\Aver{A \given B }
\\
\Aver*{\frac{A^2}{B^2+1}}
\\
\Aver[\bigg]{\frac{A^2}{B^2+1} \given c }
\end{align*}
\end{document}
Addition, if you do not have the 2014 version of mathtools, you can use this
\DeclarePairedDelimiterX\AverX[1]{[}{]}{
\renewcommand\given{ \nonscript\:
\delimsize\vert
\nonscript\:
\mathopen{}
\allowbreak}
#1
}
\newcommand\Exp{\mathbb{E}\AverX}
I'd might even consider using \operatorname{\mathbb{E}}
As far as I understand \nonscript\:
makes \:
disappear in a script context.
Since \vert
is a symbol not a fence, \vert - B
does not give the minus sign but rather an addition minus (wrong spacing). \mathopen
makes a potential -
behave as a sign rather than an addition. \allowbreak
just allows line breaks after \given
. Remove if not relevant (ie all conditionals are short).
\mid
is not a good symbol, 2 min and I'll post what I recommend to our users. BTW: always post full minimal examples.