# Customizing display of partial differential equations

I am manipulating partial differential equations symbolically, and would like to get the easily readable form $\rho \frac{\partial v}{\partial t}$, leaving variables implicit.

Based on suggestions from How to make traditional output for derivatives I started out with

Derivative /:
Module[{bb, dd, sp},
MakeBoxes[dd, _] ^=
If[Length[{α}] == 1, "\[DifferentialD]", "∂"];
MakeBoxes[sp, _] ^= "\[ThinSpace]";
bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
TemplateBox[{ToBoxes[bb[dd^Plus[α], f1]],
ToBoxes[Apply[bb,
Riffle[Map[bb[dd, #] &,
Select[({vars}^{α}), (# =!= 1 &)]], sp]]],
ToBoxes[Derivative[α][f1][vars]]}, "ShortFraction",
DisplayFunction :> (FractionBox[#1, #2] &),
InterpretationFunction :> (#3 &),
Tooltip -> Automatic]]


When functions appear outside of partial derivatives, they still appear as $v(t,x)$. Trying to fix this, I tried

supressVariable[f_Symbol] :=
f /: MakeBoxes[f[t, x], TraditionalForm] :=
InterpretationBox[ToBoxes[f], f[t, x]]
SetAttributes[supressVariable, Listable]
supressVariable[{v, ρ, p, f}];


This works fine for both

f[t, x] v[t, x] == 0 // TraditionalForm


and

ρ[t, x]*Derivative[0, 1][v][t, x] +
v[t, x]*Derivative[0, 1][ρ][t, x] +
Derivative[1, 0][ρ][t, x] == 0 // TraditionalForm


producing nicely readable equations. However, the simple

f[t, x] == 0 // TraditionalForm


gives error message

An unknown box name (ToBoxes) was sent as the BoxForm for the expression. Check the format rules for the expression

and I don't know what to do with this. Can anybody help me out?

• I can't resist pointing out that suppress is written with two p...
– Jens
Aug 24 '14 at 19:26

It seems to me that using MakeBoxes in this case is overkill. How about this simpler definition?

supressVariable[f_Symbol] :=
Format[f[t, x], TraditionalForm] := Interpretation[f, f[t, x]]

SetAttributes[supressVariable, Listable]
supressVariable[{v, ρ, p, f}];


This doesn't encounter the issue you faced, because the symbol f is passed directly to Interpretation (no need to wrap it in ToBoxes at all).

• Be aware that MakeBoxes can have superior behavior to Format in some ways. See this Q&A: (4112299) Aug 25 '14 at 19:06
• @Mr.Wizard Are you saying that there is anything wrong with Format in the context of this question? Note that the question is only about formatting for TraditionalForm.
– Jens
Aug 25 '14 at 20:39
• You're right; since TraditionalForm is not for editing anyway I guess my concern is baseless. I merely got in the habit of using MakeBoxes preferentially to Format most of the time. +1 Aug 25 '14 at 21:07

InterpretationBox holds its arguments (it has HoldAllComplete). You must evaluate ToBoxes[f] outside of this head, easily accomplished with Function as follows:

supressVariable[f_Symbol] :=
f /: MakeBoxes[f[t, x], TraditionalForm] :=
InterpretationBox[#, f[t, x]] & @ ToBoxes[f]

• Could you please be a bit more explicit on how it works? Aug 24 '14 at 12:34
• Actually I think it needs to be made listable Aug 24 '14 at 12:38
• @chris This isn't complete code; it is to replace only that one "line" in the OP's code. By default a Function will evaluate its arguments; consider: Hold[#, 2 + 2] &[1 + 1] Aug 24 '14 at 18:59
• Yes, this solution works well. Seeing this, I don't understand how my original attempt worked at all, though. Aug 25 '14 at 13:23