Re: Overriding Division Notation
- To: mathgroup at smc.vnet.net
- Subject: [mg26582] Re: Overriding Division Notation
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Tue, 9 Jan 2001 01:51:56 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Jeff Hesh wanted to make a/b display as
a
a b^-1 instead of -
b
I assume he also wants to use parentheses when appropriate as in
a/(b+c) should display as a (b+c)^-1
A few extra rules are needed to get the parentheses right.
The following code should do the trick.
(*****************)
MakeBoxes[(a_Plus) (b_Plus)^-1,form_]:=
RowBox[{"(",MakeBoxes[a,form],")",
SuperscriptBox[ RowBox[{"(",MakeBoxes[b,form],")"}], "-1"]
}]
MakeBoxes[(a_Plus) b_^-1,form_]:=
RowBox[{"(",MakeBoxes[a,form],")",
SuperscriptBox[ RowBox[{MakeBoxes[b,form]}], "-1"]
}]
MakeBoxes[a_ (b_Plus)^-1,form_]:=
RowBox[{MakeBoxes[a,form]," ",
SuperscriptBox[RowBox[{"(",MakeBoxes[b,form],")"}],"-1"]
}]
MakeBoxes[a_ b_^-1,form_]:=
RowBox[{MakeBoxes[a,form]," ",
SuperscriptBox[MakeBoxes[b,form],"-1"]
}]
(*******************)
To understand how this works look up MakeBoxes at my website.
--------------------
Regards,
Ted Ersek
Download Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html