An integral identity from Ramanujan's notebooks Browsing through Ramanujan's notebooks, I found the following identity, without proof of course (Notebook 1, p. 130):

In other words (took me a while to realize that the lower integration bound is zero, not one):

Let $a \in (0,\pi)$. Then
$$ \int_0^\infty \frac{e^{ax}-e^{-ax}}{e^{\pi x}-e^{-\pi x}} \frac{dx}{1+n^2 x^2} \quad = \quad \sum_{k=1}^\infty (-1)^{k+1} \frac{\sin(ka)}{1+kn} $$

which is pretty amazing if it is true.
Sure enough, the identity checks out numerically for several values of $a$ and $n$. My question, then, is how to prove that the identity is actually correct.
 A: It's a nice identity, but this one is fairly simple compared to some of the other magical results in the notebook. The function $f(a) =  \int_0^\infty \frac{e^{ax}-e^{-ax}}{e^{\pi x}-e^{-\pi x}} \frac{{\rm d}x}{1+n^2 x^2}$ is odd so the Fourier series of $f$ on $[-\pi,\pi]$ is
$$f(a) = \sum_{k=1}^\infty c_k\sin(ka)\implies c_k = \frac{1}{\pi}\int_{-\pi}^\pi f(a)\sin(ka)\,{\rm d}a$$
Evaluating the integral over $a$ using $$\int_{-\pi}^\pi\sin(ka)(e^{ax}-e^{-ax}){\rm d}a = \frac{2k(-1)^{k+1}}{k^2+x^2}(e^{\pi x} - e^{-\pi x})$$
gives us
$$c_k = \frac{2k (-1)^{k+1}}{\pi}\int_0^\infty\frac{{\rm d}x}{(k^2+x^2)(1+n^2x^2)}  \\=  \frac{2k (-1)^{k+1}}{\pi}\frac{1}{n^2k^2-1}\int_0^\infty\left[-\frac{1}{k^2+x^2} + \frac{n^2}{1+n^2x^2}\right]{\rm d}x = \frac{(-1)^{k+1}}{1+kn}$$
where I used $\int_0^\infty\frac{dx}{1+x^2}=\frac{\pi}{2}$ to evaluate the final integrals.
A: Here is another solution using the residue theorem. If we try to integrate the function $\frac{\sinh(az)}{\sinh(\pi z)}\frac{1}{1+n^2z^2}$ directly then we obtain the result
$$\int_0^\infty \frac{\sinh(ax)}{\sinh(\pi x)}\frac{{\rm d}x}{1+n^2x^2} = \frac{\pi}{2n}\frac{\sin(a/n)}{\sin(\pi/n)} -\sum_{k=1}^\infty \frac{(-1)^{k+1}}{k^2n^2-1}\sin(ka)$$
which requires knowledge of the identity $\frac{\pi}{2n}\frac{\sin(a/n)}{\sin(\pi/n)} = \sum_{k=1}^\infty \frac{kn(-1)^{k+1}}{k^2n^2-1}\sin(ka)$ to get the desired identity.
We can get around this by instead considering the slightly modified function
 $$f(z) = \frac{\sinh(a z)}{\sinh(\pi z)}\frac{1+inz}{1 + n^2z^2}$$ Under $z\to-z$ the two term in $f$ are even and odd respectively giving us
$$\int_{-\infty}^\infty f(x)\,{\rm d}x = 2\int_{0}^\infty \frac{\sinh(a x)}{\sinh(\pi x)}\frac{{\rm d}x}{1 + n^2x^2}$$
and both of the integrals above converge as long as $|a|<\pi$. 
We now integrate $f$ from $z=-R$ to $z=R$ along the real axis and then along a semi-circle $C_R$ in the upper half-plane. We take $R=N+\frac{1}{2}$ for some $N\in\mathbb{N}$ to avoid integrating over one of the poles of $f$. For this choice of $R$ we have $|f(z)| \leq \frac{1}{nR-1}$ along $C_R$ so $\lim\limits_{R\to\infty}\int_{C_R}f(z)\,{\rm d}z = 0$.
The poles of $f$ in the upper half plane are located at $z=ik$ for $k\in\mathbb{N}$ with
$$\text{Res}\left[\frac{\sinh(a z)}{\sinh(\pi z)}\frac{1+inz}{1 + n^2z^2}; ik\right] = \frac{1}{\pi i}\frac{(-1)^{k+1}}{1+kn}\sin(ka)$$
and by the residue theorem it follows that
$$\int_{0}^\infty \frac{\sinh(a x)}{\sinh(\pi x)}\frac{{\rm d}x}{1 + n^2x^2} = \sum_{k=1}^\infty \frac{(-1)^{k+1}}{1+kn}\sin(ka)$$
