Integrate $\int_{-\infty}^\infty \frac{x}{\sinh x}~dx$ From a Problem Set on residues:
Evaluate $$\int_0^\infty \frac{\log x}{(x-1) \sqrt{x}}~dx.$$
After the substitution $x = e^u$ and easy computations, the integral becomes $$\int_{-\infty}^\infty \frac{x}{\sinh x}~dx.$$
 A: This was trickier than I thought, 
but a method using complex analysis would be as follows:
As integration contour we choose a rectangle with vertices $\pm R,\pm R+\pi i $
Now let's define $I =\int_C\frac{z}{\sinh(z)}$ . We can write (the limit $R\rightarrow\infty$ is implicit) 
$$
I=\underbrace{I_1}_{\text{Real Line}}+\underbrace{I_2}_{\text{Real Line}+i\pi}+\underbrace{I_3+I_4}_{\text{Vertical pieces}}+\underbrace{I_5}_{\text{small circle avoiding }z=i\pi}=0
$$
by Cauchy's theorem.
It's now an easy task to show that (using $\sinh(x+i \pi)=-\sinh(x)$)
a) $I_1+I_2=2I_1-i\pi P\int_{-\infty}^{\infty}\frac{1}{\sinh(x)}$, where $P$ denotes Cauchy's principal part
b) The vertical pieces vanish
So our problem boils down to
$$
I_1=\frac{i\pi}{2} \underbrace{P\int_{-\infty}^{\infty}\frac{1}{\sinh(x)}dx}_{(*)}+\underbrace{\frac{i\pi}{2}\lim_{r\rightarrow0}\int_0^{\pi}\frac{r e^{i\phi}}{i\sinh(r e^{i\phi})}d\phi}_{I_5/2}
$$
Now $(*)=0$ essentially because $\frac{1}{\sinh(x)}$ is odd and we integrate over an even intervall.
Furthermore , using the fact that $\sinh(x)\approx x$ for small $x$ 
$$
I_1=\underbrace{\frac{\pi}{2}\int_0^{\pi}d\phi}_{I_5/2}=\frac{\pi^2}{2}
$$
And we are done
Appendix
I can't resist i have to do something really crazy (the purists may forgive me):
!Warning this part is by no means rigorous!
Let's assume that we can choose a large semicircle in the upper half plane as an integration contour (which is a quite delicate assumption because on the imaginary axis, and only there our integral is not convergent) then our integral is given by 
$$
I_1= 2\pi i\sum_{n=0}^{\infty} \text{Res}[I(z),z=i n \pi]
$$
and now he appears, one of my dearest friends from  Quantum Field Theory,
the heavily divergent sum of alternating natural numbers
$$
I_1=-2 \pi^2 \sum_{n=0}^{\infty}(-1)^n n
$$
Now what to do? It turns out that by an appropriate regularization procedure (Borel summation, $\zeta$-methods, ..., just to give you a few buzzwords) we can assign the value -1/4
to this sum and end up with
$$
I_1=\frac{\pi^2}{2}
$$
Which is surprisingly the correct result. 
I would be really interested if someone could explain  the correspondance between a divergent piece of width 0 in the integration contour and the  divergent sum of residues, which after a proper regularization, gives us nevertheless a correct and finite result. Or is this just coincidence (i have the feeling that it is NOT)
A: We have
$$\int_1^{\infty} \dfrac{\log(x)}{(x-1)\sqrt{x}}dx = \int_1^0 \dfrac{\log(1/x)}{(1/x-1)1/\sqrt{x}} \left(-\dfrac{dx}{x^2}\right) = \int_0^1 \dfrac{-\log(x)}{(1-x)\sqrt{x}}dx = \int_0^1 \dfrac{\log(x)}{(x-1)\sqrt{x}}dx$$
Hence, the integral is
\begin{align}
I & = -2\int_0^1 \dfrac{\log(x)dx}{(1-x)\sqrt{x}} = -2 \sum_{k=0}^{\infty}\int_0^1 x^{k-1/2}\log(x)dx = 2\sum_{k=0}^{\infty} \dfrac1{(k+1/2)^2} =8 \sum_{k=0}^{\infty} \dfrac1{(2k+1)^2} = \pi^2
\end{align}

A very similar method to evaluate $$I=\int_{-\infty}^{\infty} \dfrac{x}{\sinh(x)}dx = 2\int_0^{\infty} \dfrac{x}{\sinh(x)}dx$$
We have
\begin{align}
I & = 2 \cdot \int_0^{\infty} \dfrac{2x}{e^x-e^{-x}}dx = \int_0^{\infty} \dfrac{4xe^{-x}}{1-e^{-2x}}dx = 4 \sum_{k=0}^{\infty} \int_0^{\infty}xe^{-(2k+1)x}dx = 4 \sum_{k=0}^{\infty} \dfrac1{(2k+1)^2} = \dfrac{\pi^2}2
\end{align}
A: Here is a proof avoiding an indented contour and issues that raises.
Begin by noting that since the integrand is even it suffices to consider the (Cauchy) principal value integral.
Write $a := \pi/2$ and define $f$ by $f(z) := z/\sinh z$ wherever $\sinh z \neq 0.$  Let $\mathcal{S}$ denote the horizontal strip on which $0 \leq \text{im } z \leq a.$
Note (check!) the following

*

*$f$ is analytic on $\mathcal{S}.$

*$f(z) \to 0$ as  $z \to \infty$ in $\mathcal{S}.$

*$\sinh\, (z + ia) = i \cosh z$ so that $f(x + ia) = -ix/\cosh x + a/\cosh x$  for each $x \in \mathbb{R}.$

*There exist $PV\int_{-\infty}^{+\infty} \overbrace{x/\cosh x}^{\text{odd function}} \,dx = 0$ and $\int_{-\infty}^{+\infty} dx/\cosh x = \pi$ so that there exists $I := PV\int_{-\infty}^{+\infty} f(x + ia) \,dx = -i0 + a\pi = a\pi.$
It follows by usual analysis that (partly by virtue of item 2.) there exists
$$J := PV\int_{-\infty}^{+\infty} [f(x) - f(x + ia)] \,dx =  0.$$
Thus there exists $PV\int_{-\infty}^{+\infty} f(x) \, dx = J+I = 0 + a\pi = \pi^{2}/2.$
(NOTE added 15/10/2022 at 00:10 This is a simplified, edited version of my original posting wherein I took $a := 3\pi/2$ being, in retrospect, too mindful there of the singularity of the integrand at $i\pi$ as in the original posting.  Here I modify, mutatis mutandis, to $a := \pi/2$ which makes things marginally simpler.  My apologies to any earlier readers who spot this modification.)
A: I thought it might be instructive to present an approach that does not rely on the transformation, but rather directly evaluated the integral of interest.  To that end, we proceed.

Let $I$ be the integral defined as
$$\begin{align}
I&=\int_0^\infty \frac{\log(x)}{(x-1)\sqrt{x}}\,dx\\\\
&=4\int_0^\infty \frac{\log(x)}{x^2-1}\,dx
\end{align}$$
We shall analyze the contour integral $J$ defined as
$$J=4\oint_{C_{R,\varepsilon}} \frac{\log^2(z)}{z^2-1}\,dz$$
where $C_{R,\varepsilon}$ is the classical keyhole contour with radius $R>1$, with branch cut along the positive real axis, and a semi-circular deformation with radius $\varepsilon>0$ around $z=1$.  Then, we have as $R\to \infty$ and $\varepsilon\to0$,
$$\begin{align}
\lim_{R\to\infty\\\varepsilon\to0}J&=\text{PV}\left(4\int_0^\infty \frac{\log^2(x)-(\log(x)+i2\pi)^2}{x^2-1}\,dx\right)\\\\
&=-i16\pi \int_0^\infty \frac{\log(x)}{x^2-1}\,dx+i8\pi^3+16\pi^2\underbrace{\text{PV}\int_0^R \frac{1}{x^2-1}\,dx}_{=0}\tag1\\\\
&=2\pi i \text{Res}\left(\frac{4\log^2(z)}{z^2-1}, z=-1\right)\\\\
&= i4\pi^3  \tag2
\end{align}$$
Putting $(1)$ and $(2)$ together yields
$$I=\pi^2$$
as expected!
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{{\displaystyle #1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\on}[1]{\operatorname{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\sr}[2]{\,\,\,\stackrel{{#1}}{{#2}}\,\,\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
& \color{#44f}{\int_{0}^{\infty}{\ln\pars{x} \over \pars{x - 1} \root{x}}\,\dd x} =
\left.\partiald{}{\nu}{\rm P.V.}\int_{0}^{\infty}
{x^{\nu - 1/2} \over x - 1}\,\dd x
\right\vert_{\nu\ =\ 0}
\end{align}

\begin{align}
& \mbox{Lets consider}\ {\cal F}\pars{\nu} \equiv \oint_{\cal C}{z^{\nu - 1/2} \over z + 1}\,{\dd z \over 2\pi\ic}\
\\ &\mbox{where}\ {\cal C}\ \mbox{is a}\ key\mbox{-}hole\ contour\ \mbox{which "takes care" of the}\ z^{\nu - 1/2}\,\,\, principal\ branch\mbox{-}cut.
\\[5mm] & \mbox{Namely,}\ {\cal F}\pars{\nu} = 0\ \mbox{because the above mentioned contour doesn't enclose any pole.}
\\[5mm] & \mbox{Moreover,}\ 0 = {\cal F}\pars{\nu} =
\int_{-\infty}^{0}{\pars{-x}^{\nu - 1/2}
\,\expo{\ic\pi\pars{\nu - 1/2}} \over x + 1 + \ic 0^{+}}
\,{\dd x \over 2\pi\ic}
\\[2mm] & + \int_{0}^{-\infty}{\pars{-x}^{\nu - 1/2}
\,\expo{-\ic\pi\pars{\nu - 1/2}} \over x + 1 - \ic 0^{+}}
\,{\dd x \over 2\pi\ic}
\\[5mm] = & \ \ic\expo{\ic\pi\nu}\int_{0}^{\infty}
{x^{\nu - 1/2} \over x - 1 - \ic 0^{+}}\,{\dd x \over 2\pi\ic}
+ \ic\expo{-\ic\pi\nu}
\int_{0}^{\infty}{x^{\nu - 1/2} \over x - 1 + \ic 0^{+}}
\,{\dd x \over 2\pi\ic}
\\[5mm] = & \ {2\ic\cos\pars{\pi\nu} \over 2\pi\ic}\
{\rm P.V.}\int_{0}^{\infty}{x^{\nu - 1/2}\,\, \over x - 1}\,\dd x +
\bracks{{\ic\expo{\ic\pi\nu} \over 2\pi\ic}\times \pars{\ic\pi} +
{\ic\expo{-\ic\pi\nu} \over 2\pi\ic}\times \pars{-\ic\pi}}
\\[5mm] = & \
{\cos\pars{\pi\nu} \over \pi}\
{\rm P.V.}\int_{0}^{\infty}{x^{\nu - 1/2}\,\, \over x - 1}\,\dd x - \sin\pars{\pi\nu}
\\[5mm] & \implies
{\rm P.V.}\int_{0}^{\infty}{x^{\nu - 1/2}\,\, \over x - 1}
\,\dd x = \pi\tan\pars{\pi\nu}
\\ & \implies \bbx{\color{#44f}{\left.\partiald{\bracks{\pi\tan\pars{\pi\nu}}}{\nu}\right\vert_{\nu\ =\ 0} = {\large\pi^{2}}}} \\ &
\end{align}
A: Alternatively \begin{align}
\int_{-\infty}^\infty \frac{x}{\sinh x}~dx
=& \int_{-\infty}^\infty \int_0^1 \frac{2y\  e^x}{1+(e^{2x}-1)y^2}dy\ dx\\
=& \int_0^1 \frac\pi{\sqrt{1-y^2}}dy = \frac{\pi^2}2
\end{align}
