1

I have to use a lot of sums in exponential functions like

enter image description here

I would like to have the summation indices of sums to be displayed below the sums for increased readability. I know that I can achieve this for a single sum by placing \limits. Is there also a global solution for all math environments (of course beside inline math)?


Examples why I prefer to use an exponent instead the exponential function.
This: enter image description here uses less horizontal space than this: enter image description here But is in my opinion just as readable. The second case however will force me to put additional line-breaks or define further abbreviations.

DerWeh
  • 320
  • 6
    For decreased readability, you mean… – egreg Jan 27 '18 at 15:51
  • 5
    And we remember e^{...} us mathematically the same as \exp(...), so use the other form. – daleif Jan 27 '18 at 15:58
  • 2
    You could define \newcommand{\suml}{\sum\limits}, but the result is not at all pretty. It is not already without \limits. – egreg Jan 27 '18 at 16:13
  • I am aware that e^{.} \equiv \exp(.) however it is convention to use e^{.}. Mostly likely because it is denser and you need wait to many splits using \exp. \newcommand{\suml}{\sum\limits} was also what I thought of, but I thought there simply must be a more elegant and consistent way to do this in Latex. – DerWeh Jan 27 '18 at 18:06
  • 1
    This is in no way more elegant. The exp can be broken if needed the e^{...} cannot, a big minus in my book. The only time we've used e^ exclusively was in some material for biologists as they are often not aware of the exp, they could also not understand the nolimit version of sum. I'd like to know the field you are working in. Where I work, it took me several years to get some "traditions" changed for things more readable to the end user. – daleif Jan 27 '18 at 22:16
  • I was playing with an old manuscript once (we were considering republishing it. In it the author used \hat{...} to mean something specific (like a conjugate in linear algebra). That was fine on an A, but almost invisible when applied to an actual 3x3 matrix (no use if widehat). I now thus this example when I explain to students (often from physics), that having these very short syntaxes are fine in some contexts, but utter rubbish in others, better to have two syntaxes for it. – daleif Jan 27 '18 at 22:22
  • I am always open for better notations, however breaking conventions always needs a very good reason, or it won't be accepted by the community. In my case I find the superscript notation even more readable as it uses less horizontal space. I included for you @daleif a real-life example. – DerWeh Jan 28 '18 at 16:02
  • 1
    I have to say that I do not agree, students will easily forget the e in the superscript case. And the missing possibility to manually break the exponent is a no go for me. Btw consider manually scaling the ()'s in this case, it looks better and uses less vertical space – daleif Jan 28 '18 at 16:21
  • I think you have to define the exponents separately, say M and then simply write e^M. This is just unreadable and unbalanced math line. It looks like something went wrong at the publisher at around the center of the line. Upright serifs with calligraphical letters with regular slanted variables. It's just a mismash. – percusse Jan 28 '18 at 16:45
  • @daleif Sorry what do you mean by the missing possibility to manually break the exponent? – DerWeh Jan 28 '18 at 17:22
  • 1
    @percusse I agree that it is preferable to introduce a new quantity. However, I am doing mathematical conversions here. So it is not possible in many places (e.g. the example as you need to see the Gaussian integration). I don't see what is wrong with the typesetting. It variables are supposed to be italic, while things like exp and d are required to be upright. – DerWeh Jan 28 '18 at 17:27
  • 1
    If the exponent is too long for the line, you have no good way to break it. The exp method for complicated formulas can always be broken on several pages – daleif Jan 28 '18 at 17:31
  • 2
    There are no conventions on math typography other than trying to mimic old books in the name of math snobbery which I was also guilty of for some time. Only readability matters. Some old books are just horrible how rigorous they are. – percusse Jan 28 '18 at 17:46
  • 2
    +1 for that the question is well-stated. However, the idea is insane as the ligibility will be very low. – yo' Jan 28 '18 at 19:27

2 Answers2

3

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}

output

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 @
Circumscribe
  • 10,856
  • I think you could use (with amsmath) \def\sum{\DOTSB\sum@\limits} sparing you definition of \sum@beforelimitmodification (untested, just looking at amsmath.dtx) (now tested, seems ok) –  Dec 31 '18 at 15:07
  • another +1 for correct handling of \everydisplay many answers simply overwrite it... –  Dec 31 '18 at 15:09
  • @jfbu: I actually used \edef\sum{\sum\limits} before (also works with amsmath, not without), but decided to post a solution that can easily be adapted to work for other symbols. – Circumscribe Dec 31 '18 at 15:10
  • ok, the amsmath has not only \sum@ but \coprod@, ..., \prod@,....\bigsqcup@ –  Dec 31 '18 at 15:11
  • @jfbu: I actually decided to overhaul the answer somewhat. I think the solution that uses \if@display is superior to the one with \everydisplay (even though \if@display is also defined through \everydisplay). I am now using \sum@ and I also added another solution that affects all operators, and which I only thought of some moments ago. – Circumscribe Dec 31 '18 at 16:42
  • looks like a good idea, see you next year! –  Dec 31 '18 at 19:37
  • How can I get this to work for integrals? And with unicode-math? ANSWER: See https://tex.stackexchange.com/a/65335/105570 – Jollywatt Jan 15 '22 at 03:24
-1

I'm still pretty new to latex so forgive me then correct me if I'm wrong.

When the \sum_{min}^{max} command is used in \displaystyle the produced text shows the symbols as you want it with the indices above and below the large, capital Greek sigma. https://www.sharelatex.com/learn/Integrals,_sums_and_limits

However even when your entire equation is in \displaystyle some parts might still render in \textstyle. When \texstyle\sum_{min}^{max} is called the result is the sigma symbol with adjacent indices. To force the summation symbol to always have the indices above and below the sigma you'll have to force the \sum command to be \displaystyle\sum. If you only have one or two summations the easiest way to achieve this is simply to add the \displaystyle command. However when you have a large scientific document this becomes tedious.

In cases where you want all your summations to have the indices above and below (as you have it in your crazy equation examples) the simplest way is to instruct latex to always render \sum as \dispaystyle\sum. this can be done by redefining \sum to be \displaystyle\sum by adding this to your preamble:

\let\oldsum\sum
\renewcommand{\sum}{\displaystyle\oldsum}

(credit to this guy https://latex.org/forum/viewtopic.php?t=14345).

Take note that this solution will force the \sum to always be in \display even when you are adding inline math so this solution is not perfect. You can however still call the old version of \sum (i.e. \oldsum) for inline cases.

The same thing happens to integrals and products and the same solution should work (although I did not test it on anything other that the \sum command)

\let\oldsum\sum
\renewcommand{\sum}{\displaystyle\oldsum}
$$
y = \frac{\sum{x}}{\sum_{i}^{\infty}{x_i}}
\cdot
\frac{\oldsum{x}}{\oldsum_{i}^{\infty}{x_i}}
$$

shows up as

enter image description here

For completeness I should mention that the same can be achieved by using the \limits command as mentioned in the sharelatex article referenced above.

Stefan Pinnow
  • 29,535
  • 2
    This old question just got bumped to the home page. And this answer has so many things wrong with it, I hardly know where to begin. First, \displaystyle and \textstyle are declarations. Their effect lasts until the end of the current group, end of formula, or next explicit style change. So redefining \sum in the way of this answer is quite counterproductive. Look to this answer for a much better explanation. And read the comments on the question above for the typographical issues and why this is generally a bad idea. – Harald Hanche-Olsen Jul 29 '18 at 19:45