How to calculate the definite integral of $\frac {\tan(x)}{x}$ (The Cauchy principal value of)
$$
\int_0^{\infty}\frac{\tan x}{x}\mathrm dx
$$
I tried to cut this integral into $$\sum_{k=0}^{\infty}\int_{k\pi}^{(k+1)\pi}\frac{\tan x}{x}\mathrm dx$$
And then
$$\sum_{k=0}^{\infty}\lim_{\epsilon \to 0}\int_{k\pi}^{(k+1/2)\pi-\epsilon}\frac{\tan x}{x}\mathrm dx+\int_{(k+1/2)\pi+\epsilon}^{(k+1)\pi}\frac{\tan x}{x}\mathrm dx$$
$$\sum_{k=0}^{\infty}\int_{k\pi}^{(k+1/2)\pi}\frac{((2k+1)\pi-2x)\tan x}{((2k+1)\pi-x)x}\mathrm dx$$
And I did not know how to continue. I did not know if I was right or not. How to calculate this integral?
 A: You seem to be on the right track.
We have $$ P\int_0^\infty \frac{\tan{x}}{x}dx = P\int_0^\pi \frac{\tan x}{x}dx + P\int_0^\pi\frac{\tan x}{\pi + x}dx + P\int_0^\pi \frac{\tan x}{2\pi + x}dx+\ldots$$ and then we have $$ P\int_0^\pi \frac{\tan x}{k\pi +x}dx = \int_0^{\pi/2} \tan x\left(\frac{1}{k\pi+x} - \frac{1}{(k+1)\pi-x}\right)dx $$
Finally, $$ \sum_{k=0}^\infty \frac{1}{k\pi+x} - \frac{1}{(k+1)\pi-x} =\cot x,$$ so $$ P\int_0^\infty \frac{\tan{x}}{x}dx = \int_{0}^{\pi/2}\tan x\cot x \;dx = \pi/2.$$
A: This can also be handled using contour integration. Since there are no singularities inside $\gamma$,
$$
\int_\gamma\frac{\tan(z)}z\,\mathrm{d}z=0
$$
where $\gamma$ is the contour

where $k\to\infty$ then $m\to\infty$.
First notice that the integrals along all the small arcs, which are $-\pi i$ times the residues at the singularities of $\frac{\tan(z)}z$, cancel out for each $k$.
Since $\tan(z)=i\tanh(\operatorname{Im}(z))$ for $\operatorname{Re}(z)\in\mathbb{Z}$, the absolute value of the integrals along the vertical lines are at most $\frac mk$. These vanish as $k\to\infty$.
Therefore, we get
$$
\mathrm{PV}\int_{-\infty}^\infty\frac{\tan(x)}x\,\mathrm{d}x
=\int_{-\infty+mi}^{\infty+mi}\frac{\tan(z)}z\,\mathrm{d}z
$$
as $m\to\infty$, $\tan(z)\to i$. Therefore,
$$
\mathrm{PV}\int_{-\infty}^\infty\frac{\tan(x)}x\,\mathrm{d}x=\pi
$$
Since $\frac{\tan(x)}x$ is even, we get that
$$
\mathrm{PV}\int_0^\infty\frac{\tan(x)}x\,\mathrm{d}x=\frac\pi2
$$
