Calculation of $\int\frac1{\tan \frac{x}{2}+1}dx$ Calculation of $\displaystyle \int\frac{1}{\tan \frac{x}{2}+1}dx$
$\bf{My\; Try}::$ Let $\displaystyle I = \displaystyle \int\frac{1}{\tan \frac{x}{2}+1}dx$, Now let $\displaystyle \tan \frac{x}{2}=t\;,$ Then $\displaystyle dx=\frac{2}{1+t^2}dt$
So $\displaystyle I = 2\int\frac{1}{(1+t)\cdot (1+t^2)}dt$
Now Using Partial fraction, 
$\displaystyle \frac{1}{(1+t)\cdot (1+t^2)} = \frac{A}{1+t}+\frac{Bt+C}{1+t^2}\Rightarrow 1=A(1+t^2)+(Bt+C)(1+t)$
Now put $(1+t)=0\Rightarrow t=-1\;,$ We get $\displaystyle 1=2A\Rightarrow A = \frac{1}{2}.$
Now Put $(1+t^2)=0\Rightarrow t^2=-1\;,$ We Get $1=Bt^2+(B+C)t+C$
So $\displaystyle 1=\left(-B+C\right)+(B+C)$. So Solving equation...$B+C=0$ and $-B+C=1$
So $\displaystyle B=-\frac{1}{2}$ and $\displaystyle C=\frac{1}{2}$
So $\displaystyle I = 2\int\frac{1}{(1+t)\cdot (1+t^2)}dt = \int\frac{1}{1+t}dt+\int\frac{-t+1}{1+t^2}dt$
So $\displaystyle I = \frac{1}{1+t}dt-\frac{1}{2}\int\frac{2t}{1+t^2}dt+\int \frac{1}{1+t^2}dt$
So $\displaystyle I = \ln \left|1+t\right|-\frac{1}{2}\ln \left|1+t^2\right|+\tan^{-1}(t)+\mathcal{C}$
So $\displaystyle I = \ln \left|1+\tan \frac{x}{2}\right|-\frac{1}{2}\ln \left|1+\tan^2 \frac{x}{2}\right|+\frac{x}{2}+\mathcal{C}$
Can we solve it without using partial fraction? If yes then please explain to me.
Thanks
 A: Partial fractions can be avoided, but we need to integrate both $\sec x$ and $\tan x$:
\begin{align}
\frac{1}{\tan(x/2)+1} & = \frac{1}{\tan(x/2)+1} \cdot \frac{\cos(x/2)}{\cos(x/2)} \cdot \frac{\cos(x/2)-\sin(x/2)}{\cos(x/2)-\sin(x/2)} \\[0.1in] 
& = \frac{\cos(x/2)}{\sin(x/2)+\cos(x/2)} \cdot \frac{\cos(x/2)-\sin(x/2)}{\cos(x/2)-\sin(x/2)} \\[0.1in]
& = \frac{\cos(x/2)\big(\cos(x/2)-\sin(x/2)\big)}{\cos^2(x/2)-\sin^2(x/2)} \\[0.1in]
& = \frac{\cos^2(x/2)-\cos(x/2)\sin(x/2)}{\cos x} \\[0.1in]
& = \frac{\frac{1}{2}(\cos x+1)-\frac{1}{2}\sin x}{\cos x} \\[0.1in]
& = \frac{1}{2} \bigg(1+\sec x - \tan x\bigg).
\end{align}
A: Hint:
Multiply the denominator and nominator of the fraction by $\cos x/2(\sin x/2-\cos x/2)$. At the bottom you get $-\cos x$, on the top you get $-\cos^2 x/2+1/2\sin x$.
What can you do with $\cos^2 x/2$?
A: Thanks E W H Lee and shooting-squirrel
Another Try:: Let $\displaystyle I =\int\frac{1}{\tan \frac{x}{2}+1}dx$
Let $x=2y\;,$ Then $dx = 2dy$. So $\displaystyle I = 2\int\frac{1}{\tan y+1}dy = \int\frac{2\cos y}{\sin y+\cos y}dy$
So $\displaystyle I = \int\frac{\left(\cos y+\sin y\right)+\left(\cos y-\sin y\right)}{\sin y+\cos y}dy = y+\ln \left|\sin y+\cos y\right|+\mathcal{C}$
So $\displaystyle I =\int\frac{1}{\tan \frac{x}{2}+1}dx = \frac{x}{2}+\ln \left|\sin \frac{x}{2}+\cos \frac{x}{2}\right|+\mathcal{C}$
A: Set $t=\dfrac{x}{2}$, then multiply the integrand by $\cos t$, we get
\begin{equation}
\frac{2\cos t}{\cos t+\sin t}
\end{equation}
then let
\begin{equation}
I=\int\frac{2\cos t}{\cos t+\sin t}dt
\end{equation}
and
\begin{equation}
J=\int\frac{2\sin t}{\cos t +\sin t}dt
\end{equation}
Find $I+J$ and $I-J$, where $I-J$ can be found by using
\begin{equation}
\int\frac{f'(x)}{f(x)}dx=\ln\left|f(x)\right|+C
\end{equation}
We have
\begin{equation}
I+J = 2t+C
\end{equation}
and
\begin{equation}
I-J = 2\ln|\cos t +\sin t|+C
\end{equation}
So
\begin{equation}
I =\int\frac{1}{\tan \frac{x}{2}+1}dx = \frac{x}{2}+\ln \left|\sin \frac{x}{2}+\cos \frac{x}{2}\right|+C
\end{equation}
