\(B=\frac{1+cosx}{sinx}\left(1-\frac{\left(1-cosx\right)^2}{sin^2x}\right)=\frac{1+cosx}{sinx}\left(1-\frac{1-2cosx+cos^2x}{sin^2x}\right)\)
\(=\frac{1+cosx}{sinx}\left(\frac{sin^2x-1+2cosx-cos^2x}{sin^2x}\right)=\frac{1+cosx}{sinx}\left(\frac{2cosx-2cos^2x}{sin^2x}\right)\)
\(=\frac{2cosx\left(1+cosx\right)\left(1-cosx\right)}{sinx.sin^2x}=\frac{2cosx\left(1-cos^2x\right)}{sinx.sin^2x}=\frac{2cosx.sin^2x}{sinx.sin^2x}=\frac{2cosx}{sinx}=2cotx\)