2

Consider the following MWE which uses \sideset from AMS math to typeset a primed summation with an upper limit:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\[
 \sideset{}{'}\sum_{i=0}^m x = \sum_{i=-1}^{m} x
\]
\end{document}

where it is evident that the vertical placement of the upper limit of the sum, m, is different for the primed and non-primed summations. Is there a simple means, in the case where the upper limit does not impinge on the limits introduced by sideset, to have these both typeset consistently?

4

Not pretty:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\[
 \mathop{\smash{\sideset{}{'}\sum}\vphantom{\sum}}\limits_{i=0}^m x = \sum_{i=-1}^{m} x
\]
\end{document}

enter image description here

The same idea, but better integrated with amsmath:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\psum}{%
  \DOTSB\mathop{%
    \smash{\sideset{}{'}\sum}%
    \vphantom{\sum}%
  }\slimits@
}
\makeatother

\begin{document}
\[
\psum_{i=0}^m x = \sum_{i=-1}^{m} x
\]
\end{document}

A more complicated solution for making TeX into believing that the summation symbol has the right width.

\documentclass{article}
\usepackage{amsmath,xparse}

\makeatletter
\newcommand{\psum}{\DOTSB\psum@}
\NewDocumentCommand{\psum@}{e{_^}}{%
  \sbox\z@{$\m@th\displaystyle'$}\kern-\wd\z@\!%
  \mathop{%
    \kern\wd\z@
    \smash{\sideset{}{'}\sum}%
    \vphantom{\sum}%
  }\psum@scripts#1%
}
\NewDocumentCommand{\psum@scripts}{mm}{%
  \slimits@\IfValueT{#1}{_{#1}}\IfValueT{#2}{^{#2}}%
}
\makeatother

\begin{document}

\begin{gather*}
\psum_{i=0}^m x = \sum_{i=-1}^{m} x
\\
\sum_{i=-1}^{m} x = \psum^m_{i=0} x
\end{gather*}

\end{document}

In the example you see that you can input subscript and superscript in any order.

Update

With more recent version of xparse, the above code should be changed.

\documentclass{article}
\usepackage{amsmath,xparse}

\makeatletter
\newcommand{\psum}{\DOTSB\psum@}
\NewDocumentCommand{\psum@}{e{_^}}{%
  \sbox\z@{$\m@th\displaystyle'$}\kern-\wd\z@\!%
  \mathop{%
    \kern\wd\z@
    \smash{\sideset{}{'}\sum}%
    \vphantom{\sum}%
  }\slimits@\IfValueT{#1}{_{#1}}\IfValueT{#2}{^{#2}}%
}
\makeatother

\begin{document}

\begin{gather*}
\psum_{i=0}^m x = \sum_{i=-1}^{m} x
\\
\sum_{i=-1}^{m} x = \psum^m_{i=0} x
\end{gather*}

\end{document}

enter image description here

  • One quirk, which is hard to see at lower resolutions, is that the m for the primed summation is shifted right related to the regular sum. I am unsure what is causing this, however. – Freddie Witherden Dec 9 '16 at 1:35
  • @FreddieWitherden Yes, the width of the prime was taken into account. The new code should be what you wish. – egreg Dec 9 '16 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.