Transform $\frac{-2}{\tan\frac{x}{2}+1}$ to $\tan x-\sec x$? I'm learning to integrate and was asked to integrate $\int\frac{1}{1+\sin x}dx$
I get the answer $-\frac{2}{\tan\frac{x}2+1}+c$ which Symbolab confirms is correct, but the textbook says the answer is $\tan x-\sec x+c$.
I can't seem to transform my answer to that one using trig identities. Any idea how/if one can get that result?
Many thanks,
Andrew

Let $$f(x) = \frac{-2}{\tan \frac{x}{2} + 1}, \quad g(x) = \tan x - \sec x.$$
Then the first thing to note is that $f(0) = -2$, whereas $g(0) = -1$.  So if $f$ and $g$ differ by a constant, this difference must satisfy $g(x) - f(x) = 1$.  Consequently,
$$\begin{align}
f(x) + 1 &= 1 - \frac{2}{\tan \frac{x}{2} + 1} \\
&= \frac{\tan \frac{x}{2} - 1}{\tan \frac{x}{2} + 1} \\
&= \frac{\sin \frac{x}{2} - \cos \frac{x}{2}}{\sin \frac{x}{2} + \cos \frac{x}{2}} \\
&= \frac{(\sin \frac{x}{2} - \cos \frac{x}{2})^2}{\sin^2 \frac{x}{2} - \cos^2 \frac{x}{2}} \\
&= \frac{\sin^2 \frac{x}{2} - 2 \sin \frac{x}{2} \cos \frac{x}{2} + \cos^2 \frac{x}{2}}{-\cos x} \\
&= \frac{\sin x - 1}{\cos x} \\
&= \tan x - \sec x \\
&= g(x).
\end{align}$$
