Question: How to evaluate
$$\int \frac{ 1}{\cos(a) + \cos(x)} \, dx $$
where $a$ is a constant?

**My Attempt:**

I substituted in the integral:  

$A = \cos(a)$  

On solving by usual method, I got:  

$$ \frac{2 \arctan(\frac{\sqrt{A-1} . \tan(\frac{x}{2})}{\sqrt{A+1}})}{\sqrt{A^2-1}} + C$$
where $C$ is the constant of integration and $A^2> 1$.  

Now that means this solution does not work for $A = \cos(a)$.  

How should I proceed with this question in the simplest possible way (beginner's approach) so that it works for $A^2 < 1$?
Thanks in advance!

Answer: 
Note

\begin{align}
\int \frac{ 1}{\cos a+ \cos x} \, dx
&=\int \frac{ 1}{2\cos \frac{x-a}2 \cos \frac{x+a}2} \, dx\\
&= \frac1{2\sin a}\int\left(\frac{\sin \frac{x+a}2}{ \cos \frac{x+a}2} -\frac{\sin \frac{x-a}2}{ \cos \frac{x-a}2} \right)dx\\
&= \frac1{\sin a} \ln\bigg|\frac{ \cos \frac{x-a}2}{\cos \frac{x+a}2 }\bigg|+C
\end{align}
Use the substitution
$$
t=\tan(x/2)
$$
Then
$$
\cos a+\cos x=\cos a+\frac{1-t^2}{1+t^2}=\frac{1+\cos a-(1-\cos a)t^2}{1+t^2}
$$
and
$$
dx=\frac{2}{1+t^2}\,dt
$$
Now, for $\cos a\ne1$, set $b=\sqrt{(1+\cos a)/(1-\cos a)}$ and the integral becomes
$$
\frac{1}{b^2}\int\frac{2}{b^2-t^2}\,dt
$$
that's easily dealt with by using partial fractions:
$$
\frac{2}{b^2-t^2}=\frac{1/b}{b-t}+\frac{1/b}{b+t}
$$
The particular case when $\cos a=1$ can be treated separately.