OK, though I've done this many times, given that coding this in _Mathematica_ requires one to have a good enough understanding for the core language, let me do a favor: Clear[myD, mySum] myD[a_ b_, c_] := a myD[b, c] + b myD[a, c] (* Add the rule for addition just in case: *) myD[a_ + b_, c_] := myD[a, c] + myD[b, c] myD[mySum[a_, b__], x_] := mySum[myD[a, x], b] myD[(h_ /; Context[h] =!= "System`")[a__], x_] := With[{l = Length@{a}}, Total@MapThread[ Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@ l, {a}}]] myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] := KroneckerDelta[j1, j2] myD[Subscript[a_, __], Subscript[b_, __]] := 0 mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, j_, jR___] := mySum[expr /. j -> i, jL, jR] mySum[a_] := a MakeBoxes[mySum[a__], fmt_] ^:= With[{funcbody = MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", DisplayFunction -> (funcbody &)]] Usage: myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]] [![enter image description here][1]][1] myD[Subscript[x, k] mySum[g[Subscript[a, i, j], Subscript[x, j]], i, j], Subscript[x, n]] [![enter image description here][2]][2] You can press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>t</kbd> to transform the output to `TraditionalForm`, and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>n</kbd> to transform the output to `StandardForm`. [1]: https://i.sstatic.net/OO6L5D18.png [2]: https://i.sstatic.net/cWzUKBng.png