Trigonometric substitution $\tan{\frac{x}{2}}=t$. What is $\cos{x}$ then? For example, the integral is:
$$\int \frac{\sin{x}}{3\sin{x}+4\cos{x}}dx$$
And we use the substitution: $\tan{\frac{x}{2}}=t$
Now, to get $\cos{x}$ in terms of $\tan\frac{x}{2}$, I first expressed $\cos^2\frac{x}{2}$ and $\sin^2\frac{x}{2}$ in temrs of $\tan\frac{x}{2}$:
$$\cos^2\frac{x}{2}=\frac{1}{\frac{1}{\cos^2\frac{x}{2}}}=\frac{1}{\frac{\sin^2\frac{x}{2}+\cos^2\frac{x}{2}}{\cos^2\frac{x}{2}}}=\frac{1}{1+\tan^2\frac{x}{2}}=\frac{1}{1+t^2}$$
$$\sin^2\frac{x}{2}=1-\cos^2\frac{x}{2}=1-\frac{1}{1+t^2}=\frac{t^2}{1+t^2}$$
Now, using trig idendity: $\cos{2x}=\cos^2{x}-\sin^2{x}$ we have:
$$\cos{x}=\bigg(\cos^2\frac{x}{2}-\sin^2\frac{x}{2}\bigg)=\frac{1}{1+t^2}-\frac{t^2}{1+t^2}=\frac{1-t^2}{1+t^2}$$
which is good, but, I don't know what is wrong with this next procedure (first, getting $\sin^2{x}$, then using trig identity $\sin^2{x}+\cos^2{x}=1$ getting $\cos{x}$).
So, first, expressing $\sin{x}$ in terms of $\tan\frac{x}{2}$ using trig identity $\sin{2x}=2\sin{x}\cos{x}$:
$$\sin^2{x}=4\sin^2\frac{x}{2}\cos^2\frac{x}{2}=4\cdot\frac{t^2}{1+t^2}\cdot\frac{1}{1+t^2}=\frac{4t^2}{(1+t^2)^2}$$
So:
$$\cos^2{x}=1-\sin^2{x}=1-\frac{4t^2}{(1+t^2)^2}=\frac{t^4-2t^2+1-4t^2}{(1+t^2)^2}=\frac{(t^2-1)^2}{(t^2+1)^2}$$
And, $\cos{x}$ is then:
$$\cos{x}=\pm\frac{t^2-1}{t^2+1}$$
Why do I get $\pm$ here? Did I make a mistake somewhere? Thank you for your time.

I hope it's better to write $$\sin x=A(3\sin x+4\cos x)+B\cdot\dfrac{d(3\sin x+4\cos x)}{dx}$$
and find $A,B$ by comparing the coefficients $\sin x,\cos x$
Can you take it from here?
