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.