# [texhax] Putting a prime on \sum

Philip G. Ratcliffe philip.ratcliffe at fastwebnet.it
Wed Jan 6 17:41:52 CET 2010

> I just got to this question so I don't know what the original
> was called.
> Knuth raised this very question in The TeXBook and answered
> it (Exercise
> 18.44).  The first answer was to use \mathop{{\sum}'}_... but
> that would
> have the slightly unfortunate side-effect of centering the
> subscript under
> the primed \sum, rather than under the \sum.  He then goes on
> the discuss
> a more complicated solution, which would not have that
> side-effect, but
> since the TeXBook is available online, I won't copy it.
>
> The following seemed to work too:
> \def\sumprime_#1{\mathop{\sum_{#1}}\nolimits'} $$\s$$
> $$\sumprime_{x\in A}$$ Perhaps someone well-versed in
> TeXarcana can explain why in Knuth's
> wolution, the prime comes out to the right while in mine, if
> you eliminate
> the \nolimits (that is, no limit switch), it comes out atop the
> summation.  Be that as it may, it appeared to work for me,
> without the
> unfortunate displacement of the subscript.  It has the
> requiring a subscript.  I have also not considered the
> problem of having
> also a superscript.  I guess you could use \@ifnextchar, with some

This solves some (but not all) of the problems inherent to this task:

\usepackage{mathtools}

\def\scriptafterop#1#2{\mathop{\smash{\mathrlap{#2\nolimits#1}}\phantom{#2}}
}

$$\scriptafterop{'}\sum_{k=1}^{\infty}$$

Cheers,  Phil