I want to define a constant vector {$k_x , k_y , k_z$}. The problem is that Mathematica gives me D[$k_x$,x]$=k_1$. I want this to be zero, because $k_x$ is a constant.

Clearly D[$k_x$,x]$=k_1$ makes sense since $k_x=$Subscript[k,x] but it is still quite annoying because it is contrary to standard notation.

How to tell Mathematica that Subscript[k,x] is just a variable name (instead of two variables, k and x, inside the function Subscript)?


1 Answer 1


The simplest solution is to not use symbols inside of your subscripts:

D[Subscript["k", "x"], x]


In StandardForm, they look the same:

{Subscript[k, x], Subscript["k", "x"]}

enter image description here


If you must use symbols instead of strings, then you can change a system option so that Subscript objects are not differentiable:

    "DifferentiationOptions" -> "ExcludedFunctions" -> DeleteDuplicates @ Append[
        OptionValue[SystemOptions[], "DifferentiationOptions"->"ExcludedFunctions"],


D[Subscript[k, x], x] //InputForm

D[Subscript[k, x], x]

Mathematica knows there's an x inside the subscript, so it thinks the result isn't 0, but the "ExcludedFunctions" setting means Mathematica doesn't know what to do with the subscript. So, we need to define an UpValues:

D[_Subscript, __] ^:= 0


D[Subscript[k, x], x]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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