Re: A two part notation question
- To: mathgroup at smc.vnet.net
- Subject: [mg120994] Re: A two part notation question
- From: Simon <simonjtyler at gmail.com>
- Date: Sun, 21 Aug 2011 05:30:53 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j2le74$ndf$1@smc.vnet.net>
- Reply-to: comp.soft-sys.math.mathematica at googlegroups.com
Sometimes with these things it's easiest to resort to the low level MakeBoxes and MakeExpression. E.g.
f /: MakeBoxes[f[x_], form_] := With[{boxes = ToBoxes[x]},
InterpretationBox[OverscriptBox[boxes, "_"], f[x]]]
Unprotect[OverscriptBox];
OverscriptBox /: MakeExpression[OverscriptBox[x_, "_"], form_] :=
MakeExpression[RowBox[{"f", "[", x, "]"}], form]
Protect[OverscriptBox];
These definitions are stored in FormatValues[f] and FormatValues[OverscriptBox].
Although they don't need to be defined with TagSet (/:). Also, the InterpretationBox is probably overkill since we have the MakeExpression definition.
You can check that things are working with
In[7]:= f[x] // ToBoxes
Out[7]= InterpretationBox[OverscriptBox["x", "_"], f[x]]
In[8]:= Overscript[a+b, _]//FullForm
Out[8]//FullForm= f[Plus[a,b]]