How to compute this definite improper integral using the Residue Theorem?? I have been trying to compute this integral:
$$
\int_0^\infty \frac{\log^{2}\left({\left\vert{\tan\left({x}\right)}\right\vert}\right)}{1 + x^{2}}\,\mathrm{d}x
$$
using the Residue Theorem but have not been successful.
I tried to use the classical upper semi-circular contour, but realized that it would not work because $\log^{2}\left({\left\vert{\tan\left({x}\right)}\right\vert}\right)$ has singularities on the contour and is therefore not holomorphic on/in that contour.
Does anybody have any ideas of what kind of contour I should use? 
I don't think we have to worry about the branches of the logarithm function because it's argument will always be real. Is that correct?
 A: Let us consider a general family of integrals
$$ I(a) = \int_{0}^{\infty} \frac{\log^2 \left| \tan(x/2) \right|}{a^2 + x^2} \, dx. $$
Notice that OP's integral equals $2I(2)$ by a simple substitution. Now we make the following very simple observation:
$$ \forall x \in \mathbb{R} \ : \quad
\log^2 \left| \tan(x/2) \right|
= \operatorname{Re}\left[ \log(\tan (x/2)) \log(\tan(-x/2)) \right]. $$
By this observation and symmetry, we find that
\begin{align*}
I(a)
&= \frac{1}{2} \operatorname{Re}\left[  \int_{-\infty}^{\infty} \frac{1}{a^2 + x^2} \log\left( i \frac{1 - e^{ix}}{1 + e^{ix}} \right) \log\left( -i \frac{1 - e^{ix}}{1 + e^{ix}} \right) \, dx \right] \\
&= \operatorname{Re}\left[ \pi i \mathop{\underset{z=ia}{\mathrm{Res}}} \frac{1}{a^2 + z^2} \log\left( i \frac{1 - e^{iz}}{1 + e^{iz}} \right) \log\left( -i \frac{1 - e^{iz}}{1 + e^{iz}} \right) \right] \\
&= \operatorname{Re}\left[ \frac{\pi}{2a}\log\left( i \frac{1 - e^{-a}}{1 + e^{-a}} \right) \log\left( -i \frac{1 - e^{-a}}{1 + e^{-a}} \right) \right] \\
&= \frac{\pi}{2a} \left( \frac{\pi^2}{4} + \log^2 \left( \tanh(a/2) \right) \right).
\end{align*}
In the second line, we utilized the fact that the integrand extends to a holomorphic function on the upper half-plane $\mathbb{H}$ which vanishes sufficiently fast near $\infty \in \partial \mathbb{H}$ along appropriately chosen contours.
