Calculation of Complex Limit When trying to calculate a residue, I came across this limit:
$$L:=\lim_{z\to \pi k} \frac{z^3-2z^2}{(1-\mathrm e^{\mathrm iz})\sin(z)}\left[\frac{(3z^2-4z)(z-\pi k)^2}{z^3-2z^2}+2(z-\pi k)-\frac{(z-\pi k)^2\cos(z)}{\sin(z)}+\frac{(z-\pi k)^2\mathrm i\,\mathrm e^{\mathrm i z}}{1-\mathrm e^{\mathrm iz}}\right]$$
where $0\neq k\in\mathbb Z$ and $k$ is even.
Since the limits of the individual summands do not exist, it seems to be very hard to apply l'Hopital to the whole fraction.
Is there any way to simplify this in order to calculate the limit?
(The original problem was to find the residue of $z\mapsto\frac{z^2(z-2)}{(1-\exp(\mathrm i z))\sin(z)}$ at $z=k\pi$ where $0\neq k$ is an even integer.)
Thank you.

We can calculate the limit using series expansion at $z=\pi k$ where $0\neq k\in\mathbb Z, k \text{ even}$. We recall
\begin{align*}
\cos(z)&=1+\mathcal{O}\left((z-\pi k)^2\right)\\
e^{iz}&=1+i(z-\pi k)+\mathcal{O}\left((z-\pi k)^2\right)\\
\frac{1}{\sin(z)}&=\frac{1}{z-\pi k}+\mathcal{O}\left(z-\pi k\right)\\
\frac{1}{1-e^{iz}}&=\frac{i}{z-\pi k}+\frac{1}{2}+\mathcal{O}\left(z-\pi k\right)
\end{align*}
where we expand the series up to terms we need for calculation and put everything else into big-$\mathcal{O}$'s.

We obtain
\begin{align*}
\color{blue}{\lim_{z\to\pi k}}&\color{blue}{\frac{z^3-2z^2}{\left(1-e^{iz}\right)\sin z}\left[\frac{(3z^2-4z)(z-\pi k)^2}{z^3-2z^2}+2(z-\pi k)\right.}\\
&\qquad\qquad\color{blue}{\left.-\frac{(z- \pi k)^2\cos z}{\sin z}+\frac{(z-\pi k)^2ie^{iz}}{1-e^{iz}}\right]}\\
&=\lim_{z\to  \pi k}(3z^2-4z)(z-\pi k)^2\left(\frac{1}{z-\pi k}+\mathcal{O}\left(z-\pi k\right)\right)\\
&\qquad\qquad\cdot\left(\frac{i}{z-\pi k}+\frac{1}{2}+\mathcal{O}\left(z-\pi k\right)\right)\\
&\qquad+\lim_{z\to\pi k}\left(z^3-2z^2\right)\left[2(z-\pi k)-\frac{(z- \pi k)^2\cos z}{\sin z}+\frac{(z-\pi k)^2ie^{iz}}{1-e^{iz}}\right]\\
&\qquad\qquad\cdot\left(\frac{1}{z-\pi k}+\mathcal{O}\left(z-\pi k\right)\right)
\left(\frac{i}{z-\pi k}+\frac{1}{2}+\mathcal{O}\left(z-\pi k\right)\right)\tag{1}\\
&=\left(3\pi^2k^2-4\pi k\right)i+\left(\pi^3k^3-2\pi^2k^2\right)\lim_{z\to \pi k}\left[\frac{2i}{z-\pi k}\right.\\
&\qquad\left.-i\frac{\cos z}{\sin z}-\frac{e^{iz}}{1-e^{iz}}
+1-\frac{1}{2}\frac{(z-\pi k)\cos z}{\sin z}+\frac{i}{2}\frac{(z-\pi k)e^{iz}}{1-e^{iz}}\right]\tag{2}\\
&=\left(3\pi^2k^2-4\pi k\right)i+\left(\pi^3k^3-2\pi^2k^2\right)\lim_{z\to \pi k}\left[\frac{2i}{z-\pi k}+1\right.\\
&\qquad\left.-\left(\frac{z-\pi k}{2}+i\right)\frac{\cos z}{\sin z}+\left(i\frac{z-\pi k}{2}-1\right)\frac{e^{iz}}{1-e^{iz}}\right]\tag{3}\\
&=\left(3\pi^2k^2-4\pi k\right)i+\left(\pi^3k^3-2\pi^2k^2\right)\lim_{z\to \pi k}\left[\frac{2i}{z-\pi k}+1\right.\\
&\qquad-\left(\frac{z-\pi k}{2}+i\right)\left(\frac{1}{z-\pi k}+\mathcal{O}\left(z-\pi k\right)\right)\\
&\qquad\left.+\left(i\frac{z-\pi k}{2}-1\right)\left(\frac{i}{z-\pi k}-\frac{1}{2}+\mathcal{O}\left(z-\pi k\right)\right)\right]\tag{4}\\
&=\left(3\pi^2k^2-4\pi k\right)i+\left(\pi^3k^3-2\pi^2k^2\right)\lim_{z\to \pi k}\left[\frac{2i}{z-\pi k}+1\right.\\
&\qquad\left.-\frac{1}{2}-\frac{i}{z-\pi k}-\frac{1}{2}-\frac{i}{z-\pi k}-\frac{i}{4}\left(z-\pi k\right)+\frac{1}{2}\right]\tag{5}\\
&\,\,\color{blue}{=\frac{1}{2}\pi^3k^3-\pi^2k^2+\left(3\pi^2k^2-4\pi k\right)i}
\end{align*}

Comment:

*

*In (1) we separate the first bracketed term by a limit of its own, since it can be calculated separately from the other terms. We cancel $z^3-2z^2$ and use the  series expansion of $\frac{1}{1-e^{iz}}$ and  $\frac{1}{\sin z}$.


*In (2) we calculate the first limit. We factor out $z^3-2z^2$ and evaluate it at $z=\pi k$. We multiply out within in the limit and skip terms which do not contribute.


*In (3) we collect related terms.


*In (4) we expand $\frac{\cos z}{\sin z}$ and $\frac{e^{iz}}{1-e^{iz}}$ at $z=\pi k$.


*In (5) we multiply out and cancel again terms which do not contribute. Now we are ready to cancel away some terms in the last step and do a final limit calculation.
