Dirichlet Integral via complex integration: problem with last step. I am trying to understand the derivation of the Dirichlet Integral via complex integration (as outlined on wikipedia) but I have a problem with the last steps.
We consider $$f(z) = \frac{e^{iz}}{z}$$ and define $$g(z) = \frac{e^{iz}}{z+i \epsilon}$$ in order to move the pole away from the origin. Since for $g$ there are now no poles on the upper half of the complex plane we know by Cauchy's Residue Theorem that for $\gamma $ the semicircle of radius R centred at the origin $$\int_\gamma g = 0$$ i.e. $$ 0 = \int_R^R \frac{e^{ix}}{x+i\epsilon} \, dx + \int_0^\pi \frac{e^{i(Re^{i\theta} + \theta)}}{Re^{i\theta}+i\epsilon} iR \, d\theta$$
I see how the second term vanishes as $R \to \infty$ but I am not sure about the details of how to find $$\int_R^R \frac{e^{ix}}{x+i\epsilon} \, dx  = P.V.\;\int\frac{e^{ix}}{x}\,dx - \pi i \int_\mathbb{R} \delta(x) e^{ix}dx$$ (P.V. indicating the Cauchy Principal Value) That is to say I do not understand how it follows from Sokhotski–Plemelj  that the equation in the last line is true.
 A: The way you're doing is unknow to me and it looks too messy, so I propose you the following.
Putting $\,\displaystyle{f(z):=\frac{e^{iz}}{z}}\,$ , we get
$$Res_{z=0}(f)=\lim_{z\to 0}\,zf(z)=e^0=1$$
Putting now $\,\gamma_r:=\{z=r^{it}\;\;;\;\;0\leq t\leq \pi\}\,$ , we can use the lemma and specially its corollary that appear in the answer here to get
$$\lim_{\epsilon\to 0}\int_{\gamma_\epsilon}f(z)\,dz=\pi i\;\;\text{(going in the positive direction, of course)}$$
So defining the path
$$\Gamma:=[-R,-\epsilon]\cup\gamma_\epsilon\cup[\epsilon,R]\cup\gamma_R\,\,\;,\;\;\;\;\epsilon,R\in\Bbb R^+\,\,,\,\epsilon<<R$$
we get by Cauchy's Theorem
$$0=\oint_\Gamma\,f(z)\,dz=\int_{-R}^{-\epsilon}\frac{e^{ix}}{x}dx-\int_{\gamma_\epsilon}f(z)\,dz+\int_\epsilon^R\frac{e^{ix}}{x}dx+\int_{\gamma_R}f(z)\,dz$$
Using now Jordan's Lemma or evaluating directly, we get 
$$\int_{\gamma_R}f(z)\,dz\xrightarrow [R\to\infty]{} 0$$  
and 
$$0=\lim_{\epsilon\to 0\,,\,R\to\infty}\oint_\Gamma f(z)\,dz=\int_{-\infty}^\infty\frac{e^{ix}}{x}dx-\pi i\Longrightarrow$$
$$\int_{-\infty}^\infty\frac{\cos x+i\sin x}{x}dx=\pi i$$
so comparing imaginary parts and taking into account that $\,\displaystyle{\frac{\sin x}{x}}\,$ is an even function, we get what we want.
