How to draw the deformation of contour of integration in the complex plane?

I would like to draw the following picture. So far my code is the following:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings,positioning}
\begin{document}
\begin{tikzpicture}[scale=1.5,
decoration = {markings,
mark=at position 0.10 with {\arrow {latex}},
mark=at position 0.35 with {\arrow {latex}},
mark=at position 0.70 with {\arrow {latex}},
mark=at position 0.95 with {\arrow {latex}}
}
]
% axes
\draw [->] (0,-2) --(0,2) node [left] {${\rm Im}(p)$};
\draw [->] (-2,0) --(2,0) node [below] {${\rm Re}(p)$};
% poles
\foreach \i in {-1,-0.5, 0.5, 1}{\node at (0.5,\i) {$\times$};}
% text
\draw[<-,shorten <=2mm] (0.5,1)-- ++ (20:1.5) node[right] {residues};
\draw[<-,shorten <=2mm] (0.5,0.5)-- ++ (35:1.5);
\end{tikzpicture}
\end{document}


Unfortunately, I do not know how to draw the deformed contours around multiple poles.

So, I would appreciate if anyone could help me draw the deformed contours (I am comfortable in drawing the directed arrows and including the text.)

• Off-topic: don't use \rm. 20+ years obsolete. – cfr Dec 15 '16 at 3:20
• @cfr What should I use then? – johnny09 Dec 15 '16 at 4:46
• \mathrm{} or \text{} here (with the amsmath package) or \rmfamily or \textrm{} in text? The standard LaTeX 2e NFSS font selection commands. The 2 letter switches should not be used in LaTeX 2e documents. – cfr Dec 16 '16 at 0:26

Use \rmfamily instead of \rm. But, for math mode, use the \mathXX equivalents, where XX is the usual sf, bf, rm. As for the drawing, you can name the nodes that represent the poles and use their border anchors to access them. To get the node size, we use let \p1=($(node.east)-(node.center)$) then \x1 is the radius value, finally, to draw the arc around the nodes, use an arc operation, since we now know the radius to be \x1.

To let everything as flexible as possible I used a macro \openingangle to hold ist value (the opening angle is represented by the big circle on the bottom right Corner of the picture). I've left the rest of the arrows for you to complete as it's only manual labor of guessing the values.

MWE

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings,positioning}
\begin{document}
\begin{tikzpicture}[scale=1.5,
decoration = {markings,
mark=at position 0.003 with {\arrow {latex}},
mark=at position 0.06 with {\arrow {latex}},
mark=at position 0.1 with {\arrow {latex}},
mark=at position 0.16 with {\arrow {latex}},
mark=at position 0.198 with {\arrow {latex}},
},
arcpath/.style={insert path={arc[start angle=\lower, delta angle=360-\openingangle, radius=\x1]}}
]
% axes
\draw [->] (0,-2) --(0,2) node [left] {$\mathrm{Im}(p)$};
\draw [->] (-2,0) --(2,0) node [below] {$\mathrm{Re}(p)$};
% poles
\foreach \i/\j in {-1/a,-0.5/b, 0.5/c, 1/d}{\node[circle, inner sep=1pt] (\j) at (0.5,\i) {$\times$};}
% text
\def\openingangle{30}
\pgfmathsetmacro{\lower}{180+0.5*\openingangle}
\pgfmathsetmacro{\upper}{180-0.5*\openingangle}
\draw[<-,shorten <=2mm] (d) -- ++ (20:1.5) node[right] (res) {residues};
\draw[<-,shorten <=2mm] (c) -- (res);
\draw[postaction={decorate}, looseness=2]
(-0.75,0) coordinate (int) let \p1=($(a.east)-(a.center)$) in
|- (c.\lower) [arcpath] (c.\upper) -| (int|-d.\lower) -- (d.\lower) [arcpath] (d.\upper) -- (int|-d.\upper)
to[out=110, in=90] (-1.75,0) to[out=-90, in=-110]
(int|-a.\lower) -- (a.\lower) [arcpath] (a.\upper) -| (int|-b.\lower) -- (b.\lower) [arcpath] (b.\upper) -- (int|-b.\upper) -- (int);
\begin{scope}[scale=3, every node/.style={scale=3}]
\node[minimum width=1em, circle] (a) at (.5,-.5) {};
\draw let \p1=($(a.east)-(a.center)$) in (a.\lower) [arcpath] (a.\upper) -- (a.center) -- (a.\lower);
\end{scope}
\end{tikzpicture}
\end{document}