Why $\int_0^{2\pi} \frac{dx}{2-\sin x}=0$? Of course this is not true, because the integrand is always greater than zero. However, when using Mathematica to do an indefinite integral of the general form
$$
\int\frac{dx}{\xi-\sin x} = -\frac{2\arctan\left[\frac{1-\xi\tan\frac{x}{2}}{\sqrt{\xi^2-1}}\right]}{\sqrt{\xi^2-1}}
$$
Now if you plug into the limit in the result, i.e. $0$ to $2\pi$, the result is zero. What's wrong with this argument? I must miss something very basic...
I don't need another way to do the integral, just need someone tell me why this doesn't work...
 A: The $\arctan$ function is multi-valued. When it appears in formulae for indefinite integrals you have to be careful when using it to calculate definite integrals, since in practice you use the principal branch ${\rm Arctan} : {\Bbb R} \cup {\infty}\to (-\pi/2,\pi/2]$ to evaluate the expression.
Let me illustrate by a simplified example:
$$ x = \int dx = 2\arctan(\tan(x/2)).$$
Again, calculating $\int_0^{2\pi} dx = 2\pi$ leads to the same paradoxe as yours if you evaluate using ${\rm Arctan}$ on the RHS. To solve the paradoxe note that there is a constant of integration which was omitted in the formula. You may change this constant when $\tan$ goes through a singularity $x=(2k+1)\pi$, $k\in {\Bbb Z}$ so as to make the result a continuous function.
Thus for my integral, if I want a continuous indefinite integral I should split ${\Bbb R}$ into intervals between these singularities:
$$ x =\int dx = 2{\rm Arctan} (\tan(x/2)) +  2\pi k,  \ \ \ \ \ \ {\rm when } \ \ x\in  \left((2k-1) \pi, (2k+1) \pi\right], k\in {\Bbb Z}.$$
which now is continuous and an identity for all $x\in {\Bbb R}$.
A drawback is, of course, that the formula becomes somewhat indigestible to read.
A: As Olivier Diaz has pointed out rightly in the comments, there is a problem with the domain. And, also the period of the function is $2 \pi$ and hence the limits can be shifted. 
Link for the graphs : https://www.desmos.com/calculator/dd6azsbkak

Note that the antiderivative you provided is wrong.
It is $$\dfrac{2\arctan\left(\frac{2\tan\left(\frac{x}{2}\right)-1}{\sqrt{3}}\right)}{\sqrt{3}}$$
You missed the $\sqrt{3}$
Anyways as we can see from the graph there is a discontinuity at $x= \pi$
Also note that the function is changing its signs. If you wanted to simply substitute limits it wouldn't work. It is similar to the case of $$\int_{-1} ^{1} |x|^3dx$$ where you need to resolve the limits for antiderivative $>0$ and $<0$
If we directly substitute limits we find that the integral is zero.
There is a difference between calculating area under a curve and value of definite integral
Thus we need to substitute limits from $0$ to $\pi$ first and then $\pi$ to $2\pi$. that would give the required answer. Also be careful about taking limit at $x=\pi$.
The explanation relating to $\int |x|^3dx$ is just a partial explanation. The actual discrepancy occurs due to the domain of $\tan^{-1}x$ only. Just integrate by breaking into two parts.
A: Open Image here
Hi, pls find the answer in the attached image. The answer should also yield 2π/sqrt(3) which is the same as mjw answer.
Please upvote if you find it useful
A: One popular method to find this integral is to let $z=e^{ix}$, so that
$\sin x = \frac{z+z^{-1}}{2i}$ and $\frac{dz}{iz} = dx.$
$$I=\int_0^{2\pi} \frac{dx}{2-\sin x} = \oint_C \frac{ \frac{dz}{iz}}{2-\frac{z-z^{-1}}{2i}}= -2\oint_C \frac{dz}{z^2-4iz-1}$$ where $C$ is the unit circle traversed counterclockwise.
$$I = -2 \oint \frac{dz}{(z-r_1)(z-r_2)}$$ where $r_1=i(2-\sqrt{3})$ and $r_2 = i(2+\sqrt{3})$.  The root $r_1$ is inside the circle and $r_2$ is outside.
We have $$I = -2\cdot (2\pi i)\cdot \text{Res}_{z=r_1} \, \frac{1}{(z-r_1)(z-r_2)}=- \frac{4 \pi i }{r_1-r_2} = \frac{2\pi  }{\sqrt{3}}.$$
