Integrating $ \int \frac{1}{1-\tan(x)}dx $ $$ \int \frac{dx}{1-\tan(x)} $$
Please help me to solve this problem as I'm trying this since last 1 day...
 A: $$\int \frac 1{1-\tan(x)}dx=\int \frac {\cos(x)}{\cos(x)-\sin(x)}dx$$
$$=\frac 12\int \frac {\cos(x)+\sin(x)+\cos(x)-\sin(x)}{\cos(x)-\sin(x)}dx$$
$$=\frac 12\int 1+\frac {\cos(x)+\sin(x)}{\cos(x)-\sin(x)}dx$$
With the result :
$$\int \frac 1{1-\tan(x)}dx=C+\frac {x-\log(\cos(x)-\sin(x))}2$$
A: Hint:
 Since your integral is as $$\int\frac{\cos(x)\,dx}{\cos(x)-\sin(x)}=\int R(\sin(x),\cos(x))\,dx$$ wherein $R$ is rational function respect to $\sin(x)$ and $\cos(x)$; you can use the following change of variable: $$t=\tan(x/2), -\pi<x<\pi$$
A: An alternative is to use the substitution $t=\tan x$ and then expand into partial fractions. 
$$\begin{equation*}
dt=\left( 1+\tan ^{2}x\right) dx=\left( 1+t^{2}\right) dx
\end{equation*}$$
$$\begin{equation*}
I=\int \frac{1}{1-\tan x}dx=\int \frac{1}{\left( 1-t\right) \left(
1+t^{2}\right) }\,dt.
\end{equation*}$$
Since
$$\begin{equation*}
\frac{1}{\left( 1-t\right) \left( 1+t^{2}\right) }=\frac{1}{2\left(
1-t\right) }+\frac{1}{2}\frac{t}{1+t^{2}}+\frac{1}{2}\frac{1}{1+t^{2}},
\end{equation*}$$
we have
$$\begin{eqnarray*}
I &=&\frac{1}{2}\int \frac{1}{1-t}\,dt+\frac{1}{2}\int \frac{t}{1+t^{2}}\,dt+
\frac{1}{2}\int \frac{1}{1+t^{2}}\,dt \\
&=&-\frac{1}{2}\ln \left\vert 1-t\right\vert +\frac{1}{4}\ln \left\vert
1+t^{2}\right\vert +\frac{1}{2}\arctan t+C \\
&=&-\frac{1}{2}\ln \left\vert 1-\tan x\right\vert +\frac{1}{4}\ln \left\vert
1+\tan ^{2}x\right\vert +\frac{x}{2}+C \\
&=&-\frac{1}{2}\ln \left\vert 1-\tan x\right\vert +\frac{1}{2}\ln \left\vert
\sec x\right\vert +\frac{x}{2}+C. 
\end{eqnarray*}$$
This can be written as
$$\begin{eqnarray*}
I &=&-\frac{1}{2}\ln \left\vert \frac{1-\tan x}{\sec x}\right\vert +\frac{x}{
2}+C \\
&=&-\frac{1}{2}\ln \left\vert \cos x-\sin x\right\vert +\frac{x}{2}+C.
\end{eqnarray*}$$
