I was trying to define a new command for an expectation which scales the vertical dash (in case of conditional expectation) and parenthesis to the argument, respectively. Additionally, I want to have a parameter which specifies which expectation I am talking about, i.e. $\mathbb{E}_{index}$ where index an arbitrary value.
I was following the instruction from this post [vertical bar for absolute value and conditional expectation. Unfortunately, the index is now the argument of the expectation and the other way around. When simply exchanging #1 with #2, I get a missing number error.
The code I am using:
\newcommand{\expcti}[2]{\operatorname{\mathbb{E}}_{#2}\expectiarg#1}
\DeclarePairedDelimiterX{\expectiarg}[1]{[}{]}{%
\ifnum\currentgrouptype=16 \else\begingroup\fi
\activatebar#1
\ifnum\currentgrouptype=16 \else\endgroup\fi
}
\newcommand{\innermid}{\nonscript\;\delimsize\vert\nonscript\;}
\newcommand{\activatebar}{%
\begingroup\lccode`\~=`\|
\lowercase{\endgroup\let~}\innermid
\mathcode`|=\string"8000
}
I am happy about any help here. Thanks a lot!
Edit:
What I am trying to achieve is a command which automatically scales the vertical bar in a conditional expectation with the parentheses, i.e. left what I get when simply using \left[ and \right] and right what I actually want:
I'd like to achieve the formula on the r.h.s. by typing $$\expcti*{\frac{1}{2} | Y}{F}$$


\DeclarePairedDelimitercan do it. Unrelated: the formula would look nicer with\mfrac{1}{2}(it is the medium-size fraction command fromnccmath). – Bernard Jul 16 '19 at 11:59\DeclarePairedDelimiterXPP. – Bernard Jul 16 '19 at 13:06