If I type
C[x, y] // TraditionalForm
I get something that looks like
C[x, y]
But if I type
f[x, y] // TraditionalForm
I get something that looks like
f(x, y)
What do I do to designate that a particular symbol, say, f
, should have function application rendered in traditional form with square brackets rather than parentheses (i.e., ToString[f[x], TraditionalForm]
should give "f[x]"
, not "f(x)"
)?
Update: Using kguler's answer, I managed the following:
Format[f[x__], TraditionalForm] :=
Block[{f},
RawBoxes[ToBoxes[TraditionalForm[f[x]]] //.
RowBox[{"f", "(", else___, ")"}] :> RowBox[{"f", "[", else, "]"}]]];
But this does not work in all cases, in particular, when wrapped in a Defer
block:
{g[g[h[x]]], g[f[h[x]]]} // TraditionalForm
{g[g[x] | y], f[g[x] | y]} // TraditionalForm
{g[x, y | z, y], f[x, y | z, y]} // TraditionalForm
{Defer[g[D[k, x]]], Defer[f[D[k, x]]]} // TraditionalForm
{g[Defer[D[k, x]]], f[Defer[D[k, x]]]} // TraditionalForm
gives
$\{g (g (h(x))),g(f[h(x)])\}$
$\{g (g(x)\,|\,y),f[g(x)\,|\,y]\}$
$\{g(x,y\,|\,z,y),f[x,y\,|\,z,y]\}$
$\left\{g\left(\frac{\partial k}{\partial x}\right),f[0]\right\}$
$\left\{g\left(\frac{\partial k}{\partial x}\right),f\left[\frac{\partial k}{\partial x}\right]\right\}$
The second-to-last line is wrong.