# Is there a way to force Mathematica to collect terms in a more readable way?

I've got the following result from an operation in Mathematica:

(c3 + a3*t)^2*(\[DifferentialD]t)^2 - ((2 + z)^2*((\[DifferentialD]xC)^2 + (\[DifferentialD]xM)^2 + (\[DifferentialD]xY)^2))/(4*(1 + z)^2)


It looks like this in standard form:

$$(c3+a3\space t)^2 (dt)^2-\frac{(2+z)^2((dxC)^2+(dxM)^2+(dxY)^2)}{4(1+z)^2}$$

The $$\frac{(2+z)^2}{4(1+z)^2}$$ term is a factor. Is there any way to force this into a more readable form:

$$(c3+a3\space t)^2 (dt)^2-\frac{(2+z)^2}{4(1+z)^2}\space ((dxC)^2+(dxM)^2+(dxY)^2)$$

expr = ((2 + z)^2*((\[DifferentialD]xC)^2 + (\[DifferentialD]xM)^2 +
(\[DifferentialD]xY)^2))/(4*(1 + z)^2);

Collect[expr, HoldPattern@Plus[__Power], Defer]


TeXForm @ %


$$\frac{(z+2)^2}{4 (z+1)^2} \left((d\text{xC})^2+(d\text{xM})^2+(d\text{xY})^2\right)$$

• @kilgor - This almost works. I edited the question to show the full version of the equation I'm trying to re-organize. There's a negative sign that seems to be skewing the answer. Your solution gives me something that looks like:$$(c3+a3\space t)^2 (dt)^2+-\frac{(2+z)^2}{4(1+z)^2}\space ((dxC)^2+(dxM)^2+(dxY)^2)$$Any ideas how to get rid of the + - mess? Other than that, this is exactly what I need. Commented May 25, 2020 at 19:14
• @Quarkly, maybe something like: Collect[expr2, HoldPattern@Plus[__Power], Defer] /. Defer[ Times[Rational[a_?InternalSyntacticNegativeQ, b_], c___]] :> a Defer[Times[1/b, c]]?
– kglr
Commented May 25, 2020 at 21:00
• meant Collect[expr2, HoldPattern@Plus[__Power], Defer] /. Defer[ Times[Rational[a_?InternalSyntacticNegativeQ, b_], c___]] :> a Defer[Times[1/b, c]]`
– kglr
Commented May 27, 2020 at 0:01