Prove $\int_0^\infty \frac{\ln \tan^2 (ax)}{1+x^2}\,dx = \pi\ln \tanh(a)$

Here is another solution:

We remark that

$$ \log\tan^{2}\theta = -4 \sum_{n \ \mathrm{odd}}^{\infty}\frac{1}{n}\cos 2n\theta \tag{1} $$

and

$$ \sum_{n \ \mathrm{odd}}^{\infty} \frac{1}{n} x^{n} = \frac{1}{2}\log\left(\frac{1+x}{1-x}\right). \tag{2} $$

Both are easily proved by using Euler's formula $e^{i\theta} = \cos\theta + i\sin\theta$ and the Taylor series of the logarithm. Also we note that

$$ \int_{0}^{\infty} \frac{t \sin t}{a^2 + t^2} \, dt = \frac{\pi}{2} e^{-|a|}. \tag{3}$$

Then

\begin{align*} \int_{0}^{\infty} \frac{\log\tan^2(ax)}{1+x^2} \, dx &= \int_{0}^{\infty} \log\tan^2(ax) \left( \int_{0}^{\infty} \sin t \, e^{-xt} \, dt \right) \, dx \\ &= \int_{0}^{\infty} \sin t \int_{0}^{\infty} e^{-tx} \log\tan^2(ax) \, dxdt \\ &= -4 \int_{0}^{\infty} \sin t \int_{0}^{\infty} \sum_{n \ \mathrm{odd}}^{\infty}\frac{1}{n} e^{-tx} \cos (2nax) \, dxdt \\ &= -4 \int_{0}^{\infty} \sin t \sum_{n \ \mathrm{odd}}^{\infty}\frac{1}{n} \frac{t}{4a^{2}n^{2} + t^{2}} \, dt \\ &= -4 \sum_{n \ \mathrm{odd}}^{\infty} \frac{1}{n} \int_{0}^{\infty} \frac{t \sin t}{4a^{2}n^{2} + t^{2}} \, dt \\ &= -2\pi \sum_{n \ \mathrm{odd}}^{\infty} \frac{1}{n} e^{-2an} = \pi \log \left( \frac{1-e^{-2a}}{1+e^{-2a}} \right) \\ &= \pi \log (\tanh a). \end{align*}


An idea with complex contour. Let us choose the path

$$C_R:=[-R,R]\cup\gamma_R:=\{z\in\Bbb C\;;\;z=Re^{it}\,\,,\,0\leq t\leq \pi\}\,\,,\,0<<R\in\Bbb R$$

Take the function

$$f(z):=\frac{\operatorname{Log}(\tan^2az)}{1+z^2}=2\frac{\operatorname{Log}(\tan az)}{1+z^2}$$

Inside the domain enclosed by $\,C_R\,$ above, the function has the pole $\,z=i\,$ (note that at the poles of $\,\tan az\,$ the logarithmic function equals $\,0+\arg(\text{pole})\,$ , and since we're going to choose the branch along the cut from zero to $\,-i\infty \,$ , i.e. the negative y-axis all these give us zero, so we're left only with the zero of the denominator in the positive half complex plane:

$$Res_{z=i}(f)=2\lim_{z\to i}(z-i)\frac{\operatorname{Log}(\tan az)}{z^2+1}=2\frac{\operatorname{Log}(\tan ai)}{2i}=-i\log(\tanh a)$$

We also have that

$$\left|\int_{\gamma_R}2\frac{\operatorname{Log}(\tan az)}{1+z^2}dz\right|\leq2\frac{|\log|\tan az||}{1-R^2}R\pi\xrightarrow[R\to\infty]{}0$$

as using the form (with $\,z=x+yi\,\,,\,x,y\in\Bbb R\,\,,\,y>0\,$)

$$\tan az=\frac{e^{2aiz}-1}{e^{2aiz}+1}\Longrightarrow |\log|\tan az||\leq \left|\log\frac{1+e^{2iy}}{1-e^{2iy}}\right|\xrightarrow [y\to\infty]{}\log 1=0$$

Thus, we finally get by Cauchy's Theorem

$$2\pi i(-i\log(\tanh a))=2\pi\log(\tanh a)=\oint_{C_R} f(z)\,dz=$$

$$=\int\limits_{-R}^R\frac{\log(\tan^2 ax)}{1+x^2}dx+\int_{\gamma_R}f(z)\,dz\xrightarrow[R\to\infty]{}\int\limits_{-\infty}^\infty\frac{\log(\tan^2 x)}{1+x^2}dx$$

Now just divide by two the integral of the even function above and we're done.


Denote the evaluated integral as $I$, then $I$ may be rewritten as $$I=\int_0^\infty \frac{\ln \sin^2 ax}{1+x^2}\,dx-\int_0^\infty \frac{\ln \cos^2 ax}{1+x^2}\,dx$$ Using Fourier series representations of $\ln \sin^2 \theta$ and $\ln \cos^2 \theta$, $$\ln \sin^2 \theta=-2\ln2-2\sum_{k=1}^\infty \frac{\cos2k\theta}{k}$$ and $$\ln \cos^2 \theta=-2\ln2+2\sum_{k=1}^\infty (-1)^{k+1}\frac{\cos2k\theta}{k}$$ also note that $$\int_0^\infty\frac{\cos bx}{1+x^2}\,dx=\frac{\pi e^{-b}}{2}$$ then $$\begin{align}I&=-2\sum_{k=1}^\infty \frac{1}{k}\int_0^\infty\frac{\cos2kax}{1+x^2}\,dx-2\sum_{k=1}^\infty \frac{(-1)^{k+1}}{k}\int_0^\infty\frac{\cos2kax}{1+x^2}\,dx\\&=-\pi\sum_{k=1}^\infty \frac{e^{-2ak}}{k}-\pi\sum_{k=1}^\infty (-1)^{k+1}\frac{e^{-2ak}}{k}\\&=\pi\ln\left(1-e^{-2a}\right)-\pi\ln\left(1+e^{-2a}\right)\\&=\pi\ln\left(\frac{1-e^{-2a}}{1+e^{-2a}}\right)\\&=\pi\ln\left(\tanh a\right)\end{align}$$