# Custom Math Symbol - Two Sigma Sums

I'd like to be able to set a new math command/macro that is a Sigma shifted slightly (diagonal) on top of another Sigma, but am unsure how to go about it. I'd like it to behave just as a single Sigma in terms of limits being above and below in equations, and to the side when inline. If it's easier, I really only care for the equation behavior. A depiction of the symbol is the following:

• \usepackage[bbgreekl]{mathbbol} will define a blackboard bold (doublestruck) Sigma: \mathbb{\Sigma}. Certainly not what you asked for, but possibly of interest. – Chris Chudzicki May 1 '17 at 17:03
• \sum_{i,j}^{N,D} would be much cleaner. – Andrew Swann May 1 '17 at 18:00

At its simplest, with a stack.

EDITED to preserve the math style of the \sums:

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\doublesum{\mathop{\ThisStyle{\ensurestackMath{%
\stackengine{.3ex}{\SavedStyle\,\sum}{\SavedStyle\sum}{O}{l}{F}{F}{L}}}}}
\begin{document}
\centering
$\doublesum_{ij}^{ND} x_{ij} = 0$
$$\doublesum_{ij}^{ND} x_{ij} = 0$$
\end{document}


One can, of course, opt to place a comma or small gap between the respective indices and upper limits. Alternately, one can employ a more complex manipulation to vertically stagger the indices, which are now passed as four mandatory arguments:

\documentclass{article}
\usepackage{stackengine,scalerel,amsmath}
\newcommand\doublesum[4]{\ThisStyle{\ensurestackMath{\mathop{%
{\stackengine{.3ex}{\SavedStyle\,\sum}{\SavedStyle\sum}{O}{l}{F}{F}{L}}}
_{\stackengine{.3ex}{\SavedStyle_{\phantom{#1}#2}}{%
\SavedStyle_{#1}}{O}{l}{F}{F}{L}}
^{\stackengine{.3ex}{\SavedStyle_{#3}}{%
\SavedStyle_{\phantom{#3}#4}}{U}{l}{F}{F}{L}}}}}
\begin{document}
\centering
$\doublesum{i}{j}{N}{D} x_{ij} = 0$
$$\doublesum{i}{j}{N}{D} x_{ij} = 0$$
\end{document}


• I was exactly going to say that you need to honor the current math style: may I suggest that you remove the first version of your answer altogether? – GuM May 1 '17 at 16:54
• I like how slick this is! What does \ThisStyle and \SavedStyle do? I'd like to understand this construction :). – Captain Morgan May 1 '17 at 17:14
• @CaptainMorgan \ThisStyle and \SavedStyle are part of the scalerel package, and allow the current math style to be saved with the invocation of \ThisStyle and redeployed (in its argument) at the invocation of \SavedStyle. It is used in places where the math style would otherwise be lost, for example, inside of LaTeX boxes, such as employed by stackengine. Also, please see extended answer. – Steven B. Segletes May 1 '17 at 17:19
• @CaptainMorgan See this answer, tex.stackexchange.com/questions/43978/proper-use-of-mathchoice/…, which inspired the extension of the scalerel package to include \ThisStyle... – Steven B. Segletes May 1 '17 at 17:23
• @StevenB.Segletes I will look into this package. I do appreciate the extended answer! – Captain Morgan May 1 '17 at 17:27

The output is horrible, in my opinion.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
% the user level command, respecting options to amsmath such as 'nosumlimits'
\newcommand\doublesum{\DOTSB\doublesum@\slimits@}
% the lower level command, robust so it won't break in moving arguments
\DeclareRobustCommand{\doublesum@}{%
\mathop{%
\vphantom{\sum@}% the same dimensions as \sum
\smash{\mathpalette\doublesum@@\relax}% delegate to \mathpalette
}%
}
% the preceding command delegates to \mathpalette
\newcommand{\doublesum@@}[2]{%
% vertically center the whole
\vcenter{\hbox{%
% \ooalign superimposes the rows (separated by \cr)
\ooalign{%
% first row with some more space on the right
$\m@th#1\sum@\doublesum@kern{#1}$\cr
% a vertical adjustment based on the current math style
\noalign{%
\sbox\z@{$\m@th#1\mkern2mu$}%
\kern\wd\z@
}
% second row with some more space on the left
$\m@th#1\doublesum@kern{#1}\sum@$\cr
}%
}}%
}
\newcommand{\doublesum@kern}[1]{%
% the kern should be greater in \displaystyle
\mkern\ifx#1\displaystyle 4\else 2\fi mu
}
\makeatother

\begin{document}

$\displaystyle\doublesum_{i,j}^{N} \textstyle\doublesum_{i,j}^{N} \scriptstyle\doublesum_{i,j}^{N} \scriptscriptstyle\doublesum_{i,j}^{N}$

$\displaystyle\doublesum_{i,j}^{N}\sum_{i,j}^{N}$
\end{document}


See The mysteries of \mathpalette for more information on \mathpalette

• @CaptainMorgan The main purpose is to make \doublesum compatible with amsmath options. I'll add some comments to the code. – egreg May 1 '17 at 17:50
• +1 for the superior spacing; but I kindly ask your permission to include \DOTSB, \slimits@, and robustness (which I merely overlooked) in my answer too. – GuM May 1 '17 at 21:57
• @GustavoMezzetti Of course! – egreg May 1 '17 at 22:36

As usual, I prefer going the good ol’ ways: here is a classical solution with \mathpalette. It has now been updated to improve integration with the amsmath package: it is for me a pleasure to thank @egreg both for having reminded me of this and for having allowed me to copy some code from his excellent (as always!) answer.

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath} % even if it not strictly necessary...

\makeatletter

\newcommand*\doublesum{\DOTSB\doublesum@x}
\DeclareRobustCommand*\doublesum@x{\mathop{\mathpalette\doublesum@y{}}\slimits@}
\newcommand*\doublesum@y[2]{%
\vcenter{%
\setbox\z@ \hbox{$\m@th #1\sum$}%
\baselineskip .2\ht\z@
\lineskiplimit -\maxdimen
\copy\z@
\moveright .2\wd\z@ \box\z@
}
}

\makeatother

% Check robustness:
\typeout{\doublesum.} % expected output: "\DOTSB \doublesum@x ."

\begin{document}

Text before.
$\doublesum_{ij}^{ND} x_{ij} \neq \sum_{ij}^{ND} x_{ij}$
Text after: $$\doublesum_{ij}^{ND} x_{ij} = 0$$.
Now in \verb|\scriptstyle|: $$\frac{\doublesum_{i\in I} x_{i}}{2}$$.

\end{document}


This is what I get in print:

• This seems more flexible in terms of constructing math symbols from various others at specified locations. I believe this is an excellent parallel to @StevenB.Segletes answer! – Captain Morgan May 1 '17 at 17:31

How to do this in plain TeX:

\input ams-math  % for \scripstyle\sum

\newcount\stylenum
\def\varstyle#1{\mathchoice{\stylenum=0 #1}{\stylenum=1 #1}{\stylenum=2 #1}{\stylenum=3 #1}}
\def\usestyle{\ifcase\stylenum\displaystyle\or\textstyle\or\scriptstyle\or\scriptscriptstyle\fi}
\def\dbsumR{\ifcase\stylenum .35\or.25\or.21\or.15\fi em}
\def\dbsumU{\ifcase\stylenum .15\or.12\or.09\or.07\fi em}
\def\doublesum{\mathop{\varstyle{%
\raise\dbsumU\rlap{$\usestyle\sum$}{\kern\dbsumR\sum}}}}

$\displaystyle \doublesum_{ij}^{DN} \textstyle \doublesum_{ij}^{DN} \scriptstyle \doublesum_{ij}^{DN} \scriptscriptstyle \doublesum_{ij}^{DN}$

\bye