How to stop Mathematica from deriving index?
This can be solved by applying custom formatting to kx
rather than using Subscript
:
kx /: MakeBoxes[kx, TraditionalForm | StandardForm] := SubscriptBox["k", "x"];
Then kx
will be output as $k_x$, and the derivative will be correct:
D[kx, k]
0
Would highly recommend looking at TagSet
(/:
) and MakeBoxes
in the documentation for further information.
Due to the TraditionalForm
used in the MakeBoxes
pattern, this will also work with TeXForm
:
TeXForm[kx]
k_x
@Roman also suggested Format
as an alternative, so to provide some clarification there:
Format[kx] := Subscript[k, x];
By assigning Format[_]
, the output format of _
can be changed. It's a bit less excessively low-level, as Roman comments. In my own personal experience with Mathematica, it's almost a bit less intuitive, but your mileage will vary. This also works properly with TeXForm
.
Regarding OverDot
, that is also possible in these cases. For example, with v
:
Format[v] := OverDot[v];
Or:
v /: MakeBoxes[v, TraditionalForm | StandardForm] := OverscriptBox["v", "."];