I would like to represent partial derivatives in Mathematica as subscripts. e.g. $\frac{\partial f}{\partial x}(x,y) = f_x(x,y)$.

Mathematica instead produces the output $f^{(1,0)}(x,y)$. Is there any way to make the partial derivative appear as a subscript?

On another note, is there a way to suppress arguments in the output? For me it would be even better if the output would read $f_x$.

  • $\begingroup$ What do you want $f^{(2,3)}(x, y)$ to look like? Or $f^{(n, m)}(x, y)$? Or $f^{(1, 0)}(2, 3)$? $\endgroup$ – Carl Woll Jun 5 '18 at 0:40
  • $\begingroup$ I would like $f^{(n,m)}(x,y)$ to appear as $f_{x\dots xy\dots y}$ (where $x$ appears $n$ times and $y$ appears $m$ times). I won't be evaluating the derivatives of $f$ at a point, so the last consideration isn't strictly necessary. $\endgroup$ – Fishy Jun 5 '18 at 0:44

You could write a MakeBoxes rule to do what you want:

Derivative /: MakeBoxes[
    Derivative[n_Integer?NonNegative, m_Integer?NonNegative][f_], form_
] := SubscriptBox[
    MakeBoxes[f, form],
    TemplateBox[Join[ConstantArray["x", n], ConstantArray["y", m]],"RowDefault"]

For example:

Derivative[1, 0][f][x, y]
% // TeXForm

Subscript[f, x][x,y]


Derivative[3, 2][g] //TeXForm


D[f[x, y], x, x]

enter image description here

  • $\begingroup$ Thank you for your response! It doesn't seem to work for me. Can you please explain how to implement the MakeBoxes rule? (I am new to Mathematica; Do I just evaluate it in an input cell?) Also, if possible, I would like this to apply globally to the output of all functions with partial derivatives (say there are f, g, h, ...). The point is to make the notation in deriving equations visually compact. $\endgroup$ – Fishy Jun 5 '18 at 1:06
  • $\begingroup$ @Fishy Yes, just evaluate it in an input cell. I generalized it to work with all function heads. $\endgroup$ – Carl Woll Jun 5 '18 at 1:40
  • $\begingroup$ Carl-- Thank you so much, it works now! The only remaining problem is an error message which appears when I use TexForm: TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported. After googling, it seems to be a bug in mathematica itself (e.g. here ). Anyway, I consider the problem solved. Cheers! $\endgroup$ – Fishy Jun 5 '18 at 16:13
  • $\begingroup$ @Fishy If you think the answer has resolved your problem, you may click on the check mark to accept it. $\endgroup$ – xzczd Jun 6 '18 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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