47

How can i write my own math operator with limits? I want it to look like: \sum\limits_{e=1}^{m} but with a capital A (if possible bigger than the normal text) instead of the sum. Thanks for the help!

38

Use the \DeclareMathOperator* command provided by the amsmath package. Example:

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator*{\Aop}{A}
\begin{document}
\[ \Aop^a_b \]
\end{document}
| improve this answer | |
  • 3
    Where is the difference between \DeclareMathOperator* and \DeclareMathOperator? – Martin Thoma Jan 9 '16 at 21:53
  • 10
    @moose \DeclareMathOperator* will use limits so subscript/superscript will go directly below and above the symbol, while \DeclareMathOperator will not use limits and so subscript/superscript will go below right and above right. – Bakuriu Jan 30 '16 at 9:25
36

We can scale the symbol to the height plus depth of the summation and then vertically center it with respect to the formula axis.

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

\makeatletter
\DeclareRobustCommand\bigop[1]{%
  \mathop{\vphantom{\sum}\mathpalette\bigop@{#1}}\slimits@
}
\newcommand{\bigop@}[2]{%
  \vcenter{%
    \sbox\z@{$#1\sum$}%
    \hbox{\resizebox{\ifx#1\displaystyle.9\fi\dimexpr\ht\z@+\dp\z@}{!}{$\m@th#2$}}%
  }%
}
\makeatother

\newcommand{\bigstar}{\DOTSB\bigop{\star}}
\newcommand{\bigA}{\DOTSB\bigop{\mathrm{A}}}

\begin{document}
\[
\sum_{i=1}^n\bigA_{i=1}^n x_i\dots\bigstar_{i=1}^n x_i
\qquad
\textstyle
\sum\bigA\bigstar_{i=1}^n x_i
\qquad
\scriptstyle
\sum\bigA\bigstar_{i=1}^n x_i
\qquad
\scriptscriptstyle
\sum\bigA\bigstar_{i=1}^n x_i
\]
\end{document}

enter image description here

A simpler but not not scalable version (it won't work in

\newcommand{\opA}{\mathop{\vphantom{\sum}\mathchoice
  {\vcenter{\hbox{\huge A}}}
  {\vcenter{\hbox{\Large A}}}{\mathrm{A}}{\mathrm{A}}}\displaylimits}

In this way the "A" will be as large as the \sum symbol.

enter image description here

An enhanced version, where one can specify a correction factor for the big symbol in display style, as different symbols seem to require different factors.

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

\makeatletter
\DeclareRobustCommand\bigop[2][1]{%
  \mathop{\vphantom{\sum}\mathpalette\bigop@{{#1}{#2}}}\slimits@
}
\newcommand{\bigop@}[2]{\bigop@@#1#2}
\newcommand{\bigop@@}[3]{%
  \vcenter{%
    \sbox\z@{$#1\sum$}%
    \hbox{\resizebox{\ifx#1\displaystyle#2\fi\dimexpr\ht\z@+\dp\z@}{!}{$\m@th#3$}}%
  }%
}
\makeatother

\newcommand{\bigstar}{\DOTSB\bigop{\star}}
\newcommand{\bigA}{\DOTSB\bigop[0.92]{\mathrm{A}}}
\newcommand{\bigDelta}{\DOTSB\bigop[1.05]{\Delta}}

\begin{document}
\[
\sum_{i=1}^n\bigA_{i=1}^n\bigDelta_{i=1}^n x_i\dots\bigstar_{i=1}^n x_i
\]
\begin{center}
$\textstyle
\sum \bigA \bigstar \bigDelta_{i=1}^n x_i
\qquad
\scriptstyle
\sum \bigA \bigstar \bigDelta_{i=1}^n x_i
\qquad
\scriptscriptstyle
\sum \bigA \bigstar \bigDelta_{i=1}^n x_i
$
\end{center}
\end{document}

enter image description here

| improve this answer | |
  • I'd like to do the same but using \star. What are the 4 sizes used in the choice? I'd like to use \LARGE\star. Is there different sizes for display or inline math? – Sigur May 11 '15 at 13:48
  • @Sigur I added the code for the big star; I used just 90 percent of the size of a summation symbol, because the star has large overshoot. – egreg May 11 '15 at 15:21
  • thanks so much. Amazing and beautiful. Since I like to use \textstyle size in displayed mode (the \sum in displaystyle is too big in my opinion) should I use \vphantom{\textstyle\sum}? – Sigur May 11 '15 at 15:32
  • @Sigur Just use \mathop{\textstyle\bigstar} – egreg May 11 '15 at 15:37
  • sorry. Use it where? In the text body? If I well understood, you made a box with the same height as the one produced by \sum. But every time I use \sum in display mode I use \textstyle and \limits o make the summation smaller. I'd like to define the star symbol in such a way that I don't need to use \textstyle inside display mode. Simply \[ \bigstar_{i=1}^n\] with the same size as \[ \textstyle \bigstar\limits_{i=1}^n\]. – Sigur May 11 '15 at 15:43
10
\documentclass{article}
\usepackage{amsmath}
\def\Aop{\operatornamewithlimits{%
  \mathchoice{\vcenter{\hbox{\huge A}}}
             {\vcenter{\hbox{\Large A}}}
             {\mathrm{A}}
             {\mathrm{A}}}}
\begin{document}

\[ \Aop^a_b \sum_a^b \]

$ \Aop^a_b \sum_a^b $

\end{document}

enter image description here

| improve this answer | |
8

Use \mathop to turn A into a "math operator", and then use \limits to do sum-style limits:

 $$\mathop{A}\limits_{e=1}^{m}$$

Do you really want A, or do you want \bigwedge?

| improve this answer | |
6

egreg's answer is fine but works poorly for existing mathematical symbols. I recommend the following:

\newcommand{\operator}[1]{\mathop{\vphantom{\sum}\mathchoice
{\vcenter{\hbox{\huge $#1$}}}
{\vcenter{\hbox{\Large $#1$}}}{#1}{#1}}\displaylimits}

To define an operator 'A', you can now type

\newcommand{\opA}{\operator{\mathrm{A}}}

But you can also define an operator Theta:

\newcommand{\opTheta}{\operator{\Theta}}

Just remember that in the argument you pass to \operator, you are in math mode.

| improve this answer | |

Your Answer

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