Separate integer fractions from variables?
I believe this is what $PrePrint
is for, since you only want to affect how the expression looks, and I'm guessing you want it to happen automatically for every input. Using $PrePrint
thus allows you to use Out[n]
without worrying about the held expressions.
This seems to work (but I would like to find a better way to take care of the signs between terms in a sum):
$PrePrint = # /. r_Rational x_Symbol :> Sign[r] HoldForm[Evaluate[Abs[r]]] HoldForm[x] &
You can add more replacement rules if you like of course, to treat e.g. polynomials:
$PrePrint = # /. {r_Rational x_Symbol :>
Sign[r] HoldForm[Evaluate[Abs[r]]] HoldForm[x],
r_Rational x_Symbol^i_Integer :>
Sign[r] HoldForm[Evaluate[Abs[r]]] HoldForm[x^i]
} &
I would do this by using a custom MakeBoxes
rule:
MakeBoxes[Times[a__, r_Rational], StandardForm] := MakeBoxes[Times[Defer[r], a]]
Some examples:
Graphics[Circle[]]/2+Graphics[Rectangle[]]/3
Series[Sin[x], {x, 0, 10}]
Expand[(x-y)^4/24]
One nice thing about this approach is that the output is copy/pastable.
The other answer doesn't work right for any of these inputs, and the outputs generated are not copy/pastable.