1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ You are expecting too much from HoldForm. Its only interaction with the front-end is to be treated as an invisible wrapper. It gives the form it wraps no protection from output styling by the front-end. Its protection of the form only extends to preventing evaluation in a kernel. $\endgroup$ – m_goldberg May 8 '14 at 15:28
  • $\begingroup$ Strongly related: "Conversion of expressions by the FrontEnd." $\endgroup$ – Alexey Popkov May 8 '14 at 16:38
  • 1
    $\begingroup$ I think a possible answer to this is in my response to this question: Formula Formatting is Small and Chunky? $\endgroup$ – Jens May 8 '14 at 20:15
1
$\begingroup$

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.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.