 
 
 
 
 
 
RE: Those Pesky Minus Signs
- To: mathgroup at smc.vnet.net
- Subject: [mg43354] RE: Those Pesky Minus Signs
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Tue, 26 Aug 2003 07:13:28 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
David was right about a typo in my code.  I don't know how that got in
there. 
I added the first definition below to cover things like
      (-a-b-c)
Notice I could have chaged MakeBoxes[a_*b:   ]  to  MakeBoxes[(a_.)*b:   ]
but then we would get 
    -1(a+b+c) when we really want 
     -(a+b+c)
So I made another definition to handle that case.
----------------------------
MakeBoxes[b:Plus[_?Negative*_, (_?Negative*_)..],
    form:(StandardForm | TraditionalForm)] :=
  RowBox[{"-",
      RowBox[{"(", MakeBoxes @@ {-b, form}, ")"}]}]
MakeBoxes[a_*b:Plus[_?Negative*_, (_?Negative*_)..],
    form:(StandardForm | TraditionalForm)] :=
  RowBox[{MakeBoxes @@ {-a, form},
      RowBox[{"(", MakeBoxes @@ {-b, form}, ")"}]}]
MakeBoxes[p_Rational?Negative, form:(StandardForm | TraditionalForm) ] :=
  FractionBox[ MakeBoxes @@ {Numerator[p], form},
    MakeBoxes @@ {Denominator[p], form} ]
--------------------
For lots of other cases I recommend my HoldTemporary package posted at 
http://library.wolfram.com/infocenter/MathSource/705/
The package is really neat.  In the package I define a function called
HoldTemporary that works like HoldForm, but the hold is automatically
released.
You can use HoldTemporary to prevent mapping of Times across an array.
----------------------------
Regards,
  Ted Ersek
  Get Mathematica tips, tricks from
  http://www.verbeia.com/mathematica/tips/Tricks.html

