[texhax] Prime on \sum
Philip G. Ratcliffe
philip.ratcliffe at fastwebnet.it
Sun Jan 10 12:33:29 CET 2010
> 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 following solves the ordering problem:
\makeatletter
\def\@@sumprimea_#1^#2{\sum_{#1}^{#2}\sumstrut'}
\def\@sumprimea_#1{\@ifnextchar^{\@@sumprimea_{#1}}{\@@sumprimea_{#1}^{}}}
\def\@@sumprimeb^#1_#2{\sum^{#1}_{#2}\sumstrut'}
\def\@sumprimeb^#1{\@ifnextchar_{\@@sumprimeb^{#1}}{\@@sumprimeb^{#1}_{}}}
\def\sumprime{\@ifnextchar_{\@sumprimea}{\@sumprimeb}}
\makeatother
> The similarity of
> \sumstrut to Knuth's \strut will be obvious.
And this is a slightly more economical and general sum strut:
\def\sumstrut{\mathop{\vphantom{\sum}}\nolimits}
Note, however, there is extra horizontal space between the sum and prime
with respect to what is obtained from \sum\nolimits', which my first
solution avoided. Note also what happens to, eg,
$$\sumprime^{\infty\times\infty}$$; again, my first solution avoids this
problem, as does the following (which also solves the height problem):
\def\sumprime{\mathop{\sum\!\smash{\mathop{\vphantom{\sum}}\nolimits'}}}
Cheers, Phil
More information about the texhax
mailing list