I would like to integrate $$ \int_{\Gamma_{W}}\frac{1}{\cos^2z}dz=\int_{-H}^{H}\frac{1}{\cos^2(W+iy)}idy $$ where the contour is the vertical line between $W-iH$ and $W+iH$. Of course, we know $$\frac{d}{dz}\tan z=\frac{1}{\cos^2z} \, ,$$ so as long as $W$ is not a zero of cosine (so that $\frac{1}{\cos^2z}$ is analytic in a neighborhood around the contour) it would seem that in this region $\tan z$ is a primitive of $\frac{1}{\cos^2z}$ so by the fundamental theorem of calculus that I can evaluate this as $$\int_{\Gamma_{W}}\frac{1}{\cos^2z}dz=\tan(W+iH)-\tan(W-iH) \, .$$
However, if I simply evaluate the tangent at the endpoints, then there is no difference between integrating along the blue contour or the red contour below. In each case, I can draw a neighborhood around the contour, in which $\frac{1}{\cos^2z}$ is analytic. Clearly the integrals along each contour should differ by the residue of the pole between them. What simple mistake am I making?
