I'm trying to create a summation command that formats it better than just using \sum, and without having to use \sum\limits_a^b every time. I'm using

     \sum\limits_{#1 = #2}^{#3}

The else part doesn't work. If I use \summ{1}{2}, I get

enter image description here

which is as expected. but if I use \summ{1}{2}{3}, I get

enter image description here

which is not right. What am I doing wrong?

  • Welcome to TeX.SE.
    – Mico
    Jan 19, 2021 at 19:31
  • 1
    If I understand the definition of \summ correctly, it takes 3 arguments, the first of which is optional (and defaults to \@nil). If this understanding is correct, you may want to change \summ{1}{2}{3} to \summ[i]{1}{2}, say, as the first, optional parameter has to be encased in square brackets, not curly braces.
    – Mico
    Jan 19, 2021 at 19:38
  • Also, you're comparing \tmp to \@nnil yet you're setting \tmp to \@nil. While they may be similar, other packages could define \@nnil at which point your macro would fail. So, make sure you're comparing \tmp to \@nil (what you're supplying in your default for the optional argument) and not something else.
    – Werner
    Jan 19, 2021 at 19:56
  • why do you ever need \sum\limits ? if you want, for some reason \sum to take limits even in inline math just add \limits to its definition. But you basically then can not use \sum in inline math at all. Jan 19, 2021 at 20:23

1 Answer 1


The way you've set up the macro \summ, taking 1 optional and 2 required arguments, you probably shouldn't write \summ{1}{2}{3}; instead, do give \summ[i]{1}{2} a try. You'll find out that it expands to \sum\limits_{i=1}^{2}.

I think that defining \summ to take an optional argument is unnecessarily complicated. How about dropping the conditional and simply setting


That way, it's no big deal to switch from \summ{1}{N} to \summ{i=1}{N}, is it?

A full MWE:

$\summ{1}{N} \quad \summ{i=1}{N}$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .