2
$\begingroup$

I was wondering if it is possible to force particular style of displaying derivatives in Mathematica.

For example if I type: $$AB\partial_\mu C[\mu]$$

After execution it automatically be displayed as: $$ABC'(\mu)$$

I would prefer to have my derivatives with $\partial_\mu$ symbol for reasons. Is this possible?

Edit: Thanks for the reply Carl Woll. Such terms you written will never appear. What I want is to aesthetically have terms like $A^\mu\partial_\mu B$ and not $A^\mu B'$. Former case means something to me while the latter case requires one mental step to convert $'$ to derivative.

$\endgroup$
1
  • $\begingroup$ What do you want $AB\partial_\mu C[\mu + \nu]$ to look like? $\endgroup$
    – Carl Woll
    Commented Dec 1, 2017 at 21:39

1 Answer 1

2
$\begingroup$

One possibility is to modify the formatting for Derivative:

Derivative /: MakeBoxes[c'[x_], StandardForm] := MakeBoxes[D[c[x], x]]

For your example:

enter image description here

If you would rather have c instead of c[μ], you could modify the above:

Derivative /: MakeBoxes[Derivative[1][c_][x_], StandardForm] := With[
    {boxes = MakeBoxes[D[c, x]]},
    InterpretationBox[boxes, Derivative[1][c][x]]
]

(Here I use an InterpretationBox so that the output is copy/pasteable.) Then:

enter image description here

However, in both cases, if the argument to c is not an index, then problems arise. For example:

enter image description here

Here is an alternative that doesn't require that you give arguments:

MakeBoxes[Dt[c_,x__], StandardForm] := With[{boxes = MakeBoxes[D[c,x]]},
    InterpretationBox[boxes, Dt[c,x]]
]

Then:

enter image description here

(Note that the use of DifferentialD above has the alias Esc d d Esc) A few more examples:

enter image description here

$\endgroup$

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.