1

I am having trouble getting Mathematica to retain my original equation form. For example:

enter image description here

As you can see, even though I use HoldForm, it still changes the style of my equation. Very frustrating.

Tyler Durden
  • 4,090
  • 14
  • 43

1 Answers1

1

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] &;

An example:

(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.

akater
  • 1,540
  • 11
  • 16