TITLE: On the integral $\int_0^\infty{\frac{\sin(\lambda x)\mathrm{d}x}{e^{2\pi x}-1}}$
QUESTION [8 upvotes]: In the book Asymptotics and Special Functions by Frank Olver, an integral formula of Legendre reads
$$\int_0^\infty{\frac{\sin(\lambda x)\mathrm{d}x}{e^{2\pi x}-1}}=\frac{1}{2(e^\lambda-1)}-\frac{1}{2\lambda}+\frac{1}{4}\text{ for }\lambda>0$$
Which is then used to prove an already-well-known integral
(by repeatedly differentiating with respect to $\lambda$ and setting $\lambda=0$ in the formula above):
$$\int_0^\infty{\frac{x^{2s-1}\mathrm{d}x}{e^{2\pi x}-1}}=(-1)^{s-1}\frac{B_{2s}}{4s}\text{ for }s>1$$
However, the author introduced, that the first formula can be obtained by straightforwardly integrating the function $\frac{e^{-i\lambda{z}}}{e^{2\pi{z}}-1}$, in which $\lambda>0$, around a rectangle with vertices at $0,K,K+i,i$, and indentations at $0$ and $i$. Then let $K\to\infty$ and the indentations shrink to zero.
I literally don't see how this works, if simply applied residue theorem, and how are the integrals combined. Could someone please show me more details about the process producing the first formula through such integration? Very appreciative.
Ps. I'm not a native English speaker, so I got confused with what he intrinsically meant by the term "indentations", the contour wasn't drawn so there's not an illustration ;)
EDIT.
HUUUGE gratitude to Mark Viola, I finally figured out the method.
The core is to only consider the imaginary part of the integral, which won't diverge.
(Added) Here's a modified version of my first approach following Mark's answer: (Equivalent)
Choose $0<\delta<\frac{1}{2}$
$$I=\int_\delta^K{\frac{e^{-i\lambda{x}}\mathrm{d}x}{e^{2\pi x}-1}}+\int_K^\delta{\frac{e^{-i\lambda(x+i)}\mathrm{d}x}{e^{2\pi(x+i)}-1}}+\int_K^{K+i}{\frac{e^{-i\lambda{x}}\mathrm{d}x}{e^{2\pi{x}}-1}}+e^\lambda\int_0^{\frac{3}{2}\pi}{\frac{e^{-i\lambda\delta{e^{i\theta}}}i\delta{e^{i\theta}}\mathrm{d}\theta}{e^{2\pi\delta{e^{i\theta}}}-1}}+\int_{\frac{\pi}{2}}^{2\pi}{\frac{e^{-i\lambda\delta{e^{i\theta}}}i\delta{e^{i\theta}}\mathrm{d}\theta}{e^{2\pi\delta{e^{i\theta}}}-1}}+\int_{\delta{i}}^{i-\delta{i}}{\frac{e^{-i\lambda x}\mathrm{d}x}{e^{2\pi x}-1}}=I_1+I_2+I_3+I_4+I_5+I_6$$
$I=i(e^\lambda+1)$ by residue theorem.
Taking the limit,
$$\Im(I_1+I_2)=\int_0^\infty{\Im(\frac{e^{-i\lambda{x}}}{e^{2\pi x}-1})\mathrm{d}x}(1-e^\lambda)=(e^\lambda-1)\int_0^\infty{\frac{\sin(\lambda x)\mathrm{d}x}{e^{2\pi x}-1}}$$
$$\left|I_3\right|\le\max_{0\le{x}\le1}{\left|\frac{e^{-i\lambda(ix+K)}}{e^{2\pi(ix+K)}-1}\right|}\to 0$$
$$\Im(I_4)=e^{\lambda}\int_0^{\frac{3}{2}\pi}{\Im(\frac{ie^\lambda}{2\pi}+O(\delta))\mathrm{d}\theta}=\frac{3e^\lambda}{4}$$
$$\Im(I_5)=\int_{\frac{\pi}{2}}^{2\pi}{\Im(\frac{ie^\lambda}{2\pi}+O(\delta))\mathrm{d}\theta}=\frac{3}{4}$$
$$\Im(I_6)=-\int_\delta^{1-\delta}{\Im(i\frac{e^{\lambda x}}{e^{2\pi ix}-1})\mathrm{d}x}=-\int_\delta^{1-\delta}{-\frac{e^{\lambda x}}{2}\mathrm{d}x}=_{\delta\to0}\frac{e^\lambda-1}{2\lambda}$$
Combine the results and we get the result.

REPLY [5 votes]: A nice and straightforward solution was offered by @Mark Viola. I would like to propose another approach, which also uses complex integration, but in a bit another way.
$$I(\lambda)=\int_0^\infty\frac{\sin(\lambda x)}{e^{2\pi x}-1}dx=\int_0^\infty\sin(\lambda x)\Big(\sum_{k=1}^\infty e^{-2\pi kx}\Big)dx=\sum_{k=1}^\infty\frac{\lambda}{(2\pi k)^2+\lambda^2}=S_0$$
Let's also denote $S=\sum_{k=-\infty}^\infty\frac{1}{(2\pi k)^2+\lambda^2}$
It is easy to see that the desired sum $S_0=\frac{\lambda}{2}S-\frac{1}{2\lambda}$.
Now, we can evaluate $S$ in a standart way - integrating the function $f(z)=\frac{\pi\cot(\pi z)}{(2\pi z)^2+\lambda^2}$ in the complex plane along a big circle of radius $R\to\infty$.
On the one hand, the integrand declines as $\sim\frac{1}{z^2}$, therefore $\oint\to0$ at $R\to\infty$.
On the other hand, the integral is the sum of residues inside this circle:
$$\sum Res=0=S+Res_{z=\pm i\lambda/2\pi}\frac{\pi\cot(\pi z)}{(2\pi z)^2+\lambda^2}$$
$$\Rightarrow\,\, S=-\frac{2\pi^2}{(2\pi)^2}\frac{\cot\frac{i\lambda}{2}}{i\lambda}=\frac{1}{2\lambda}\frac{e^\lambda+1}{e^\lambda-1}$$
We get our integral (the sum $S_0$):
$$S_0=\frac{1}{4}\frac{e^\lambda+1}{e^\lambda-1}-\frac{1}{2\lambda}=\frac{1}{4}\frac{e^\lambda-1+2}{e^\lambda-1}-\frac{1}{2\lambda}=\frac{1}{2(e^{\lambda}-1)}-\frac{1}{2\lambda}+\frac{1}{4}$$