Here's another solution, also based on the mathtools
package, but now making use of the \DeclarePairedDelimiterX
macro as well as the \given
and \Set
macros set up on page 27 of the package's user guide.
The main user macro in the code below is called \expect
. Observe that it inserts half of a thinspace to the right of the opening square bracket and to the left of the closing square bracket.
Incidentally, I think the E
symbol ("expectation", right?) should be typeset as an upright-Roman character since it represents a math operator.
\documentclass{article}
\usepackage{mathtools}% for "\DeclarePairedDelimiterX" macro
% Expectation operator
\DeclareMathOperator{\E}{E}
%% Three auxiliary macros: \given, \SetSymbol, and \Set
\providecommand\given{}
\newcommand\SetSymbol[1][]{%
\nonscript\:#1\vert\allowbreak\nonscript\:\mathopen{}}
\DeclarePairedDelimiterX\Set[1]\lbrack\rbrack{%
\renewcommand\given{\SetSymbol[\delimsize]}#1}
%% Main user macro: \expect
\newcommand\expect[2][]{\E\Set[#1]{\mkern1.5mu#2\mkern1.5mu}}
\begin{document}
\[
\expect[\bigg]{\sum_{i=1}^N x_n\given Y}
\qquad
\expect[\Big]{\sum_{i=1}^N x_n}
\]
\end{document}
\middle
? (tex.stackexchange.com/questions/3137/…)mathtools
. See the package documentation, § 3.6, Paired Delimiters, pp. 25–29.