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 /:
MakeBoxes[Derivative[α__][f1_][vars__Symbol], TraditionalForm] :=
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?
Answer
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).
Comments
Post a Comment