How to solve the indefinite integral $\int x \cot x\,\mathrm dx$ We can easily solve it with the bounds $0$ to $\frac{\pi}{2}$, but how to solve the indefinite integral?
Wolfram Alpha gives the following solution:
$$\int x \cot(x)\,\mathrm dx = x \log\left(1 - e^{2 i x}\right) - \frac{1}{2} i\left(x^2 + Li_2(e^{2 i x})\right) + \text{constant}$$
I don't have the Pro access, so I can't check the steps for how to get there. So, can anybody help me with understanding the indefinite integral, and how to solve it?
 A: For the integral $∫x\cot(x)dx$ use integration by parts:
$$\int \operatorname{u} \operatorname{dv}
                    = \operatorname{u}\operatorname{v} -
                    \int \operatorname{v} \operatorname{du}$$
Let$$ u=x, \quad dv=\cot(x)dx
.$$
Then $du=(x)'dx=1dx$ and $v=∫\cot(x)dx=\ln(\sin(x))+C$
The integral can be rewritten as:
$$ \int{x \cot{\left(x \right)} d x} =\color{black}{\left(x \cdot \ln{\left(\sin{\left(x \right)} \right)}-\int{\ln{\left(\sin{\left(x \right)} \right)} \cdot 1 d x}\right)}$$$$=\color{black}{\left(x \ln{\left(\sin{\left(x \right)} \right)} - \int{\ln{\left(\sin{\left(x \right)} \right)} d x}\right)}$$
This integral does not have a closed form:
$$=x \ln{\left(\sin{\left(x \right)} \right)} - \color{black}{\int{\ln{\left(\sin{\left(x \right)} \right)} d x}} =$$$$ x \ln{\left(\sin{\left(x \right)} \right)} - \color{black}{\left(\frac{i x^{2}}{2} - x \ln{\left(1 - e^{2 i x} \right)} + x \ln{\left(\sin{\left(x \right)} \right)} + \frac{i \operatorname{Li}_{2}\left(e^{2 i x}\right)}{2}\right)}$$
Therefore
$$\int{x \cot{\left(x \right)} d x} = - \frac{i x^{2}}{2} + x \ln{\left(\left|{e^{2 i x} - 1}\right| \right)} - \frac{i \operatorname{Li}_{2}\left(e^{2 i x}\right)}{2}$$
Simplify:
$$\int{x \cot{\left(x \right)} d x} = - \frac{i x^{2}}{2} + x \ln{\left(\sin{\left(x \right)} \right)} + x \ln{\left(2 \right)} - \frac{i \operatorname{Li}_{2}\left(e^{2 i x}\right)}{2}+C$$ where $C$ is the constant of integration.

$\mathrm{Li}$ is the Logarithmic integral function. See here: https://en.wikipedia.org/wiki/Logarithmic_integral_function
Addendum: Remebering $$\begin{cases} \sin x = \dfrac {e^{ix}-e^{-ix}} {2i} \\ \cos x = \dfrac {e^{ix} + e^{-ix}} {2} \end{cases}$$
$$\int{\ln(\sin(x)) d x}=x\ln\left(-\dfrac{\mathrm{i}\cdot\left(\mathrm{e}^{\mathrm{i}x}-\mathrm{e}^{-\mathrm{i}x}\right)}{2}\right)-\mathrm{i}\cdot\left(-\mathrm{i}x\ln\left(\mathrm{e}^{\mathrm{i}x}-\mathrm{e}^{-\mathrm{i}x}\right)-\dfrac{-2\mathrm{i}x\ln\left(\mathrm{e}^{-\mathrm{i}x}+1\right)-2\mathrm{i}x\ln\left(1-\mathrm{e}^{-\mathrm{i}x}\right)+x^2}{2}-\mathrm{i}x\ln\left(\mathrm{e}^{-\mathrm{i}x}+1\right)+\operatorname{Li}_2\left(\mathrm{e}^{-\mathrm{i}x}\right)+\operatorname{Li}_2\left(-\mathrm{e}^{-\mathrm{i}x}\right)-\mathrm{i}x\ln\left(1-\mathrm{e}^{-\mathrm{i}x}\right)\right)$$
