Evaluating $\int \frac{1}{a+b\sec(x)}dx$ I tried to find a closed-form expression for the integral
$$\int\frac{1}{a+b\sec(x)}\>dx$$ and, afterwards, set $a=0$, $b=1$ to recover the result for the simplified integral
$$\int\cos(x)\>dx=\sin(x)+C$$
The above integral was inspired by Américo Tavares’s rather illuminating solution to Ways to evaluate $\sec(t)$,

Here's the progress I've made which makes use of the integral
$$(\star)\int\frac{dx}{m^2+n^2x^2}=\frac{1}{mn}\arctan\left(\frac{nx}{m}\right)\quad m,n>0$$
Using $\cos(x)=2\cos^2(x/2)-1$, we get the following
$$I=\int\frac{dx}{a+b\sec(x)}=\int\frac{\cos(x)}{a\cos(x)+b}dx=\int\frac{2\cos^2(x/2)-1}{2a\cos^2(x/2)+b-a}dx\\=2\underbrace{\int\frac{dx}{2a+(b-a)\sec^2(x/2)}}_\color\red{(1)}-\underbrace{\int\frac{\sec^2(x/2)}{2a+(b-a)\sec^2(x/2)}dx}_\color\red{(2)}$$
$\color\red{(2)}$ becomes
$$\int\frac{\sec^2(x/2)}{2a+(b-a)\sec^2(x/2)}dx=\int\frac{\sec^2(x/2)}{a+b+(b-a)\tan^2(x/2)}dx\\=\frac{2}{\sqrt{b^2-a^2}}\arctan\left(\sqrt{\frac{b-a}{a+b}}\tan(x/2)\right)$$
from the substitution $u=\tan(x/2)$ and then applying $(\star)$.
For tackling $\color\red{(1)}$, the same u-substitution and applying partial fractions converts the integral into
$$\int\frac{dx}{2a+(b-a)\sec^2(x/2)}=2\int\frac{du}{(a+b+(b-a)u^2)(1+u^2)}\\=2\left[\frac{a-b}{2a}\int\frac{du}{(a+b+(b-a)u^2)}+\frac{1}{2a}\int\frac{du}{1+u^2}\right]$$
Thus
$$\int\frac{dx}{2a+(b-a)\sec^2(x/2)}=\frac{a-b}{a\sqrt{b^2-a^2}}\arctan\left(\sqrt{\frac{b-a}{a+b}}u\right)+\frac{1}{a}\arctan(u)\\=\frac{a-b}{a\sqrt{b^2-a^2}}\arctan\left(\sqrt{\frac{b-a}{a+b}}\tan(x/2)\right)+\frac{1}{a}\arctan(\tan(x/2)))$$
However, the problem is that setting $a=0$ afterwards results in the denominator becoming zero. Also, I couldn't think another approach to this.
Any help?
 A: As @Hussain-Alqatari commented, using immediately the tangent half angle substitution, you have
$$I=\int \frac{dx}{a+b\sec(x)}=\int \frac{2(1-t^2)}{ (b-a)t^4+2 b t^2+(a+b)}\,dt$$ Assuming $b\neq a$
$$I=\frac 2{b-a}\int \frac {1-t^2}{(t^2+1)(t^2-\alpha)}\,dt \qquad \text{with} \qquad \alpha=\frac{a+b}{a-b}$$ Using partial fraction decomposition
$$ \frac {1-t^2}{(t^2+1)(t^2-\alpha)}=-\frac{2}{1+\alpha }\frac 1{t^2+1}+\frac{1-\alpha }{1+\alpha }\frac 1 {t^2-\alpha}$$ which is very simple
$$\color{blue}{I=\frac{2 }{a}\tan ^{-1}(t)-\frac {2b}{a \sqrt{a^2-b^2}}\tanh ^{-1} \left(\sqrt{\frac{a-b}{a+b}}t\right)}$$
A: To derive the result valid for $a\to 0$, integrate as follows
\begin{align}
\int \frac{1}{a+b\sec x}dx
=& \frac1a \int \left(1- \frac{b}{b+a\cos x}\right)dx\\
 =& \frac1a \bigg(x-2b\int  \frac{d(\tan\frac x2)}{(b+a)+(b-a)\tan^2\frac x2}\bigg)\\
=& \frac1a \bigg( x- \frac{2b}{\sqrt{b^2-a^2}}\tan^{-1}\frac{\tan\frac x2}{\sqrt{\frac{b+a}{b-a}} \>}\bigg) +C\\
\end{align}
Note that
$$\lim_{a\to 0 } \frac{2b}{\sqrt{b^2-a^2}}\tan^{-1}\frac{\tan\frac x2}{\sqrt{\frac{b+a}{b-a}} }
= x - \frac ab \sin x+O(a^2)
$$
Thus
$$ \lim_{a\to 0}\> \int \frac{1}{a+b\sec x}dx=\frac1b \sin x+C
$$
as expected.
