$$\begin{aligned}\int_0^{\infty} \frac{\cos ax-\cos bx}{x^2}\,dx &=\int_0^{\infty}\int_a^{b}\frac{\sin tx}{x}\,dt\,dx \\&=\int_a^{b}\int_0^{\infty}\frac{\sin tx}{x}\,dx\,dt\\&=\int_a^b \frac{\pi}{2}\,dt\\&=\frac{(b-a)\pi}{2}\end{aligned} $$
We of course assume that $a$ is real here. For a complex analysis, consider the integral
$$\oint_C dz \frac{\sin{a z}}{\sinh{z}}$$
where $C$ is the following contour:
Because there are no poles in the interior of the contour, this integral is zero by Cauchy's theorem. On the other hand, the contour integral is equal to
$$\int_{\epsilon}^R dx \frac{\sin{a x}}{\sinh{x}} + i \int_0^{\pi} dy \frac{\sin{a(R+i y)}}{\sinh{(R+i y)}} + \\ \int_R^{\epsilon} dx \frac{\sin{a(x+i \pi)}}{\sinh{(x+i \pi)}} + i \epsilon \int_0^{-\pi/2} d\phi \, e^{i \phi} \frac{\sin{a(i \pi + \epsilon e^{i \phi})}}{\sinh{(i \pi + \epsilon e^{i \phi})}} + \\i \int_{\pi-\epsilon}^{\epsilon} dy \frac{\sin{i a y}}{\sinh{i y}} + i \epsilon \int_{\pi/2}^0 d\phi \, e^{i \phi} \frac{\sin{a \epsilon e^{i \phi}}}{\sinh{\epsilon e^{i \phi}}} $$
We take the limits as $R \to \infty$ and $\epsilon \to 0$; in these limits, the second and sixth integrals vanish. We also need only consider the real part of the above expression, as the integral of interest is real; this then eliminates the fifth integral from consideration altogether, and we need only examine the real part of the third. By expanding the trig functions using, e.g., addition theorems, we get the following relation:
$$\left (1+\cosh{\pi a}\right) \int_0^{\infty} dx \frac{\sin{a x}}{\sinh{x}} - \frac{\pi}{2} \sinh{\pi a} = 0$$
or
$$\int_0^{\infty} dx \frac{\sin{a x}}{\sinh{x}} = \frac{\pi}{2} \tanh{\frac{\pi a}{2}}$$
Of course, this is not the integral desired. Nevertheless, assuming everything is absolutely convergent (which it is here), we may differentiate both sides with respect to $a$ and reverse order of derivative and integral to get
$$\int_0^{\infty} dx \frac{x \cos{a x}}{\sinh{x}} = \frac{\pi^2}{4} \text{sech}^2{\frac{\pi a}{2}}$$
as was to be shown.
Best Answer
Hint: For the calculus approach, note that $\tan(\pi/2-x)=\frac{1}{\tan x}$. So split the interval into $0$ to $\pi/4$, and $\pi/4$ to $\pi/2$. For the second half, make the change of variable $x=\pi/2-u$.
When we make the change of variable, we have to wade through a morass of minus signs. One comes from $dx=-du$; another comes from the fact that the integration bounds will be in the "wrong" order; and a third comes from $\ln(1/t)=-\ln(t)$.