# How can I stop Mathematica from re-arranging formulae in TraditionalForm?

Let's say I have a sample formula, for example (Abs[x]/(-(2 - \[Kappa]) - 5))/(Binomial[a, b]/4) or something like that. I can of course typeset it to a limited degree and with not necessarily nice results:

It is so small that this x is barely distinguishable from this kappa, and I can't typeset Abs or Binomial.

So I use TraditionalForm and I get this:

This is certainly much nicer. But my formula got rearranged heavily. Yes, I have to admit it, it looks much prettier this way in that particular case (sometimes TraditionalForm actually makes formulae less clear), but this is not what I wanted to achieve. I wanted my formula to be displayed in LaTeX quality exactly as I typed it!

So I add a HoldForm just to get this:

Phew. And they call THIS a "held form".

I can get what I want if I also enter a HoldForm in the middle of the formula in the right place:

But in more complex examples I have to spam those HoldForms obnoxiously, which is annoying. Also having HoldForms in the middle of formulae can get annoying, since this will affect evaluation.

How to stop this rearranging? Isn't there anything like, say, TraditionalForm[StopRearranging[formula]]?

• Feb 13, 2015 at 21:07
• Are you typing your formulas in an input cell? None of this would happen if you were using one of the cell styles that are meant for that purpose, like DisplayFormula. So you should perhaps clarify what you really want to do with the typed formulas eventually: i.e., use them only for display or do other calculations with them.
– Jens
Feb 13, 2015 at 22:59
• You might want to apply TraditionalForm at single parts of your formula. Highlight Abs[x] and use CTRL+SHIFT+T, then highlight Binomial[a,b] and do the same. Highlight the whole formula and type CTRL+B to remove the bold style. Is this what you are after? (This will work if you use TraditionalForm as default Input method, otherwise you'll have to use Cell Display As... Traditional Form to convert it without touching it). Feb 14, 2015 at 3:27
• @Jens Checked this. Typed the formula in a DisplayFormula cell. Right-clicked and selected Convert to -> TraditionalForm. The formula still got re-arranged. Feb 14, 2015 at 14:07
• The point is that the DisplayFormula Cell is already in TraditionalForm. You don't need to convert anything.
– Jens
Feb 14, 2015 at 16:29

It's worth examining how your original expression was rendered in TraditionalForm, even though it was not just what you wanted.

exp = (Abs[x]/(-(2 - \[Kappa]) - 5))/(Binomial[a, b]/4) // TraditionalForm

Let's look at the underlying structure:

tagExp = ToBoxes[exp]

TagBox[FormBox[ FractionBox[RowBox[{"4", " ", TemplateBox[{"x"}, "Abs"]}], RowBox[{RowBox[{"(", RowBox[{"[Kappa]", "-", "7"}], ")"}], " ", TemplateBox[{"a", "b"}, "Binomial"]}]], TraditionalForm], TraditionalForm, Editable -> True]

Let's invert the process to check whether this code will result in the rendering we began with:

tagExp//DisplayForm

And now we get a treeform display of the structure:

tagExp // TreeForm

You may be able to tweak the TagBox coding to obtain what you are looking for.

Here's a somewhat simpler, seat-of-the-pants approach. I'm not sure this is an improvement on what you came up with. But, here goes.

For this FractionBox seems to be the place to start. But in other circumstances other formatting boxes (StyleBox, SuperscriptBox, SubscriptBox, etc.) may be required.

The general structure of your problem is

FractionBox["top", "bottom"] // DisplayForm

Once you realize this, you can move ahead to deal with the top and bottom (or numerator and denominator, if you prefer).

Yes, you might have formatted this as a simple fraction using /. But this is a live operator that could give you trouble as you move forward. FractionBox is your outermost frame, so to speak.

Let' s begin with the bottom, since that seems more straightforward.

bottom = Binomial[a, b]/4 // TraditionalForm

Let's put the bottom into the FractionBox structure:

FractionBox["top", bottom] // DisplayForm

The top itself can be put into its own FractionBox. Like you, I had to use HoldForm to accomplish this.

top = FractionBox[Abs[x] // TraditionalForm, HoldForm[(-(2 - \[Kappa]) - 5)]] // DisplayForm

Let's now insert the top into the outermost FractionBox

FractionBox[top, bottom] // DisplayForm

If that's too small, wrap it in Style:

Style[FractionBox[top, bottom], 24] // DisplayForm

StyleBox will produce the same effect. And it may actually be more appropriate here.

StyleBox[FractionBox[top, bottom], 24] // DisplayForm

Firstly to address the start of the question in which you didn't like how small everything was. This can be fixed quite simply by changing an option to FractionBox

FractionBoxOptions -> {AllowScriptLevelChange -> False}

Normally you would set this as part of a style sheet for Input style or you could set it at the cell level using the options inspector. To see it in use I am setting it for the entire notebook as per the animated gif below:

For the second part of your question, to stop your reordering you can wrap stuff in PolynomialForm and set the option TraditionalOrder to False. You can still use TraditionalForm so that you get traditional typesetting of the binomial but the problem with this approach is that it only stops reordering of the final rearranged expression. You need to intervene before the fractions boxes get rearranged ...which is what you have discovered by using HoldForm.

Once you are in a cell that displays in TraditionalForm, the issue is how to enter things like Abs[x] and Binomial[a,b] so that they display properly. This is indeed not as convenient as it should be (compared to $\LaTeX$). Specifically for the binomial, I had posted a solution in this answer.