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)
In each interval $(-\frac{\pi}{2}+k\pi,\frac{\pi}{2}+k\pi)$ the solution will be $F(x) = \frac12\arctan(2\tan x) + C_k $. To make it continuous for $x\in\mathbb R$ you need that for every $k\in\mathbb Z$ $$ \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^-} F(x) = \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^+} F(x) $$ that is
$$ \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^-} \frac12\arctan(2\tan x) + C_k = \lim_{x\rightarrow (k\pi+\frac{\pi}{2})^+} \frac12\arctan(2\tan x) + C_{k+1} $$
$$ \lim_{x\rightarrow (\frac{\pi}{2})^-} \frac12\arctan(2\tan x) + C_k = \lim_{x\rightarrow (-\frac{\pi}{2})^+} \frac12\arctan(2\tan x) + C_{k+1} $$
$$ \lim_{t\rightarrow +\infty} \frac12\arctan(2t) + C_k = \lim_{t\rightarrow -\infty} \frac12\arctan(2t) + C_{k+1} $$
$$ \frac{\pi}{4} + C_k = -\frac{\pi}{4} + C_{k+1} $$ $$ C_{k+1} = C_k + \frac{\pi}{2}$$ $$ C_k = C_0 +\frac{k\pi}{2}$$ You have then $$ F(x) = \frac12\arctan(2\tan x) + \frac{k\pi}{2} + C_0 \qquad \text{for } x\in (-\frac{\pi}{2}+k\pi,\frac{\pi}{2}+k\pi) $$ or equivalently $$ F(x) = \frac12\arctan(2\tan x) + \lfloor \frac{x}{\pi}+\frac12\rfloor \frac{\pi}{2} + C_0 $$