Evaluate $\int \frac{1}{1+3\sin^2 x} dx$
I know that this has an antiderivative on $\mathbb{R}$
I can use the trig. substitution $t = \tan x$ on $(-\frac{\pi}{2}+k\pi, \frac{\pi}{2}+k\pi)$
$x = \arctan t$
$dx = \frac {1}{1+t^2} dt$
To get $\int \frac{1}{1+3\sin^2 x} dx$ = $\int \frac{1}{1+3\frac{t^2}{t^2+1} }\cdot \frac{1}{1+t^2} dt$ = $\int \frac{1}{1+(2t)^2} dt =\frac 1 2 \int{\frac {1}{1+u^2} du} = \frac 1 2 \arctan (2\tan x) + C$
But this only appplies on the interval $(-\frac{\pi}{2}+k\pi, \frac{\pi}{2}+k\pi)$, whereas the original function should have an antiderivative on $\mathbb {R}$. So I have to make it continuous, but I don't know how.
(I do know that we did a similar thing for $\int |x| \ dx $, but I lost my notes and don't know how doing this is called in english so I can't google it. We called it "gluing" antiderivatives. And I remember that we utilized limits in some fashion related to the integration constants)