Solution (source code)

= Solution

A repeated linear factor requires both reciprocal powers. Write the <partial fraction decomposition> as
$$
\frac{A}{x-1}+\frac{B}{(x-1)^2}+\frac{C}{x+2}.
$$
Multiplication by the common denominator gives $4x^2-x=A(x-1)(x+2)+B(x+2)+C(x-1)^2$. Setting $x=1$ gives $B=1$, and setting $x=-2$ gives $C=2$. Comparing the coefficients of $x^2$ then gives $A=2$. Thus
$$
\boxed{\frac{4x^2-x}{(x-1)^2(x+2)}
=\frac2{x-1}+\frac1{(x-1)^2}+\frac2{x+2},\qquad x\ne1,-2.}
$$