3

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!

Hermis14
  • 423
  • On what basis do you rest your claim that the "sizes [of \sum and \prod] are usually not quite predictable"? FWIW, as long as you understand the difference between display math mode and inline math mode, there's absolutely nothing unpredictable about the sizes of \sum and \prod. – Mico Nov 22 '21 at 20:58
  • what do you mean by not predicatable? \sum (and all the others) come in exactly two sizes, one for textstyle inline math and one for displaystyle. what is annoying you about that? Your redefinition is defining \prod in terms of itself so is an infinite loop, but the definition is not necessary. – David Carlisle Nov 22 '21 at 21:06
  • I don't think this is a duplicate of that generic question: there are sum subtle points here that make applying those methods awkward. – egreg Nov 22 '21 at 21:28
  • @egreg I agree but someone flagged this as a duplicate... – Hermis14 Nov 22 '21 at 21:31
  • @Hermis14 Let's wait for it to be reopened. In the meantime, I warn you against defining \set that way: the size of the braces and of the middle bar is way too big. – egreg Nov 22 '21 at 21:33
  • @egreg In fact scalerel works as expected except that it does not apply consistently both to the inline math and display mode. – Hermis14 Nov 22 '21 at 21:33
  • @Hermis14 And the “solution” you came up with is very suboptimal. – egreg Nov 22 '21 at 21:34
  • you are misusing array which is intended for typesetting matrices and sets its content in inline mode if you used display math the operators would be display size in all cases and you would not be tempted to use \scalerel` – David Carlisle Nov 22 '21 at 22:12
  • @DavidCarlisle That's a very important point I was not aware of... Thank you! Then, should I use the split environment in place of array? – Hermis14 Nov 22 '21 at 22:24
  • aligned see my answer – David Carlisle Nov 22 '21 at 22:27

2 Answers2

4

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

egreg
  • 1,121,712
2

The above two equations show the inconsistent sizing of operators.

The inconsistency is due to the misuse of the array environment which is not designed for displayed equations, but for typesetting matrices: it sets its content in textstyle not displaystyle.

If you use a display alignment then the operators use a consistent style.

enter image description here

However the delimiters here are far too large. You can modify the set command to take an optional size.

enter image description here

\documentclass{article}

\usepackage{mathtools}

\newcommand{\set}[3][]{\mathopen{#1{}{#2}~#1|~{#3}\mathclose{#1}}}

\begin{document} \begin{equation} \prod_{\alpha \in A} X_{\alpha} = \set[\Big]{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{aligned}
        \prod_{\alpha \in A} X_{\alpha}
        &=
        \set[\Big]{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}\\
        &=
        \set[\Big]{x \in A\to \bigcup_{\alpha\in A} X_{\alpha}}{\forall \alpha \in A: x_{\alpha} = x(\alpha) \in X_{\alpha}}
    \end{aligned}
\end{equation*}

\end{document}

David Carlisle
  • 757,742
  • I like your answer, too, especially for handling the size of the delimiter and braces of a set. The comment on the difference between array and aligned is also nice. I wish I could have chosen both answers! – Hermis14 Nov 22 '21 at 23:08
  • @Hermis14 when in doubt between me and egreg then naturally there is a right choice and a wrong choice:-) – David Carlisle Nov 22 '21 at 23:32