This question already has an answer here:


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:


$\sum_a x_a$ vs $\displaystyle \sum_a x_a$
$\expec_a x_a$ vs $\displaystyle \expec_a x_a$

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    I think the relevant duplicate is here: How are big operators defined? – Alan Munn Nov 24 '18 at 16:41
  • @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
  • 2
    There is no need to delete the question, but you can agree with the duplicate vote to close it as a duplicate. The advantage over just deleting is that your question remains searchable and might help others with a similar problem find the answer. – moewe Nov 24 '18 at 17:05
  • I think that tex.stackexchange.com/q/23432 is a better duplicate – egreg Nov 24 '18 at 19:01

Browse other questions tagged or ask your own question.