<s>[INST] Compute $\int\frac{x^2}{\tan{x}-x}dx$ for $x \in (0, \frac{\pi}{2})$ 
Compute the indefinite integral $\displaystyle{\int\frac{x^2}{\tan{x}-x}dx, x \in (0, \frac{\pi}{2})}$.

I have tried substituting $\tan{x} = t$ or write $\tan{x} = \displaystyle{\frac{\sin{x}}{\cos{x}}}$ and then try to solve it from there, but I didn't manage to do it. Also, $\displaystyle{\left(\frac{\sin{x}}{x}\right)' = \frac{\sin{x} - x\cos{x}}{x^2}}$, but in the integral I have the inverse of this...
 [/INST] $$\int\frac{x^2}{\tan{x}-x} =\int\frac{x^2 \cos x +x \sin x - x \sin x}{\sin{x}-x \cos x}=\int \left(\frac{x \sin x}{\sin{x}-x \cos x} - x \right) $$
Now notice that $$\sin x - x \cos x=t \implies   x\sin x = dt$$
Hence $$\int \left(\frac{x \sin x}{\sin{x}-x \cos x} - x \right) = \ln |(\sin{x}-x \cos x) | - \frac{x^2}{2} +C $$
</s>