Indefinite integral with residue theorem I tried to solve the following integral using residue theorem. $$\int_0^\infty\frac{x}{\sinh x} ~\mathrm dx=\int_{-\infty}^\infty\frac{x}{e^x-e^{-x}}~\mathrm dx$$
$e^x-e^{-x}=0$ when $x=n\pi i, n\subset\mathbb Z$
So the residues are (when n is a positive integer)
$$\frac{(-1)^n n\pi i}{2}$$
Thus the value of definite integral will be
$$2\pi i\sum_{n=1}^\infty \frac{(-1)^n n\pi i}{2}=\pi^2(1-2+3-4+5-\ldots)$$
But the series diverges obviously. Here I used the technique that
$$A=1-1+1-1+1-\ldots$$
$$A=1-(1-1+1-1+1-\ldots)$$
$$A=1-A, A=\frac{1}{2}$$
$$B=1-2+3-4+5-6+7-\ldots$$
$$B=(1-1+1-1+1-\ldots)-(1-2+3-4+5-\ldots)$$
$$B=A-B, B=\frac{1}{4}$$
Thus the integral value is $\frac{\pi^2}{4}$.
Although the value itself is correct, I think this method is still controversial. How can this method become justified? Or is there a problem in my residue theorem solution?
 A: Through the substitutions $x=\log t$, then $t=\frac{1}{v}$, we have:
$$ I=\int_{0}^{+\infty}\frac{x\,dx}{\sinh{x}}=\int_{1}^{+\infty}\frac{2\log t}{t^2-1}\,dt = 2\int_{0}^{1}\frac{-\log v}{1-v^2}\,dv\tag{1}$$
and now a simple Taylor series expansion is enough, since:
$$ \int_{0}^{1}(-\log v)v^{2k}\,dv = \frac{1}{(2k+1)^2} \tag{2}$$
leads to:
$$ I = 2\sum_{k\geq 0}\frac{1}{(2k+1)^2} = \frac{3}{2}\,\zeta(2)=\color{red}{\frac{\pi^2}{4}}.\tag{3}$$
You may also use the Laplace transform:
$$ \mathcal{L}\left(\frac{1}{\sinh x}\right)= -H_{\frac{s-1}{2}},\qquad \mathcal{L}^{-1}(x)=\delta'(s)\tag{4}$$
give that your integral is directly related with a value of $\psi'$, namely a dilogarithm.
A: We can use complex analysis that begins by enforcing the substitutions that were used in the solution posted by @jackd'aurizio .  There, we have
$$\int_0^\infty \frac{x}{\sinh(x)}\,dx=\int_0^\infty \frac{\log(x)}{x^2-1}\,dx \tag 1$$
Now, we analyze the contour integral 
$$\begin{align}
I&=\oint_C \frac{\log^2(z)}{z^2-1}\,dz\\\\
&=\int_{0^+}^R \frac{\log^2(x)}{x^2-1}\,dx-\text{PV}\left(\int_{0^+}^R\frac{\left(\log(x)+i2\pi\right)^2}{x^2-1}\,dx\right)\\\\
&-\int_\pi^{2\pi} \frac{(\log(1+\nu e^{i\phi})+i2\pi)^2}{(2+\nu e^{i\phi})(\nu e^{i\phi})}i\nu e^{i\phi}\,d\phi\\\\
&+\int_{0^+}^{2\pi^-}\frac{\log^2(Re^{i\phi})}{R^2e^{i2\phi}-1}iRe^{i\phi}\,d\phi-\int_{0^+}^{2\pi^-}\frac{\log^2(\epsilon e^{i\phi})}{\epsilon ^2e^{i2\phi}-1}i\epsilon e^{i\phi}\,d\phi \tag 2
\end{align}$$
where $C$ is the classical "keyhole" contour with the "keyhole" taken along the real axis.  For $R>1$, we have from the residue theorem
$$\begin{align}
I&=2\pi i \,\text{Res}\left(\frac{\log^2(z)}{z^2-1}, z=-1\right)\\\\
&=2\pi i \left(\frac{\log^2(e^{i\pi})}{-2}\right)\\\\
&=i\pi^3 \tag 3
\end{align}$$
Now, as $R\to \infty$ and $\epsilon \to 0$, the last two integrals on the right-hand side of $(2)$ vanish.  Furthermore, the principal value,  $\text{PV}\left(\int_0^\infty \frac{1}{x^2-1}\,dx\right)=0$.  And as $\nu \to 0$, the third integral on the right-hand side of $(2)$ approaches $i2\pi^3$.
Hence, we find from the limiting value of $(2)$ and $(3)$
$$-i4\pi \int_0^\infty \frac{\log(x)}{x^2-1}\,dx+i2\pi^3=i\pi^3 \tag 4$$
Finally, from $(4)$ we obtain
$$\int_0^\infty \frac{x}{\sinh(x)}\,dx=\frac{\pi^2}{4}$$
A: $\newcommand{\angles}[1]{\left\langle\,{#1}\,\right\rangle}
 \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{\half}{{1 \over 2}}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\iff}{\Leftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[2]{\,\mathrm{Li}_{#1}\left(\,{#2}\,\right)}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$


*

*
This is another posibility to evaluate the integral along a complex plane contour:
\begin{align}
\color{#f00}{\int_{0}^{\infty}{x \over \sinh\pars{x}}\,\dd x} & =
\half\int_{-\infty}^{\infty}{x \over \sinh\pars{x}}\,\dd x =
\int_{-\infty}^{\infty}{x\expo{x} \over \expo{2x} - 1}\,\dd x\
\stackrel{\expo{x}\ \mapsto\ x}{=}\
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd x
\end{align}
The integral is evaluated along a $\mathit{\mbox{key-hole}}$ contour which takes care of the $\ds{\ln\pars{z}}$ $\mathit{\mbox{branch-cut}}$ along the 'positive real axis'. Namely,
$$
\ln\pars{z} = \ln\pars{\verts{z}} + \,\mathrm{arg}\pars{z}\ic\,,\ 0 < \,\mathrm{arg}\pars{z} < 2\pi\,,\ z \not= 0
$$
Along the above mentioned contour, we evaluate the integral
$$
\int{\ln^{2}\pars{z} \over z^{2} - 1}\,\dd z
$$
which has one  pole $\ds{\pars{= -1}}$  'inside' the contour. The
forthcoming $\ds{\ \ic\,0^{\pm}\ }$ 'factors' will take care of the singularity at $\ds{x = +1}$ along the $\ds{\ln}$ branch-cut.

$$
2\pi\ic\,{\braces{\ln\pars{\verts{-1}} + \pi\ic}^{\, 2} \over -1 - 1} =
\int_{0}^{\infty}
{\bracks{\ln\pars{t} + 0\,\ic}^{\, 2} \over
\pars{t - 1 + \ic 0^{+}}\pars{t + 1}}\,\dd t
+
\int_{\infty}^{0}
{\bracks{\ln\pars{t} + 2\pi\ic}^{\, 2} \over
\pars{t - 1 - \ic 0^{-}}\pars{t + 1}}\,\dd t
$$
\begin{align}
\pi^{3}\,\ic & =
\mathrm{P.V.}\int_{0}^{\infty}{\ln^{2}\pars{t} - \ln^{2}\pars{t} - 4\pi\ic\,\ln\pars{t} - 4\pi^{2} \over t^{2} - 1}\,\dd t
\\[3mm] &\ +\ \overbrace{\int_{0}^{\infty}{\ln^{2}\pars{t} \over t + 1}\,
\bracks{-\pi\ic\,\delta\pars{t - 1}}\,\dd t}^{\ds{=\ 0}}
\\[3mm] & -
\int_{0}^{\infty}{\bracks{\ln\pars{t} + 2\pi\ic}^{\, 2}\over t + 1}\,
\bracks{\pi\ic\,\delta\pars{t - 1}},\dd t
\\[1cm] & =
-4\pi\ic\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t -
4\pi^{2}\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1} + 2\pi^{3}\ic
\\[1cm] \imp
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t & =
{\pi^{3}\ic - 2\pi^{3}\ic \over -4\pi\ic} -
{4\pi^{2} \over -4\pi\ic}\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1}
\\[3mm] & = \color{#f00}{\pi^{2} \over 4} -
\pi\ic\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1}\tag{1}
\end{align}

Note que
\begin{align}
\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1} & =
\lim_{\epsilon \to 0^{+}}\pars{\int_{0}^{1 - \epsilon}{\dd t \over t^{2} - 1} +
\int_{1 + \epsilon}^{\infty}{\dd t \over t^{2} - 1}}
\\[3mm] & =
\lim_{\epsilon \to 0^{+}}\pars{\int_{0}^{1 - \epsilon}{\dd t \over t^{2} - 1} +
\int_{1/\pars{1 + \epsilon}}^{0}{\dd t \over t^{2} - 1}} =
\lim_{\epsilon \to 0^{+}}
\int_{1 - \epsilon}^{1/\pars{1 + \epsilon}}{\dd t \over 1 - t^{2}} = 0
\end{align}
\begin{align}
&\mbox{because}
\\[3mm] &\ 
0 < \verts{\int_{1 - \epsilon}^{1/\pars{1 + \epsilon}}{\dd t \over 1 -t^{2}}}
<\verts{\pars{{1 \over 1 + \epsilon} - 1 + \epsilon}\,{1 \over
1 - 1/\pars{1 + \epsilon}^{2}}} =
\verts{\epsilon\pars{1 + \epsilon} \over 2 + \epsilon} \to
\stackrel{\epsilon\ \to\ 0}{0}
\end{align}

With this result and expression $\pars{1}$:
$$
\color{#f00}{\int_{0}^{\infty}{x \over \sinh\pars{x}}\,\dd x} =
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t =
\color{#f00}{\pi^{2} \over 4}
$$


A: A simpler way to use complex analysis is to consider the integral
$$\oint_C dz \frac{z}{\sinh{z}} $$
where $C$ is the rectangle with vertices $-R$, $R$, $R+i \pi$, $-R+i \pi$, with a semicircular detour of radius $\epsilon$ at $z=i \pi$ into the rectangle.  Thus, the contour integral is equal to
$$\int_{-R}^R dx \frac{x}{\sinh{x}} + i \int_0^{\pi} dy \frac{R+i y}{\sinh{(R+i y)}}-PV \int_{-R}^R dx \frac{x+i \pi}{\sinh{(x+i \pi)}} \\ + i \epsilon \int_{2 \pi}^{\pi} d\phi \, e^{i \phi} \frac{i \pi + \epsilon e^{i \phi}}{\sinh{(i \pi + \epsilon e^{i \phi})}} -i \int_0^{\pi} dy \frac{-R+i y}{\sinh{(-R+i y)}} $$
As $R \to \infty$, the second and fifth integrals vanish.  Further, the fourth integral becomes as $\epsilon \to 0$, $-\pi^2$.  Also, the 2nd piece of the third integral vanishes due to symmetry.  Left with the first piece, we may drop the principal value indicator and combine with the first integral to get, by Cauchy's theorem,
$$2 \int_{-\infty}^{\infty} dx \frac{x}{\sinh{x}} - \pi^2 = 0$$
The rest follows.
