Compute $\int_0^{\pi /2}\frac x {\tan x} \, dx$ using contour integration How can I calculate the integral $$\int_0^{\pi /2}\frac x {\tan x} \, dx$$ with complex integration? (Contours, residue theorem, etc.) I was thinking on using the fact that $\displaystyle \tan x=\frac{e^{ix}-e^{-ix}}{i(e^{ix}+e^{-ix})}$, which implies $e^{ix}=z$. I still have not been succesful. 

A complex-analytic solution. Here is a combination of calculus and a basic complex analysis: Perform integration by parts to sanitize the integrand:
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx
= \underbrace{ \left[ \vphantom{\int} x \log\sin x \right]_{0}^{\frac{\pi}{2}} }_{=0}
- \int_{0}^{\frac{\pi}{2}} \log \sin x \, dx. $$
Also notice that, if $x \in (0,\frac{\pi}{2}]$ then $\log|\sin x| = -\log 2 + \operatorname{Re}\log(1 - e^{2ix})$. So
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx
&= - \frac{1}{2} \int_{0}^{\pi} \log |\sin x| \, dx \\
&= \frac{\pi}{2}\log 2 - \frac{1}{2} \operatorname{Re} \left( \int_{0}^{\pi} \log(1 - e^{2ix}) \, dx \right) \\
(z = e^{2ix}) \quad&= \frac{\pi}{2}\log 2 - \frac{1}{4} \operatorname{Re} \left( \oint_{|z|=1} \frac{\log(1 - z)}{iz} \, dz \right),
\end{align*}
Since $z \mapsto \frac{\log(1 - z)}{iz}$ is holomorphic in the unit disc $\mathbb{D}$ and has only logarithmic singularity on the boundary $\partial \mathbb{D}$, we can still apply the Cauchy integral theorem to conclude that the integral vanishes. Therefore we have
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{\pi}{2}\log 2. $$

Alternative complex-analytic solution. Use the substitution $x = \arctan u$ to write
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{-\infty}^{\infty} \frac{\arctan u}{u(u^2+1)} \, du. $$
This hints us that we may use some contour integration technique, but we need to resolve the branch cut of $\arctan$. Here we give one such trick. Notice that
$$ \frac{\arctan u}{u} = \int_{0}^{1} \frac{dt}{1+u^2 t^2}. $$
Plugging this back and interchanging the order of integration, we get
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{0}^{1} \left( \int_{-\infty}^{\infty} \frac{du}{(u^2 t^2+1)(u^2+1)} \right) \, dt. $$
Now we can perform contour integration to obtain that
\begin{align*}
\int_{-\infty}^{\infty} \frac{du}{(u^2 t^2+1)(u^2+1)}
&= 2\pi i \left( \underset{u = i}{\mathrm{Res}} \, \frac{1}{(u^2 t^2+1)(u^2+1)} + \underset{u = i/t}{\mathrm{Res}} \, \frac{1}{(u^2 t^2+1)(u^2+1)} \right) \\
&= \frac{\pi}{t+1}.
\end{align*}
So we have
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{0}^{1} \frac{\pi}{t+1} \, dt = \frac{\pi}{2} \log 2. $$
