8

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$?

6

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
  • 2
    Two suggestions: (i) Use \vcenter{\hbox{...}} instead \raisebox{<offset amount>}{...}. (ii) For the scriptstyle and scriptstyle cases, use \oplus rather than \bigoplus in the \widthof calculations. – Mico Sep 23 '15 at 3:12
  • @Mico Both suggestions incorporated. Thanks. – Gonzalo Medina Sep 23 '15 at 17:11
  • 1
    Add also \vphantom{\bigoplus} as the limits are badly placed in the current version. – egreg Sep 23 '15 at 17:25
4

For simple geometric shapes, picture mode is invaluable:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pict2e}

\makeatletter
\newcommand*{\bigboxplus}{\DOTSB\mathop{\mathpalette\big@boxplus\relax}\slimits@}

\newcommand{\big@boxplus}[2]{%
  \vcenter{%
    \m@th\bigbox@thickness{#1}%
    \sbox\z@{$#1\bigoplus$}%
    \dimen@=\ht\z@ \advance\dimen@\dp\z@
    \hbox{%
      \setlength{\unitlength}{\dimen@}%
      \begin{picture}(1,1)
      \polyline(0.1,0.1)(0.9,0.1)(0.9,0.9)(0.1,0.9)(0.1,0.1)(0.5,0.1)
      \polyline(0.5,0.1)(0.5,0.9)
      \polyline(0.1,0.5)(0.9,0.5)
      \end{picture}%
    }%
  }%
}

\newcommand{\bigbox@thickness}[1]{%
  \ifx#1\displaystyle
    \linethickness{0.2ex}%
  \else
    \ifx#1\textstyle
      \linethickness{0.16ex}%
    \else
      \ifx#1\scriptstyle
        \linethickness{0.12ex}%
      \else
        \linethickness{0.1ex}%
      \fi
    \fi
  \fi
}
\makeatother

\begin{document}

\begin{gather*}
\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \bigboxplus_{i=1}^3 x_i \\
{\textstyle\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \bigboxplus_{i=1}^3 x_i } \\
A_{\sum_{i=1}^3 x_i} \quad A_{\bigoplus_{i=1}^3 x_i} \quad A_{\bigboxplus_{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_{\bigboxplus_{i=1}^3 x_i}} 
\end{gather*}

\end{document}

enter image description here

  • Interesting! Motivates one to stick with piecewise linear fonts... ;) – Matt Sep 24 '15 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.