# How to simplify the trigonometric term?

Simplify $$\frac{2\tan\left(\frac{x}{2}\right)}{\left(\tan\left(\frac{x}{2}\right)-1\right)^2} + \frac{\tan^2\left(\frac{x}{2}\right)+1}{2\tan\left(\frac{x}{2}\right)}$$

It should be like: $$\frac{2\sin(x) - 2\sin^2(x) - 2}{2(\sin(x)-1)\sin(x)}$$ I can use any trigonometric identities, for example: $$\tan\left(\frac{x}{2}\right)=\frac{1-\cos(x)}{\sin(x)}$$

Let $y=\dfrac x2$.
Then using the identities $$\sec^2y=1+\tan^2y\tag{1}$$ $$\sin 2y=2\sin y\cos y\tag{2}$$ the expression becomes \begin{align}\frac{2\tan y}{(\tan y-1)^2}+\frac{\tan^2y+1}{2\tan y}&=\frac{2\tan y}{\tan^2y+1-2\tan y}+\frac{\sec^2y}{2\tan y}\tag{1}\\&=\frac{\frac{2\sin y}{\cos y}}{\frac1{\cos^2y}-\frac{2\sin y}{\cos y}}+\frac{\frac1{\cos^2y}}{\frac{2\sin y}{\cos y}}\tag{1}\\&=\frac{2\sin y\cos y}{1-2\sin y\cos y}+\frac1{2\sin y\cos y}\\&=\frac{\sin2y}{1-\sin2y}+\frac1{\sin2y}\tag{2}\\&=\frac{\sin^22y-\sin2y+1}{\sin2y(1-\sin2y)}\\&=\frac{\sin^2x-\sin x+1}{\sin x(1-\sin x)}\\&=\boxed{\frac{2\sin x - 2\sin^2 x - 2}{2(\sin x-1)\sin x}}\end{align} as you have stated.