Only changing the limits for \sum
:
You could use the internal conditional \if@display
from amsmath
to test whether or not \limits
should be inserted.
Below, I'm redefining \sum
by adding \if@display\limits\fi
to its definition.
\documentclass{article}
\usepackage{amsmath}
\makeatletter %% <- make @ usable in command names
\renewcommand*\sum{\DOTSB\sum@\if@display\limits\fi}
\makeatother %% <- revert @
\begin{document}
Lorem $e^{\sum_{n=1}^\infty \frac1n}$ ipsum
\[
e^{\sum_{n=1}^\infty \frac1n}
\]
\begin{align}
e^{\sum_{n=1}^\infty \frac1n}&
\\
&e^{\sum_{n=1}^\infty \frac1n}
\end{align}
Lorem $e^{\sum_{n=1}^\infty \frac1n}$ ipsum
\end{document}
This can be adapted to work for other operators like \prod
, \coprod
, \bigcup
, \bigotimes
, etc. by changing \sum@
in the obvious way.
If you have an operator, say \myoperator
, for which \myoperator@
does not exist, you can create it with
\makeatletter %% <- remove if you paste the next line between \makeatletter/-other
\let\myoperator@\myoperator
\makeatother %% <- remove this one too, then
and proceed as above.
Alternative:
I originally had another solution that I was quite happy with that uses \everydisplay
.
The contents of this register is inserted at the start of every display math environment and I used it to redefine \sum
by including \limits
.
It works without amsmath
(which everyone should use), but apart from that I think it's superceded by the solution above.
Anyway, here it is.
The following would replace the \makeatletter
-\makeatother
block above.
\makeatletter %% <- make @ usable in command names
\let\sum@beforelimitmodification\sum
\everydisplay\expandafter{\the\everydisplay %% <- old \everydisplay
\renewcommand*\sum{\sum@beforelimitmodification\limits}% %% <- new addition
}
\makeatother %% <- revert @
Changing the limits for all operators:
I just thought of another completely different method that affects all big operators (compatible with \amsmath
) at once.
With amsmath
loaded, all big operators (apart from integrals) include \slimits@
in their definition, which simply expands to \displaylimits
(which acts as \limits
in \displaystyle
and does nothing in other math styles).
By redefining it, you can give all operators used in display environments limits.
\documentclass{article}
\usepackage{amsmath}
\makeatletter %% <- make @ usable in command names
\renewcommand*\slimits@{\if@display\limits\else\displaylimits\fi}
\makeatother %% <- revert @
\begin{document}
Lorem $e^{\sum_{n=1}^\infty \frac1n}$ ipsum
\[
e^{\sum_{n=1}^\infty \frac1n}
\]
\begin{align}
e^{\sum_{n=1}^\infty \frac1n}&
\\
&e^{\sum_{n=1}^\infty \frac1n}
\end{align}
Lorem $e^{\sum_{n=1}^\infty \frac1n}$ ipsum
\end{document}
↑↑ Output looks identical, so see the image above ↑↑
If this doesn't work for some custom defined operator, say \myoperator
, you should add \slimits@
to its definition, like this:
\makeatletter %% <- make @ usable in command names
\let\myoperator@beforelimitchange
\renewcommand*\myoperator{\DOTSB\myoperator@beforelimitchange\slimits@}
\makeatother %% <- revert @
e^{...}
us mathematically the same as\exp(...)
, so use the other form.\newcommand{\suml}{\sum\limits}
, but the result is not at all pretty. It is not already without\limits
.