[texhax] Prime on \sum

Michael Barr barr at math.mcgill.ca
Sat Jan 9 22:52:47 CET 2010


Here are macros I have worked up to put a prime on a summation.

\documentclass{article}

\makeatletter
\newbox\sumstrutbox
\setbox0=\hbox{$\displaystyle\sum$}
\setbox\sumstrutbox = \hbox{\vrule height \ht0 width 0pt depth \dp0}
\def\sumstrut{\relax\ifmmode\copy\sumstrutbox\else\unhcopy\sumstrutbox\fi}

\def\@@sumprime_#1^#2{\sum_{#1}^{#2}\sumstrut'}
\def\@sumprime_#1{\@ifnextchar^{\@@sumprime_{#1}}{\@@sumprime_{#1}^{}}}
\def\sumprime{\@ifnextchar_{\@sumprime}{\@sumprime_{}}}
  \makeatother

\begin{document}

$$\sumprime_{n=1}^\infty$$
$$\sumprime_{n=1}$$
$$\sumprime^\infty$$

\end{document}

Note that a subscript, if any, must come first and then a superscript, if 
there is one.  You cannot write \sumprime^\infty_{n=1}.  I think there is 
some way of parsing the latter, but I don't know how.  The similarity of 
\sumstrut to Knuth's \strut will be obvious.

Michael Barr


More information about the texhax mailing list