Here you go my friend:

$\displaystyle \int\frac{dx}{a+b\cos(x)}$

Let $\displaystyle x\longmapsto 2\arctan(z)$ so we get $\displaystyle dx=\frac{2}{1+z^2}dz$. So subbing gives

$\displaystyle \int\frac{dx}{a+b\cos(x)}\stackrel{x=2\arctan{z}}{ \longmapsto}2\int\frac{1}{a+b\cos\left(2\arctan(z) \right)}\cdot\frac{dz}{1+z^2}$

Now remember three things

$\displaystyle \cos(2\phi)=\cos^2(\phi)-\sin^2(\phi)\quad(1)$

$\displaystyle \cos(\arctan(\phi))=\frac{1}{\sqrt{1+\phi^2}}\quad (2)$

$\displaystyle \sin(\arctan(\phi))=\frac{\phi}{\sqrt{1+\phi^2}}\q uad(3)$

So combining these three things we can see that

$\displaystyle \begin{aligned}\cos\left(2\arctan(z)\right)&=\cos^ 2\left(\arctan(z)\right)-\sin^2\left(\arctan(z)\right)\\

&=\left(\frac{1}{\sqrt{1+z^2}}\right)^2-\left(\frac{z}{\sqrt{1+z^2}}\right)^2\\

&=\frac{1}{1+z^2}-\frac{z^2}{1+z^2}\end{aligned}$

So

$\displaystyle \begin{aligned}2\int\frac{dz}{a+b\cos\left(2\arcta n(z)\right)}\cdot\frac{1}{1+z^2}&=2\int\frac{dz}{a +\frac{b}{1+z^2}-\frac{bz^2}{1+z^2}}\cdot\frac{1}{1+z^2}\\

&=2\int\frac{dz}{a(1+z^2)+b-bz^2}\\

&=2\int\frac{dz}{(a-b)z^2+a+b}\end{aligned}$

Now consider this. We can rewrite $\displaystyle (a-b)z^2$ as $\displaystyle \left(\sqrt{a-b}z\right)^2$

So now make a trig sub $\displaystyle \sqrt{a-b}z\longmapsto\sqrt{a+b}\tan(\vartheta)$ so $\displaystyle dz=\frac{\sqrt{a+b}}{\sqrt{a-b}}\sec^2(\vartheta)d\vartheta$

Subbing this gives

$\displaystyle \begin{aligned}2\int\frac{dz}{\left(\sqrt{a-b}z\right)^2+a+b}&\stackrel{\sqrt{a-b}z=\sqrt{a+b}\tan(\vartheta)}{\longmapsto}2\frac{ \sqrt{a+b}}{\sqrt{a-b}}\int\frac{\sec^2(\vartheta)}{\left(\sqrt{a+b}\t an(\vartheta)\right)^2+a+b}d\vartheta\\

&=\frac{2}{\sqrt{a-b}\sqrt{a+b}}\int\frac{\sec^2(\vartheta)}{\tan^2(\ vartheta)+1}d\vartheta\end{aligned}$

Now remember that

$\displaystyle \begin{aligned}\tan^2(\phi)+1&=\frac{\sin^2(\phi)} {\cos^2(\phi)}+1\\

&=\frac{\sin^2(\phi)+\cos^2(\phi)}{\cos^2(\phi) }\\

&=\frac{1}{\cos^2(\phi)}\\

&=\sec^2(\phi)\end{aligned}$

So

$\displaystyle \begin{aligned}\frac{2}{\sqrt{a-b}\sqrt{a+b}}\int\frac{\sec^2(\vartheta)}{\tan^2(\ vartheta)+1}d\vartheta&=\frac{2}{\sqrt{a-b}\sqrt{a+b}}\int~d\vartheta\\

&=\frac{2\vartheta}{\sqrt{a-b}\sqrt{a+b}}\end{aligned}$

So we must make our tedious backsubs

$\displaystyle \sqrt{a-b}z=\sqrt{a+b}\tan(\vartheta)\implies \arctan\left(\frac{\sqrt{a-b}z}{\sqrt{a+b}}\right)=\vartheta$

But now remember that $\displaystyle x=2\arctan(z)\implies \tan\left(\frac{x}{2}\right)=z$

So we finally get

$\displaystyle \int\frac{dx}{a+b\cos(x)}=\frac{2\arctan\left(\fra c{\sqrt{a-b}\tan\left(\frac{x}{2}\right)}{\sqrt{a+b}}\right) }{\sqrt{a^2-b^2}}+C$

I hope that helps