How to evaluate $\int \frac{\cos x}{a-\cos x} \mathrm{d}x $ in a more elegant way? I am trying to evaluate
$$\int \frac{\cos x}{a-\cos x} \mathrm{d}x \quad (1)$$

Since there is a ratio of trigonometric functions, I tried to reduce the problem to a polynomial ratio by using Weierstrass substitutions:
$$t = \tan\left(\frac{x}{2}\right) \iff x = 2\arctan(t)  \iff \mathrm{d}x = \frac{2}{t^2+1}$$
$$\cos x = \dfrac{1 - t^2}{1 +  t^2}$$
$$\sin x = \dfrac{2t}{1 + t^2}$$
Therefore from $(1)$:
$$ \int \frac{1-t^2}{1+t^2} \frac{1}{a-\frac{1-t^2}{1+t^2}}\frac{2}{1+t^2}\mathrm{d}t = a \int \frac{1-t^2}{1+t^2} \frac{1}{1+(a+1)t^2} \mathrm{d}t $$

The function is a ratio such as: $\deg(1-t^2) = 2 < 4 = \deg((1+3t^2)(1+t^2))$ therefore we can break the relationship to partial fractions. We notice that the denominator has complex roots, therefore:
$$ \int \frac{1-t^2}{(1+t^2)(1+(a+1)t^2)} \mathrm{d}t = \cdots = \int -\frac{1}{t^2+1}+\frac{2}{(a+1)t^2+1} \mathrm{d}t$$
Therefore,
$$\int \frac{\cos x}{a-\cos x} \mathrm{d}x = -x + \frac{2a}{\sqrt{a^2-1}} \tan^{-1} \left(\sqrt{\frac{a+1}{a-1}} \tan \frac{x}{2} \right) + C$$

I feel there is an easier way to evaluate this integral. Can you come up with one?

Let $|a| > 1$.  Observe $$f_a(x) = \frac{\cos x}{a - \cos x} = \frac{(\cos x - a) + a}{a - \cos x} = -1 + \frac{a}{a - \cos x} = -1 + \frac{a}{a - (1 - 2 \sin^2 \frac{x}{2})}$$ where we have employed the half-angle identity $$\sin^2 \frac{x}{2} = \frac{1 - \cos x}{2}.$$  Consequently
$$\begin{align} f_a(x) 
&= -1 + a \frac{1}{(a-1) + 2 \sin^2 \frac{x}{2}} \\
&= -1 + a \frac{\sec^2 \frac{x}{2}}{(a-1) \sec^2 \frac{x}{2} + 2 \tan^2 \frac{x}{2}} \\
&= -1 + a \frac{\sec^2 \frac{x}{2}}{(a-1)(1+\tan^2 \frac{x}{2}) + 2 \tan^2 \frac{x}{2}} \\
&= -1 + \frac{2a}{a-1} \frac{\frac{1}{2}\sec^2 \frac{x}{2}}{1+ \frac{a+1}{a-1} \tan^2 \frac{x}{2}}.
\end{align}$$
With the substitution $$u = \sqrt{\frac{a+1}{a-1}}\tan \frac{x}{2}, \quad du = \frac{1}{2}\sqrt{\frac{a+1}{a-1}} \sec^2 \frac{x}{2} \, dx,$$ we obtain
$$\begin{align}
\int f_a(x) \, dx 
&= -x + \frac{2a}{a-1} \sqrt{\frac{a-1}{a+1}} \int \frac{du}{1 + u^2} \\
&= -x + \frac{2a}{\sqrt{a^2-1}} \tan^{-1} u + C \\
&= -x + \frac{2a}{\sqrt{a^2-1}} \tan^{-1} \left(\sqrt{\frac{a+1}{a-1}} \tan \frac{x}{2} \right) + C.
\end{align}$$
Of course, I have taken the trouble to write out each step in detail which makes the solution longer than it really needs to be.
As an exercise for the reader, how is this approach modified if $|a| < 1$?
