# How to create an expectation symbol that behave similarly to \sum? [duplicate]

### Introduction

This question is already asked here. If you want you could consider this one a duplicate. However, even if the proposed solution satisfied the one that posted the question, it doesn't completely satisfy me (and this is the reason for this duplicated question).

My aim is to declare a new operator for the expected value that behave like the summation symbol. The proposed solution is to declare it with \DeclareMathOperator*{}{} command (note the presence of the asterisk). This solution satisfies the feature of \sum like operators that put superscripts and subscripts in a different way depending on the current math mode. However, in \sum like operators, the size of the symbol itself change accordingly to the current math mode.

In the following a visual example that shows the difference between \sum and the new math operator. And this is the code to generate it:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\DeclareMathOperator*{\expec}{\mathbb{E}}

\begin{document}
$\sum_a x_a$ vs $\displaystyle \sum_a x_a$
~~~
$\expec_a x_a$ vs $\displaystyle \expec_a x_a$
\end{document}


### Real question

How could I define the new operator in order to scale it differently based on the current math mode?

Bonus question: I'm interested only in scaling the symbol. However, in some cases, one may want to use a different symbol (I'm thinking about the \int command, that in a lot of fonts use two different symbols for inline and display math). So, a solution that takes into account also this feature would be appreciated.

Of course, it could be that I miss something really obvious like that already exist a math operator for the expected value. In this case, I will appreciate if you notify me. However, the question remains valid for other new defined operators.

## marked as duplicate by moewe, Community♦Nov 24 '18 at 17:04

• @AlanMunn I was hoping that at least your linked question didn't provide an answer to my bonus question (that I added seconds later your comment) but I was wrong. The solution using \mathchoice covers also that issue. Should I mark it as a duplicate or should I delete it since there are no answer yet? – gvgramazio Nov 24 '18 at 16:53