The question concerns the Notation package.
I want to define notation for the function very similar to the built-in Power[a,b] function.
I am trying to do it in the following way:
Needs["Notation`"];
Notation[ParsedBoxWrapper[SuperscriptBox["A_","B_"]] \[DoubleLongLeftArrow] ParsedBoxWrapper[RowBox[{"MyPower", "[","A_", ",", "B_", "]"}]]]
It works fine with MyPower[a,c], displaying a^c.
However if the case of MyPower[a+b,c], the result is a+b^c.
The question is how to make Mathematica to put parenthesis automatically, so I can get a^c in the first case and (a+b)^c in the second case.
I believe that the answer is about setting the precedence order using TagBox function with SyntaxForm argument. However, this function is rather ill-documented and I couldn't get it work.
P.S. I would like to note that automatic parenthesis placement works fine for binary operations:
Needs["Notation`"];
Notation[ParsedBoxWrapper[RowBox[{"A_", " ", "plus" , " ", "B_"}]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[RowBox[{"MyPlus", "[", RowBox[{"A_", ",", "B_"}], "]"}]]]
Notation[ParsedBoxWrapper[RowBox[{"A_", " ", "times" , " ", "B_"}]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[RowBox[{"MyMult", "[", RowBox[{"A_", ",", "B_"}], "]"}]]]
MyPlus[a, MyMult[b, c]] (* Returns a plus (b times c) *)
MyMult[MyPlus[a, b], c] (* Returns (a plus b) times c *)
Notation[ParsedBoxWrapper[RowBox[{"A_", " ", TagBox["plus", "", SyntaxForm -> "+"], " ", "B_"}]]\[DoubleLongLeftRightArrow]ParsedBoxWrapper[RowBox[{"MyPlus", "[", RowBox[{"A_", ",", "B_"}], "]"}]]]
Notation[ParsedBoxWrapper[RowBox[{"A_", " ", TagBox["times", "", SyntaxForm -> "a"], " ", "B_"}]]\[DoubleLongLeftRightArrow]ParsedBoxWrapper[RowBox[{"MyMult", "[", RowBox[{"A_", ",", "B_"}], "]"}]]]
MyPlus[a, MyMult[b, c]] (* Returns a plus b times c *)
MyMult[MyPlus[a, b], c] (* Returns (a plus b) times c *)
MyPower[x ** y, z]. The same problem with cross operatorMyPower[x\[Cross]y, z]. – bcp Jul 07 '14 at 09:45