Better way to evaluate $\int \frac{dx}{\left (a +b\cos x \right)^2}$ $$\int \frac{dx}{\left (a +b\cos x \right)^2}$$
$$u=\frac{b +a \cos x}{a +b\cos x }$$
$$du=\frac{\sin x\left(b^2 -a^2\right)}{ \left (a +b.\cos x \right)^2}$$
$$\frac{du}{\sin x\left(b^2 -a^2\right)}=\frac{dx}{\left (a +b\cos x \right)^2}$$
$$\cos x=\frac{au -b}{a - bu}  $$
$$\sin x=\sqrt{1-\left(\frac{au -b}{a - bu}\right)^2}$$
 It is becoming messy with this .I also tried it using half angle formula but didn't find it good.

Hint:
Rationalize with $z=e^{ix}$ (and $dz=iz\,dx$),
$$\int \frac{dx}{\left (r+\cos x \right)^2}
=\int\frac{dz}{iz\left(r+\dfrac{z+z^{-1}}2\right)^2}
=\int\frac{4z\,dz}{i\left(z^2+2rz+1\right)^2}
=\int\frac{4(z+r-r)\,dz}{i\left((z+r)^2+1-r^2\right)^2}.
$$
This yields a term $\log({z^2+2rz+1})=\log(r+\cos x)$ and, depending on the sign of $1-r^2$, an $\arctan$ or $\text{artanh}$.
