I am trying to define an object type in Mathematica as follows
Operator /: MakeBoxes[Operator[pow_, sym_], fmt_] :=
With[{sbox = If[StringQ[sym], sym, ToBoxes[sym]]},With[{abox = SuperscriptBox[#, pow]
&@sbox},InterpretationBox[abox, Operator[pow, sym]]]]
This works fine when I use integer powers for example
X = Operator[2,x]
gives me $x^2$, however it doesn't work if I use a symbol for the power for example
Y = Operator[a+b,x]
should give $x^{a+b}$ but it does not. What needs to be changed?
...With[{abox = SuperscriptBox[#, ToBoxes[HoldForm@pow]] &@sbox},....
$\endgroup$ – Kuba♦ Jun 26 '13 at 21:06