Improper Integral via Residues I want to evaulate $\displaystyle{ \int_{-\infty}^{\infty} \frac{e^{kx}}{1+e^x} dx, \ k \in \mathbb{R} }$ via the Residue Theorem over the contour $[x=\pm a, y=0, y=2\pi]$ oriented counterclockwise.


*

*Lets define the complex function, $\displaystyle{ f(z) = \frac{e^{kz}}{1+e^z} }$.

*The function has singularities at $z_n = i\pi(2n+1), \ n \in \mathbb{Z}$ and thus we have a single singularity within the desired domain at $n=0$, $z_0 = i\pi$.
Any tips on how to proceed?
 A: Let 
$$I = \int_{-\infty}^\infty dz\, \frac{e^{kz}}{1+e^z}.$$
Consider the integral $I'$ along the top of the rectangular contour. 
We find
$$\begin{eqnarray*}
I' &=& \int_{\infty + 2\pi i}^{-\infty + 2\pi i}  dz\, \frac{e^{kz}}{1+e^z} \\
&=& \int_{\infty}^{-\infty} d\zeta\, \frac{e^{k(\zeta+2\pi i)}}{1+e^\zeta}
    \hspace{10ex} (\textrm{let } z = \zeta+2\pi i) \\
&=& -e^{2\pi k i} I.
\end{eqnarray*}$$
The argument of the integral along the right side of the rectangle goes like $e^{(k-1)x}$ for $x\gg 0$. 
This must be suppressed, so $\mathrm{Re}\, k < 1$. 
Likewise, to the left the argument goes like $e^{k x}$ for $x\ll 0$, so $\mathrm{Re}\, k > 0$.
For $0<\mathrm{Re}\, k < 1$, the integrals along the sides of the rectangle vanish. 
The integral along the closed rectangular contour is then 
$I + I' = (1-e^{2\pi k i})I = 2\pi i \mathrm{Res}_{z=\pi i},$
and so
$$\begin{eqnarray*}
I &=& \frac{1}{1-e^{2\pi k i}} 
    2\pi i \,\mathrm{Res}_{z=\pi i} \, \frac{e^{kz}}{1+e^z} \\
&=& \frac{1}{1-e^{2\pi k i}} 2\pi i \frac{e^{k\pi i}}{e^{\pi i}}. 
\end{eqnarray*}$$
To calculate the residue we use the fact that if $f(z)$ is analytic and $f(z)/g(z)$ has a simple pole at $z_0$ that
$\mathrm{Res}_{z=z_0}f(z)/g(z) = f(z_0)/g'(z_0).$
Therefore, for $0<\mathrm{Re}\, k < 1$, 
$$\begin{equation*}
\int_{-\infty}^\infty dz\, \frac{e^{kz}}{1+e^z} 
= \frac{\pi}{\sin k\pi}.
\end{equation*}$$
