# Precise control of fraction expression

It seems that expression for fraction differs
when the number of terms in the numerator is more than 2.

{a, a + b, a + b + c, a + b + c + d, a + b + c + d + e}/2

{a/2, (a + b)/2, 1/2 (a + b + c), 1/2 (a + b + c + d),
1/2 (a + b + c + d + e)}


Much better to see it as a screenshot :

I want to control the expression for fraction precisely.
Like alpha/beta/gamma/delta type in the screenshot.
(I want to see such expressions in output cell)
You can just provide an answer without theoretical explanation.
(After seeing some examples, probably I can do something more difficult)

• Answer to this question depends on if you want to use these outputs as inputs to symbolic computation or just as typographical layout. Mar 4, 2023 at 14:14

They are not different. They are exactly the same, What you are mixing is external representation of expressions vs. the internal one.

Here is the TreeForm of

And here is the TreeForm of

You can see the internal representation is the same.

But the external representation of the first one and the second one are

To control the external representation it means you have to fight the frontend and have to use things like Hold or HoldForm or Inactive and so on to prevent evaluation. But this buys you nothing, Since to be able to use the expression you have to release the hold. So you end up with just more complicated code to look at.

If you are interested in final expression representation only, and not during computation, then you could always do that at the very end using the Hold functions mentioned above. If this is what you want, it will be easy to do that.

expr = {a, a + b, a + b + c, a + b + c + d, a + b + c + d + e}/2


## "gamma" type

Expand[expr]


## Alpha type

DisplayForm[FractionBox[Numerator[#], Denominator[#]]] & /@ expr


I would actually do everything using MateX, since it is just for display purposes. Here is an example

## Alpha

<< MaTeX
expr = {a, a + b, a + b + c, a + b + c + d, a + b + c + d + e}/2;
s = "\\frac{" <> ToString@TeXForm[Numerator[#]] <> "}{" <>
ToString@TeXForm[Denominator[#]] <> "}" & /@ expr;
MaTeX[s]


## Beta

s = "\\frac{1}{" <> toX[Denominator[#]] <> "}\\left(" <>
toX[Numerator[#]] <> "\\right)" & /@ expr
MaTeX[s, Magnification -> 1.3]


Delta type could be done similarly.

Expanding on Alexey's answer, here are some possible ways to obtain different box structures of rational expressions. You could further complicate the β type to remove unnecessary parentheses for a/2.

expr = {a, a + b, a + b + c, a + b + c + d, a + b + c + d + e}/2;

(* α type *)
Clear[MakeBoxes];
MakeBoxes[Times[Rational[n_, d_], expr__], StandardForm] :=
FractionBox[ToBoxes[Times[n, expr]], d];
expr

(* β type *)
Clear[MakeBoxes];
MakeBoxes[Times[Rational[n_, d_], expr__], StandardForm] :=
RowBox[{FractionBox[n, d], " ", RowBox[{"(", ToBoxes[expr], ")"}]}];
expr

(* γ type *)
Clear[MakeBoxes];
Expand /@ expr

(* δ type *)
Clear[MakeBoxes];
MakeBoxes[Times[Rational[n_, d_], expr__], StandardForm] :=
RowBox[{FractionBox[n, d], " ", ToBoxes[expr]}];
Expand /@ expr
`