# \mathop in sums and limits

What is the \mathop command meant to be, officially?

I see it used in indexes of sums and limits to improve the spacing, e.g.

\sum_{n\mathop = 1}^\infty a_n


Why doesn't it just format it like this automatically? It looks so much better.

-
You (or they) are doing it wrong... that is, the use of \mathop. Indices are set with different spacing around the relations/operators. You can use n\,=\,1 to get the same effect. – Werner Apr 16 '14 at 5:57
@Werner Why exactly is it wrong? Is this using \mathop or trying to change the spacing at all? – bwv869 Apr 16 '14 at 5:59
\mathop is meant to temporarily define a math operator (or function, say, like sup or inf or argmax/argmin), and here = is a relation. So, while the spacing better spacing may be achieved, the usage is technically incorrect. – Werner Apr 16 '14 at 6:05

TeX sets \thickmuskip between the relational operator and most other math atoms in styles \displaystyle and \textstyle, but no space in script styles \scriptstyle and \scriptscriptstyle.

A \thinspace is also inserted in script styles between an operator atom (\mathop) and an ordinary atom (\mathord). Thus

\sum_{n \mathop{=} 1}


gets you the desired spacing:

However:

• The relational symbol becomes an operator, a violation of a clean markup.
• The spacing is too small in \displaystyle and \textstyle.
• \mathop vertically centers the symbol, e.g.:

\sum_{n \mathop{.} 1}


The dot is moved to the math axis and becomes a "\cdot".

This is not a problem for the equals sign, because this is usually already centered around the math axis.

The spacing can be manually fixed by adding \, as suggested in Werner's comment:

\sum_{n \,=\, 1}


• It's more to the point.
• Shorter for typing.

• Too large space in \displaystyle and \textstyle

There is a trick to circumvent the latter: \nonscript suppresses the following space in the script styles.

\documentclass{article}

\newcommand*{\mrel}[1]{%
\mskip\thinmuskip
\nonscript\mskip-\thinmuskip
\mathrel{#1}%
\mskip\thinmuskip
\nonscript\mskip-\thinmuskip
}
\begin{document}
$\sum_{n \mrel= 1} \mrel= 1$
\end{document}


\thinmuskip is added in script styles, otherwise it is canceled by -\thinmuskip.

## LuaTeX

In LuaTeX the spacings between the math atoms can be configured very deeply. Also the cramped styles are available as commands. Cramped styles are used, if something is above the expression (denominator, \sqrt, ...). Then superscripts are lowered a bit. Cramped style is used in the subscript of \sum.

The following example configures a thin space between math atoms in \scriptstyle and cramped \scriptstyle, where a thick space would be set in \textstyle or \displaystyle.

 \documentclass{article}

\usepackage{ifluatex}
\makeatletter
\ifluatex
\def\@tempa#1#2#3{%
\csname luatexUmath#1#2spacing\endcsname\luatexcrampedscriptstyle=#3\relax
\csname luatexUmath#1#2spacing\endcsname\scriptstyle=#3\relax
}%
\@for\@tempb:={ord,op,close,inner}\do{%
\@tempa\@tempb{rel}\thinmuskip
}%
\@for\@tempb:={ord,op,open,inner}\do{%
\@tempa{rel}\@tempb\thinmuskip
}%
\fi
\makeatother

\begin{document}
$\sum_{n = 1}^{n = 1}$
\end{document}


Remarks:

• LuaLaTeX uses a prefix luatex for new LuaTeX commands to avoid name clashes with existing macros.
• There are 16 settings. The \@for loops avoid a long list of assignments.
-
Thanks! Would using \mathop also be incorrect in this context: \lim_{x\mathop \to \infty} f(x) ? I will use \, from now on, I don't actually see a difference in displaystyle. – bwv869 Apr 16 '14 at 7:47
@Oliver: At least \to is usually already vertically centered. In \displaystyle the space around = as \mathrel is larger than around = as \mathop. – Heiko Oberdiek Apr 16 '14 at 7:58

as stated by Werner in a comment, \mathop is intended to define operators like lim et al., while = is a relation.

as for the spacing, that was determined through knuth's examination of numerous examples published in the most carefully typeset journals of the early 20th century. these publications are cited in various writings by knuth. i recommend particularly his Gibbs lecture, published in the bulletin of the american mathematical society. (i'm not in a position to give a link right now, but it should be easy to find using google.)

-
Can't find it on google or youtube unfortunately - would like to see it. – bwv869 Apr 16 '14 at 8:01
this is how to find it. (the tool i'm using doesn't show full urls, so i have to give a recipe.) go to ams.org/bull and choose "all available volumes". then choose year 1979, volume 1, issue 2, and search through the contents list for the article by knuth. (if someone can put the correct url into my answer, please do; i won't be able to until next month.) – barbara beeton Apr 16 '14 at 8:14
@Oliver -- thanks for the link. – barbara beeton Apr 16 '14 at 8:30

Here are four strategies. The first is what I like the best.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\su}[1]{%
\text{\thickmuskip=3mu$#1$}%
}

\begin{document}
\begin{alignat*}{2}
&\text{Normal: }   && \sum_{k=1}^{m}a_{k}\\
&\text{Modified: } && \sum_{\text{$k=1$}}^{m}a_{k}\\
&\text{Thin space: } && \sum_{k\,=\,1}^{m}a_{k}\\
&\text{Command: } && \sum_\su{k=1}^{m}a_{k}
\end{alignat*}
\end{document}


-
Thanks. It's not as obvious close up but from a distance it seems obvious that the third is superior to the first, e.g. quickpic.info/z/i6.jpg – bwv869 Apr 16 '14 at 12:15