integration by substitution, using $\;t = \tan \left(\frac 12 x\right)$ $\displaystyle\int_0^\frac{\pi}{2}\frac{1}{2-\cos x} \, dx$ using the substitution $t=\tan\frac{1}{2}x$

  
*
  
*$x=2\tan^{-1}t$
  
*$\dfrac{dx}{dt}=\dfrac{2}{1+t^2}$
  
*$dx=\dfrac{2}{1+t^2}\,dt$
  
*$\displaystyle\int_0^1 \left(\frac{1}{2-\cos x}\right)\left(\frac{2}{1+t^2}\right)\,dt$ 

Is this the right idea? If so what do I do next?
$\displaystyle\int_0^1\left(\frac{1}{2-\frac{1-t^2}{1+t^2}}\right) \,\left(\frac{2}{1+t^2}\right)\, dt$
$\displaystyle\int_0^1\frac{2}{1+3t^2}\,dt$
$=2\left[\frac{\ln(1+3t^2)}{6t}\right]_0^1$
 A: If $\;t = \tan\left(\frac 12 x\right)$, i.e., $\,x = 2\tan^{-1}t,\,$ what should $\dfrac 1{2 - \cos x}$ then be?
We need to replace the function (integrand) of $x$ to one expressed as a function of $t$.
What are the new limits for $\,t\,$ if $\;t = \tan\left(\frac 12 x\right)$?
When $x = 0,\;$ $t = \tan\left(\frac 02\right) = 0$. Okay. But, when $x = \pi/2$, the upper limit of integration needs to be $t = \tan\left(\pi/4\right)$
See Weierstrass Substitution for why $\;\cos x = \dfrac{1-t^2}{1+t^2},\;$ and in general, for the logic of using "$t$-substitution": $t = \tan \frac x2$.

ADDED:
After substituting all of the above, we should have the integrand:
$$\frac{1}{2-\dfrac{1-t^{2}}{1+t^{2}}}\frac{2}{1+t^{2}}=\frac{2}{2(1+t^{2})-(1-t‌​^{2})}=\frac{2}{1+3t^{2}}=\frac{2}{1+(\sqrt{3}t)^{2}}$$
So we have
$$\int_0^1 \frac{2}{1+(\sqrt{3}t)^{2}}\,dt = 2\int_0^1 \frac{1}{1+(\sqrt{3}t)^{2}}\,dt\tag{1}$$
Now, I'm afraid to say, the work isn't done yet. We cannot use $\ln|f(t)|$ where $f(t) =1 + \sqrt{3}t)^{2}$ because we do not have an integrand in the form of $\;\dfrac{f'(t)}{f(t)} \,dx$.
But we're all set up with $(1)$ to use the substitution $$u = \sqrt 3 t.\,\implies du = \sqrt 3 dt \implies dt = \dfrac{1}{\sqrt 3} du$$
Then we have an integrand of the form $$2 \int_0^{\sqrt 3} \dfrac{1}{\sqrt 3} \dfrac{1}{1 + u^2}\,du = \dfrac{2}{\sqrt 3}\int_0^{\sqrt 3}  \dfrac{1}{1 + u^2}\,du\tag{2}$$
Now, we recall that $$\int \dfrac {1}{1 + u^2} \,du = \tan^{-1}u + C\tag{$\star$}$$
Can you try and finish it from here? Apply $\star$ to the integral given by $(2)$

$(\star)$ See trigonometric substitution for integrals involving $a^2 + u^2$, where $a$ is a constant. Our integral is of the same form, with $a = 1$:
$$\int \frac{du}{a^2 + u^2} = \frac 1a\tan^{-1}\left(\frac ua\right)\,+ C$$
A: Hint: 
When $\tan \dfrac{x}{2}=t$ you have $ \cos x= \dfrac{1-t^2}{1+t^2}$
A: If $x=2\arctan t$ then $\cos x = \cos\left(2\arctan t\right)$.  Use the fact that $\cos(2u)=\cos^2u-\sin^2u$.  So you get
$$
\cos x = \cos^2\left(\arctan t \right) -\sin^2\left(\arctan t \right)
$$
If $\varphi=\arctan t$ then $\dfrac t1=t = \tan\varphi=\dfrac{\text{opposite}}{\text{adjacent}}$, so $\cos\varphi=\dfrac{\text{adjacent}}{\text{hypotenuse}}$.  So $\text{opposite}=t$, $\text{adjacent}=1$, and by the Pythagorean theorem $\text{hypotenuse}=\sqrt{1+t^2}$.
Then $\cos=\dfrac{\text{adjacent}}{\text{hypotenuse}}$ and so
$$
\cos^2(2\arctan t) = \cos^2 (\cdot)-\sin^2(\cdot) = \left(\frac{1}{\sqrt{1+t^2}}\right)^2 - \left(\text{something similar}\right)^2 = \cdots\cdots
$$
