# Can the Notation function support complex structures on its left hand side?

In my investigation of the possibilities offered by the Notation package, I came over a limitation in the complexity of the left hand side symbol. For instance, although I am able to enter

 Notation[
ParsedBoxWrapper[
OverBar[SuperStar[af]]]
\[DoubleLongLeftRightArrow]
ParsedBoxWrapper["afstarbar"]]


without Mathematica complaining, evaluating afstarbar returns an incorrectly formatted symbol (the whole symbol is replaced by a red error square instead of displaying $\overline{af^*}$). The output is:

 OverBar[SuperStar[$CellContextaf]] An unknown box name (OverBar) was sent as the BoxForm for the expression. Check the format rules for the expression.  I am unfamiliar with the concept of "boxing", but I tried the following: Notation[ ParsedBoxWrapper[ MakeBoxes[ OverBar[SuperStar[af]]]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper["afstarbar"]]  And the display is slightly better, as the$af^*\$ is here, but the bar is replaced by the red error square and the output is:

\!$$\*OverscriptBox[ SuperscriptBox[\(af$$, $$*$$],
NotationPrivatesingleBlank[]]\)

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


Any trick on how to get the symbol to display correctly with the Notation package?

-
I don't remember having this problem with OverBar before... is this "bug" a regression or is my memory just faulty? –  Simon Jan 18 '12 at 7:49
It could be a Mac-OS specific problem as I have noticed that Notation behaves differently between Mathematica 8.0.0.0 for Windows and for Linux and the same version for Mac. cf. reddit discussion –  agravier Jan 18 '12 at 7:54
The same problem is happening on my linux box. (Btw, thanks for the link to the reddit Mma "group". I didn't know that such a thing existed!) –  Simon Jan 18 '12 at 7:57

So (I guess that) the problem occurs because
Notation[LHS \[DoubleLongLeftRightArrow] RHS] converts the LHS into boxes,
where OverBar[x] is OverscriptBox[x,"_"].
It then interprets the underscore as a Blank (_), which it tries to match up with a pattern on the RHS.

I'm sure that I've used the Notation package with OverBars before and have not had troubles with it. But then again, maybe not.

Anyway, you can forget about the Notation package for this since you can easily use the underlying box mechanism to implement the notation that you want:

MakeBoxes[afstarbar, form_] := InterpretationBox[
OverscriptBox[SuperscriptBox["af", "*"], "_"], afstarbar]

-
Thank you, I will try that out in a few hours when I have access to Mathematica. I will also document myself about the boxes mechanism to better understand what is going on. –  agravier Jan 18 '12 at 8:04
What's with the form parameter? –  Sjoerd C. de Vries Jan 18 '12 at 16:32
@Sjoerd: You can have different MakeBoxes for StandardForm and TraditionalForm` (etc). I didn't use the parameter but named it just so I can remember what it is for. –  Simon Jan 18 '12 at 20:59
@Simon, I confirm that your solution works, thank you! –  agravier Jan 19 '12 at 4:08