A limit and a delta function in an integral. Let's say I want to calculate the integral
\begin{equation}
\lim_{\gamma\to0}\frac{1}{2\pi i}\int^\infty_{-\infty}dx\left(\frac{1}{x-a+i\gamma}-\frac{1}{x-a-i\gamma}\right)\frac{-1}{e^x+1},
\end{equation}
($a\in\mathbb{R}$) and somebody says to me that the relation
\begin{equation}
\frac{1}{\pi}\lim_{\gamma\to0}\frac{\gamma}{x^2+\gamma^2}=\delta(x)
\end{equation}
might be useful. Rewriting the fractions in the integrand I write the integral as
\begin{equation}
\lim_{\gamma\to0}\frac{1}{\pi}\int^\infty_{-\infty}dx\,\frac{\gamma}{(x-a)^2+\gamma^2}\frac{1}{e^x+1},
\end{equation}
and being willing to use the given relation I might want to continue to write
\begin{equation}
\int^\infty_{-\infty}\frac{1}{\pi}\lim_{\gamma\to0}\frac{\gamma}{x^2+\gamma^2}\frac{1}{e^x+1}=\frac{1}{e^a+1},
\end{equation}
and be happy because this is the answer we are supposed to find. However, I'm not sure as to why this works like this (if it does). I know that interchanging limits and integrals can be a delicate business, and if you can pull the limit inside the integral here, then what is wrong with writing
\begin{equation}
\lim_{\gamma\to0}\left(\frac{1}{x-a+i\gamma}-\frac{1}{x-a-i\gamma}\right)=\frac{1}{x-a}-\frac{1}{x-a}=0?
\end{equation}
I'd be happy with any help!
 A: There are a variety of ways to make the details precise, and the theory has a number of awkward points, but here is a sketch of how things typically go. See wikipedia for more details.
There is some algebra $\mathcal{T}$ of "test functions" which includes $-\frac{1}{e^x + 1}$.
There is some space $\mathcal{F}$ of functions with the proprerty that, for every $f \in \mathcal{F}$, we can define a linear functional
$$ I_f : \mathcal{T} \to \mathbb{C} : t \mapsto \int_{-\infty}^{\infty} f(x) t(x) \, \mathrm{d} x $$
and whenever $f \neq g$, there exists a test function $t$ such that $I_f(t) \neq I_g(t)$.
Finally there is some dual space $\mathcal{T}^*$ consisting of all linear functionals on $\mathcal{T}$ of an appropriate type. 
What's happening is that if we have a family $f_\gamma$ of functions in $\mathcal{F}$, we can compute
$$ \lim_{\gamma \to 0} \int_{-\infty}^{\infty} f_\gamma(x) t(x) \, \mathrm{d}x 
= \lim_{\gamma \to 0} I_{f_\gamma}(t) $$
Now, for every $g \in \mathcal{F}$, we have $I_g \in \mathcal{T}^*$. The type of dual space we use is selected so that evaluation is continuous; that is, we can compute the above by first computing the limit in $\mathcal{T}^*$:
$$ \lim_{\gamma \to 0} I_{f_\gamma}(t)  = \left( \lim_{\gamma \to 0} I_{f_\gamma} \right)(t)$$
The thing you were told is that if we set
$$ f_\gamma(x) = \frac{\gamma}{x^2 + \gamma^2} $$
then
$$ \frac{1}{\pi} \lim_{\gamma \to 0} I_{f_\gamma} = \delta $$
and so putting everything together gives
$$ \lim_{\gamma \to 0} \int_{-\infty}^{\infty} f_\gamma(x) t(x) \, \mathrm{d}x
= \pi t(0) $$
for every test function $t$.
