Evaluating$\int {1\over1-\sin2x}dx$ $$
\int {1\over1-\sin 2x}dx = \int {1\over \sin^2 x-2\sin x\cos x+\cos^2x}dx = \int {1\over (\sin x-\cos x)^2}dx
$$
From here I get two different answers, depending on whether I factor out $\sin x$ or $\cos x$.
Factoring out $\sin x$, this one is correct according to WolframAlpha:
$$=\int {1\over [\sin x(1-{\cos x\over \sin x})]^2}dx=\int {1\over \sin^2x(1-{\cos  x\over \sin x})^2}dx = \int {1\over(1-\cot x)^2}d(1-\cot x)$$
$$={1\over \cot x-1}+C$$
But when I factor out $\cos x$:
$$=\int {1\over [\cos x({\sin x\over \cos x}-1)]^2}dx=\int {1\over \cos^2x({\sin x\over \cos x}-1)^2}dx = \int {1\over(\tan x-1)^2}d(\tan x-1)$$
$$={1\over 1-\tan x}+C$$
I bet it's just some stupid typo that I'm missing, I can't figure it out.
Thanks.

They are both correct. To see this, you can simply take the derivative of each antiderivative to get your original integral back. This shows that both primitives you found are equal, up to a constant.
$$\frac{d}{dx} \left(\frac{1}{\cot x - 1}\right) = \frac{1}{\left(\cos x - \sin x\right)^2}$$
$$\frac{d}{dx} \left(\frac{1}{\tan x - 1}\right) = \frac{1}{\left(\cos x - \sin x\right)^2}$$
\begin{eqnarray*}
\left(\cos x - \sin x\right)^2 &=& (\cos x - \sin x)(\cos x - \sin x)\\
&=& \cos^2 x - 2 \sin x \cos x + \sin^2 x\\
&=& 1 - \sin 2x 
\end{eqnarray*}
In your first line, you have
\begin{eqnarray*}
(\sin x - \cos x)^2 &=& (\sin x - \cos x)(\sin x - \cos x)\\
&=& \sin^2 x - 2 \sin x \cos x + \cos^2 x\\
&=& 1-\sin 2x
\end{eqnarray*}
As you can see, these are equivalent.
