I see in a calculus textbook that, for $|A| \neq 1$, \begin{align} f(x) &\equiv \int \frac{1}{A + \cos x} \,\text{d}x \\&=\frac{1}{ \sqrt{A^2 - 1} } \left( x - 2 \tan^{-1} \frac{ \sin x }{ A + \sqrt{A^2 - 1} + \cos x } \right) \end{align} which I have verified using Mathematica
$$\frac{\text{d}\, f(x)}{\text{d}\, x} = \frac{1}{A + \cos x}$$
However, I have failed to show the equivalence (up to a constant) of $f(x)$ to the more sensible form obtained by Mathematica (as explained here): $$g(x) \equiv \int \frac{1}{A + \cos x} \,\text{d}x = \frac{-2}{\sqrt{1-A^2}} \tanh ^{-1}\frac{(A-1) \tan \frac{x}{2}}{\sqrt{1-A^2}}$$ With the half angle substitution, one can replace $\tan \frac x2$ in above result. However, what really stumps me is how to get the linear term and arctangent in $f(x)$. It seems reasonable to try some identities involving inverses like $$\tanh^{-1}(\sin x) = \sinh^{-1}(\tan x) $$ or equivalently $$ \sin^{-1}( \tanh x ) = \tan^{-1}( \sinh x )$$ together with some common ways to combine $\sin x$ and $\cos x$. But, so far, I have gotten nowhere.
There are several ways to compute $$I=\int \frac{dx}{A + \cos x} $$ Using the tangent half-angle substitution $t=\tan \left(\frac{x}{2}\right)$, it reduces to $$I=2\int \frac{dt}{(A-1) t^2+(A+1)}=\frac 2{A-1}\int\frac{dt}{t^2+\frac{A+1}{A-1}}$$ So, now, using $$t=\sqrt{\frac{A+1}{A-1}}u\implies I=\frac{2 }{\sqrt{A-1} \sqrt{A+1}}\tan ^{-1}\left(\frac{\sqrt{A-1} }{\sqrt{A+1}}t\right)$$ but,as you can see, there could be some problem depending on the value of $A$. If $A >1$, I think that this is the best form to use.
If $A<1$, the argument of the tangent becomes an imaginary number but we can use the identity $\tan(i \theta)=i\tanh(\theta)$ and the the second formula.