Find steps to solve : $\int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u + x^2} \, du $ $$ \int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u + x^2} \, du\quad\text{with}\quad x \in ]-1,1[ $$

 $$ \int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u  + x^2} \, du = \arctan \left( \frac{x \sin t}{1- x \cos t} \right) $$

I have this integral with a known result. The "proof" the book gives is :

"We recognize that the fraction is $\dfrac{h'(u)}{1+h(u)^2}$ with $h(u) = \dfrac{x \sin u}{1- x \cos u } $"

But it's not that easy to spot, and I would like to know how to find this result without guessing that out of nowhere and without knowing it beforehand.
I've tried substitutions but I can't find a way to make it work.
Any idea on how to solve this ? Thanks !
 A: I also don't see a way to spot that antiderivative, so here's what I would call the "systematic" way of doing it. That is, simply applying general purpose integration techniques and identities without trying to find antiderivatives by inspection.
When working with integrals involving rational functions of $\sin$ and $\cos$, a standard method of integration is the tangent half-angle substitution $v = \tan(u/2)$. This means $\sin(u) = 2v/(1+v^2)$, $\cos(u) = (1-v^2)/(1+v^2)$, and $du = 2dv/(1+v^2)$. Applying this to your integrand gives
$$
\int_0^t\frac{x\cos(u) - x^2}{1 - 2x \cos(u) + x^2}du = \int_0^{\tan(t/2)}\frac{x[1-x - (1+x)v^2]}{(1-x)^2 + (1+x)^2 v^2}\frac{2dv}{1+v^2}
$$
We then do a standard partial fraction expansion:
\begin{multline}
\int_0^{\tan(t/2)}\frac{x[1-x - (1+x)v^2]}{(1-x)^2 + (1+x)^2 v^2}\frac{2dv}{1+v^2} = \int_0^{\tan(t/2)}\left[\frac{\frac{1+x}{1-x}}{1 + \left(\frac{1+x}{1-x}v\right)^2} - \frac{1}{1+v^2}\right]dv
\\ = \left.\left[\tan^{-1}\left(\frac{1+x}{1-x}v\right) - \tan^{-1}(v)\right]\right|_0^{\tan(t/2)} = \left.\tan^{-1}\left[\frac{2xv}{1 - x + (1+x)v^2}\right]\right|_0^{\tan(t/2)},
\end{multline}
where the last equality comes from the tangent addition identity. The last step is to perform the substitution and use $\tan(t/2) = [1 - \cos(t)]/\sin(t)$ to get
\begin{multline}
\left.\tan^{-1}\left[\frac{2xv}{1 - x + (1+x)v^2}\right]\right|_0^{\tan(t/2)} = \tan^{-1}\left(\frac{2x\sin(t)[1-\cos(t)]}{(1-x)\sin^2(t) +(1+x)[1-\cos(t)]^2}\right)
\\ = \tan^{-1}\left(\frac{2x\sin(t)[1-\cos(t)]}{[1 - x\cos(x)][1-\cos(t)]}\right) = \tan^{-1}\left[\frac{x\sin(t)}{1 - x\cos(t)}\right]
\end{multline}
I've skipped over a fair bit of algebra to give the highlights, but you can check that it all works. So in conclusion,
$$
\int_0^t\frac{x\cos(u) - x^2}{1 - 2x \cos(u) + x^2}du = \tan^{-1}\left[\frac{x\sin(t)}{1 - x\cos(t)}\right],
$$
as desired.
A: I'm not sure this helps but ...
\begin{align}\mathcal{I}&=\displaystyle\int \frac{x\cos u-x^2}{(-2x)\cos u+(x^2+1)}\mathrm du\\&=\underbrace{\displaystyle\int \frac{x\cos u}{-2x\cos u+(x^2+1)}\mathrm du}_{\mathcal{I_1}}-x^2\overbrace{\displaystyle\int \frac{\mathrm du}{-2x\cos u+(x^2+1)}}^{\mathcal{I_2}}\end{align}

\begin{align}\mathcal{I_2}&=\displaystyle\int \frac{\mathrm du}{-2x\cos u+(x^2+1)}\\&=\displaystyle\int \frac{1}{\frac{1-t^2}{1+t^2}(-2x)+x^2+1}\left(\frac{2\mathrm dt}{1+t^2}\right)\, \text{ ,via substituting $t=\tan(u/2)$}\\&=2\displaystyle\int \frac{\mathrm dt}{(t(x+1))^2+(x-1)^2}\\&=\frac{2}{x^2-1}\arctan\left(\frac{(x+1)t}{x-1}\right)\, \text{ ,using the formula $\displaystyle\int \frac{dx}{a^2x^2+b^2}=\frac{1}{ab}\arctan(ax/b)$}\\&=\frac{2}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\end{align}

\begin{align}\mathcal{I_1}&=\displaystyle\int \frac{x\cos u}{-2x\cos u+x^2+1}\, \mathrm du\\&=-x\displaystyle\int\left(\frac{1}{2x}+\frac{x^2+1}{2x(2x\cos u-x^2-1)}\right)\, \mathrm du\\&=\frac{-u}{2}-\frac{x^2+1}{2}\displaystyle\int\frac{\mathrm du}{2x\cos u-x^2-1}\\&=\frac{-u}{2}+\frac{(x^2+1)}{(x^2-1)}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\, \text{ ,using $\mathcal{I_2}$}\end{align}

Therefore,
\begin{align}\mathcal{I}&=-\frac{u}{2}+\frac{x^2+1}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)-\frac{2x^2}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\\&=\frac{-u}{2}-\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\end{align}
Now, you can put the limits.
Footnotes
Weierstrass Substitution
