I'd like to write a function whose arguments contains symbols that are automatically localized, just like some built-in functions, like Sum. Even better, I'd like to see the symbols' color change, to remind the user about the localization.
For example, if I wanted to do matrix multiplication in tensor notation, where the specified index is summed over the specified coordinates, I would use
SetAttributes[contractIndices, HoldAll]
contractIndices[expr_, dummyindices_List, coordinates_List] :=
Module[{result = Hold[expr]},
Do[result = Sum[result /. {a -> coord}, {coord, coordinates}], {a,
dummyindices}];
ReleaseHold[result]]
and expect
contractIndices[f[i, j] g[j, k], {j}, {x, y, z}]
to return
f[i,x] g[x,k] + f[i,y] g[y,k] + f[i,z] g[z,k]
even if the symbol j had been given a value previously.
Of course I could simply always enclose this inside a Module[{j},...], but I want a function that automatically localizes, just as Sum does with its dummy variable.