Evaluate $\int\frac{\cot{x}}{1+\sin{x}+\cos{x}} \mathrm dx$ Find this integral:
$$\int\dfrac{\cot{x}}{1+\sin{x}+\cos{x}}\mathrm dx$$
My try: since
$$1+\sin{x}+\cos{x}=2\cos^2{\dfrac{x}{2}}+2\sin{\dfrac{x}{2}}\cos{\dfrac{x}{2}}$$
$$\cot{x}=\dfrac{1-\tan^2{\dfrac{x}{2}}}{2\tan{\dfrac{x}{2}}}$$
so
$$\dfrac{\cot{x}}{1+\sin{x}+\cos{x}}=\dfrac{1-\tan^2{\dfrac{x}{2}}}{2\tan{\dfrac{x}{2}}\left(2\cos^2{\dfrac{x}{2}}+2\sin{\dfrac{x}{2}}\cos{\dfrac{x}{2}}\right)}$$
then I fell very ugly.Thank you 
 A: Now divide the numerator & the denominator by $\displaystyle \sec^2\frac x2=1+\tan^2\frac x2$
So, we have $I=\displaystyle\int\frac{1-\tan^2\frac x2}{2\tan\frac x2(2+2\tan\frac x2)}\sec^2\frac x2dx$
Putting $\displaystyle \tan\frac x2=u$
$$I=\int\frac{1-u^2}{2u(1+u)}du=\frac12\int\frac1u du-\frac12\int du$$ assuming $1+u\ne0$
A: Let
$$I=\int \frac{\cot x}{1+\sin x+\cos x} \operatorname{d}x$$
Substitute $t = \tan\left(\frac{x}{2}\right)$ and  $\operatorname{d}t = \frac{1}{2} \sec^2\left(\frac{x}{2}\right)  \operatorname{d}x$, and transform the integrand using the substitutions $\sin x  = \frac{2 t}{t^2+1}, \cos x = \frac{1-t^2}{t^2+1}$ and  $\operatorname{d}x = \frac{2 }{t^2+1}\operatorname{d}t$:
$$I=   \int -\frac{t^2-1}{t(t^2+1)\left(1+\frac{2 t}{t^2+1}+\frac{1-t^2}{t^2+1}\right)} \operatorname{d}t= \int \frac{1}{2}\left(\frac{1}{t}-1\right) \operatorname{d}t=\frac{1}{2}(\ln t+t)+C$$
Substitute back for $t = \tan\left(\tfrac{x}{2}\right)$ and finally
$$
 I =  \frac{1}{2}\left[\ln\left(\tan\left(\tfrac{x}{2}\right)\right)-\tan\left(\tfrac{x}{2}\right)\right]+C.
$$
