[Tex/LaTex] How to make a math operator symbol be bigger in display math

displaystylemath-operators

I have an operator $\boxplus$ that works on an indexed collection of arguments, similar to $\sum$ or $\prod$ or $\bigoplus$.

The following makes the index ranges typeset nicely:

\usepackage{amsopn}
\DeclareMathOperator*{\op}{\boxplus}

But the size is still fixed, which looks wrong, especially in displaymath:

 $ \sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i $
$$ \sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i $$

How can I make appropriate sizes be used for inline math and displaymath,
like what happens automatically with $\sum$ and $\prod$ and $\bigoplus$?

Best Answer

One option using \mathchoice:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{calc}

\newcommand{\op}{
  \mathop{
    \vphantom{\bigoplus} 
    \mathchoice
      {\vcenter{\hbox{\resizebox{\widthof{$\displaystyle\bigoplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\bigoplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\scriptstyle\oplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\scriptscriptstyle\oplus$}}{!}{$\boxplus$}}}}
  }\displaylimits 
}

\begin{document}

\begin{gather*}
\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i \\
{\textstyle\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i } \\
A_{\sum_{i=1}^3 x_i} \quad A_{\bigoplus_{i=1}^3 x_i} \quad A_{\op_{i=1}^3 x_i} \\
 B_{A_{\sum_{i=1}^3 x_i}} \quad B_{A_{\bigoplus_{i=1}^3 x_i}} \quad B_{A_{\op_{i=1}^3 x_i}} 
\end{gather*}

\end{document}

enter image description here

Mostly equivalent macros with \mathpalette, that avoids code duplication. There are other small fixes.

\makeatletter
\newcommand*{\op}{%
  \DOTSB
  \mathop{\vphantom{\bigoplus}\mathpalette\matt@op\relax}%
  \slimits@
}
\newcommand\matt@op[2]{%
  \vcenter{\m@th\hbox{\resizebox{\widthof{$#1\bigoplus$}}{!}{$\boxplus$}}}%
}
\makeatother