Fix the size of variable-size operators

renewcommandscalerelsize;

When using variable-size operators such as \prod, \sum, \bigcup, and \bigcap, their sizes are usually not quite predictable, which makes me pretty annoyed. I just want to make their sizes fixed throughout the document, e.g., the same vertical size as X_{1}^{1}.

I tried to renew the definition of \prod using \renewcommand and scalerel package:

\renewcommand{\prod}{{\scalerel*{\prod}{X_{1}^{1}}}}

but it throws an error:

TeX capacity exceeded, sorry [grouping levels=255]. \prod

It should be allowed to use \limits to put limits on the top and bottom of the symbol in display mode.

Any comment on this issue?

Edit:

I prepared an example demonstrating the issue:

\documentclass{article}

\usepackage{amsmath}
\usepackage{scalerel}

\newcommand{\set}[2]{\left\{{#1}~\middle|~{#2}\right\}}

\begin{document}
    \begin{equation*}
        \prod_{\alpha \in A} X_{\alpha}
        =
        \set{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}
    \end{equation*}

    \begin{equation*}
        \begin{array}{r@{~}l}
            \prod_{\alpha \in A} X_{\alpha}
            &=
            \set{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}\\
            &=
            \set{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}
        \end{array}
    \end{equation*}

    The above two equations show the inconsistent sizing of operators.

    \newcommand{\prode}{\mathop{\scalerel*{\prod}{X_{1}^{1}}}}
    \newcommand{\bigcupe}{\mathop{\scalerel*{\bigcup}{X_{1}^{1}}}}

    The desired result is
    \begin{equation*}
        \begin{array}{r@{~}l}
            \prode\limits_{\alpha \in A} X_{\alpha}
            =
            \set{x \in A\to \bigcupe\limits_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}
        \end{array}
    \end{equation*}
\end{document}

enter image description here

In the last equation, I defined \prode and \bigcupe. But I just want to renew \prod and \bigcup. I think the error is caused by infinite loops.

Found solution:

I solved the problem by using \let found in Can I redefine a command to contain itself?

\let\oldprod\prod
\renewcommand{\prod}{\mathop{\scalerel*{\oldprod}{X_{1}^{1}}}}
\let\oldbigcup\bigcup
\renewcommand{\bigcup}{\mathop{\scalerel*{\oldbigcup}{X_{1}^{1}}}}

Thank you!

Best Answer

The size is predictable and it follows the typographic traditions.

Anyway, here's a way to reduce the size in display style to be the same as in text style.

I take advantage from the fact that big operators are defined in a uniform way by amsmath, using a common template and the operator \xyz refers internally to \xyz@.

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn
\NewDocumentCommand{\reduceoperators}{m}
 {
  \clist_map_function:nN { #1 } \hermis_reduceoperator:n
 }

\cs_new_protected:Nn \hermis_reduceoperator:n
 {
  \cs_set_eq:cc { latex@#1@ } { #1@ }
  \cs_set_protected:cpx { #1@ }
   {
    \mathop
     {
      \mathchoice
      {\textstyle\use:c{latex@#1@}}
      {\use:c{latex@#1@}}
      {\use:c{latex@#1@}}
      {\use:c{latex@#1@}}
     }
   }
 }
\ExplSyntaxOff

\reduceoperators{sum,prod,bigcup,bigcap}

\begin{document}

\begin{gather*}
\tag{samples}
\sum\prod\bigcup\bigcap
\\[4ex]
\tag{good}
\prod_{\alpha \in A} X_{\alpha} =
\bigl\{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}
  \bigm| \forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}\bigr\}
\\
\tag{bad}
\prod_{\alpha \in A} X_{\alpha} =
\Bigl\{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}
  \Bigm| \forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}\Bigr\}
\\
\tag{ugly}
\prod_{\alpha \in A} X_{\alpha} =
\left\{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}
  \;\middle|\; \forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}\right\}
\end{gather*}

\end{document}

The idea is to save the meaning of \sum@ into \latex@sum and then redefining \sum@ to mean

\mathop\mathchoice{\textstyle\latex@sum@}{\latex@sum@}{\latex@sum@}{\latex@sum@}

so in display style we actually use the \textstyle version. With the help of expl3 trickery, we're able to do all the needed redefinitions at once with no code duplication.

I also take the occasion to show how your definition of \set with \left and \right is not really good. For the expression you have \big size is more than enough: already \Big size is too much.

enter image description here

Related Question