This problem came from some other website, where someone asked for help with the integral
$$\int\frac {x \, dx}{1-\cos x}$$
After adding my suggestion of integration by parts to an existing suggestion of multiplying top and bottom by $1+\cos x$, he thanked us for his help and posted his solution. Due to a trig identity I didn't recognize and formatting issues with the lack of latex, I posted my own solution. I see his logic now, but what I don't see are how the 2 results are equivalent.
Both methods start the same way by multiplying top and bottom by $1+\cos x$.
$$\int\frac{x(1+\cos x) \, dx}{\sin^2x \, dx}=\int x(\csc^2x+\csc x\cot x) \, dx$$
My method was to use integration by parts here.
$$u=x,\quad du=dx$$ $$dv=(\csc^2x+\csc x\cot x) \, dx,\quad v=-\cot x -\csc x$$ $$\int x(\csc^2x+\csc x\cot x) \, dx=-x\cot x-x\csc x+\int(\cot x +\csc x) \, dx=$$ $$-x\cot x-x\csc x-\int\frac{-\cos x}{\sin x} \, dx-\int\frac{-\cot x\csc x-\csc^2x}{\cot x+\csc x} \, dx=$$ $$-x\cot x-x\csc x-\ln(\sin x)-\ln(\cot x+\csc x)+C=$$ $$-x\cot x-x\csc x+\ln(\csc x)+\ln\frac1{\cot x+\csc x}+C=$$ $$-x\cot x-x\csc x+\ln(\csc x)+\ln\frac{\csc x-\cot x}{\csc^2x-\cot^2x}+C=$$ $$-x\cot x-x\csc x+\ln(\csc^2x-\csc x\cot x)+C$$
Hopefully, the next method will be shorter. He also did integration by parts with the same substitutions, but used the reciprocal of a tangent half-angle formula to obtain
$$v=-\csc x-\cot x=-\cot\frac x2$$
making the result of his integration by parts
$$-x\cot\frac x2+\int\cot\frac x2=-x\cot\frac x2-2\int\frac{-\frac12\cos\frac x2}{\sin\frac x2}=$$
$$-x\cot\frac x2-2\ln\left(\sin\frac x2\right)$$
Given the identity he used, the first part seems to agree, but I can't seem to show that
$$-2\ln\left(\sin\frac x2\right)=\ln(\csc^2x-\csc x\cot x)+C$$
I tried the following
$$-2\ln\left(\sin\frac x2\right)=\ln\left(\frac1{\sin^2\frac x2}\right)=\ln\left(\frac2{1-\cos x}\right)=\ln\left(\frac{2+2\cos x}{\sin^2x}\right)=\ln(2\csc^2x+2\csc x\cot x)$$
which does not agree. So where is the mistake?