Integrating polynomial fraction of same degree I'm to integrate:
$$ \int {\frac{x^2}{x^2+x-2} }dx$$
If there was a constant in the numerator then I could solve this but I'm not sure with $x^2$. Can I use long division? I  tried and it didn't seem to work out (but my long division is very rusty).

$$\int {x^2\over x^2+x-2}dx=\int {x^2+x-2-x+2\over x^2+x-2}dx=\int1+{-x+2\over x^2+x-2}dx$$
$$=x-{1\over2}\int{2x-4\over x^2+x-2}dx=x-{1\over2}(\int{2x+1\over x^2+x-2}-{5\over x^2+x-2}dx)$$
$$=x-{1\over2}ln( x^2+x-2)+{5\over2}\int{1\over x^2+x-2}dx $$
After that you need to deal with $$\int{1\over x^2+x-2}dx=\int{1\over (x+2)(x-1)}dx $$
$$={1\over3} \int {1\over(x-1)}-{1\over(x+2)}dx={1\over3}(ln(x-1)-ln(x+2))+c$$ 
Total result is $$=x-{1\over2}ln( x^2+x-2)+{5\over6}(ln({x-1\over x+2}))+c $$
we are done.
