I am having trouble getting Mathematica to retain my original equation form. For example:
As you can see, even though I use HoldForm, it still changes the style of my equation. Very frustrating.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.Sign up to join this community
Here you have to enforce fraction on the Boxes level. This is one possible way to do it:
SetAttributes[fraction, Attributes@MakeBoxes]; MakeBoxes[fraction[a_, b_], rest_] ^:= FractionBox[MakeBoxes[a, rest], MakeBoxes[b, rest]]
Then you can manually transform subexpressions:
fixFractions = # /. Times[a_, Power[b_, -1]] :> fraction[a, b] &;
(1 + Sqrt[1+8b(b-1)])/2 // HoldForm // fixFractions // TraditionalForm
However, sometimes you might want to leave
Times[_, Power[_, -1]] as it is. Good news it's not difficult to control with pattern-matching.
Note: In this case it works perfectly even without attributes for
fraction. However, I don't want to remove the
SetAttributes[fraction, Attributes@MakeBoxes] part, even though I myself don't clearly understand the reasons. Comments on that matter are very welcome.