Complex integration exercise with $\arctan $ Show that $$\int_0^{2\pi}\arctan\Bigl( \frac {\sin x} {\cos x -2 }\Bigl) \, dx=0.$$ I can write this as $$\mathrm {Im}\int_0^{2\pi}\log(  e^{ix}-2)\,dx.$$ Making the substitution  $z =e^{ix} $ leads to $\operatorname{Im}\int_C\log(  z-2)\frac {dz}{iz}$. This should be equal to $2\pi \log (-2)$. However the imaginary part of $\log (-2)$ is not $0,$ so I must be wrong somewhere. Thanks for any clarify
 A: I initially thought the issue was that $\operatorname{Arg}(a+ib)=\arctan \left(\frac{b}{a} \right)$ only if $a>0$.
But $$ \begin{align} \int_{0}^{2 \pi} \arctan \left(\frac{\sin x}{\cos x -2} \right) \, \mathrm dx  &= \int_{0}^{\pi} \arctan \left(\frac{\sin x}{\cos x -2} \right) \, \mathrm dx +  \int_{\pi}^{2 \pi} \arctan \left(\frac{\sin x}{\cos x -2} \right) \, \mathrm dx \\ &= \int_{0}^{\pi} \left( \Im \left(\log(e^{ix}-2)\right) - \pi\right)\, \mathrm dx + \int_{\pi}^{2\pi} \left( \Im \left(\log(e^{ix}-2)\right) + \pi\right)\, \mathrm dx \\ &= \Im \int_{0}^{2 \pi} \log(e^{ix}-2) \, \mathrm dx \end{align}$$
So that's not the issue.
The issue is instead the fact that we're using the principal branch of the logarithm, and the branch cut for $\log(z-2)$ intersects the unit circle.
To get around this, we can rewrite the integral as 
$$ \begin{align} \int_{0}^{2 \pi} \arctan \left(\frac{-\sin x}{2-\cos x }\right) \mathrm dx &= \Im \int_{0}^{2 \pi} \log(2-e^{ix}) \, \mathrm dx \\ &= \Im \int_{|z|=1} \log(2-z) \, \frac{\mathrm dz}{iz}  \\ &=\Im \left( 2 \pi  \log 2 \right) \\ &=0. \end{align}$$
When using the principal branch of the logarithm, the branch cut for $\log(2-z)$ is on $[2, \infty)$ since that is where $2-z$ is real and negative.
A: $$
\begin{aligned}
\int_0^{2\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx &= 
\int_0^{\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx + 
\int_{\pi}^{2\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx = \\
|\text{in a second integral}: x = 2\pi-y| &\Leftrightarrow \\ 
|y \text{ changes from }\pi \text{ to } 0; dx = -dy| &= \\
&=\int_0^{\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx + 
\int_{\pi}^{0}\arctan\left(\frac{\sin(2\pi-y)}{\cos(2\pi-y) - 2}\right)(-dy) = \\
|\sin(2\pi-y) = -\sin y| \\
|\cos(2\pi-y) = \cos y| \\
&=\int_0^{\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx + 
\int_{0}^{\pi}\arctan\left(\frac{-\sin y}{\cos y - 2}\right)dy = \\
|\arctan(-x) = -\arctan x| \\
|\text{in a second integral, let} y = x| \\
&=\int_0^{\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx - 
\int_{0}^{\pi}\arctan\left(\frac{\sin x}{\cos x - 2}\right)dx = 0.
\end{aligned}
$$
