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'd rather have a more elegant way to do this, but this way at least works:
You've shown that $\cos x = \dfrac{1-t^2}{1+t^2}$, and then that $\sin^2 x = \dfrac{4t^2}{(1+t^2)^2}$.
Notice that if you start with $a=b=3$ and then square both sides of $a=b$ to get $a^2=b^2$, you can deduce that $a = \pm b$.  That just means that either $a=b$ or $a=-b$; it doesn't mean $a$ is equal to both $b$ and $-b$.  So you must conclude that for each value of $x$, either $\sin x = \dfrac{2t}{1+t^2}$ or $\sin x = \dfrac{-2t}{1+t^2}$.  Might it be equal to that first expression for some values of $x$ and the second for others? If so, things would get somewhat more complicated.  But now look at the graphs of $x\mapsto\sin x$ and $x\mapsto \tan\dfrac x 2$ on the interval $-\pi\le x\le\pi$.  What you see is that $\sin x\ge0$ if $\tan\dfrac x 2\ge0$ and $\sin \le 0$ if $\tan\dfrac x 2\le 0$.  Consequently you have $\sin x = \dfrac{2t}{1+t^2}$ for all values of $x$.  Now compare the graphs of $x\mapsto\cos x$ and $x\mapsto \tan\dfrac x 2$ on that same interval, and observe that $\cos x\ge 0$ if $-1\le\tan \dfrac x 2\le 1$ and $\cos x\le 0$ if $\tan\dfrac x 2\ge 1$ or $\tan\dfrac x 2\le -1$.  That is the behavior of $\dfrac{1-t^2}{1+t^2}$ and not of $-\dfrac{1-t^2}{1+t^2}$. That decides between $\text{“}{+}\text{''}$ and $\text{“}{-}\text{''}$.
