How to evaluate the trigonometric integral $\int \frac{1}{\cos x+\tan x }dx$ 
$$\int \dfrac{1}{\cos x+\tan x }dx$$ 

This can be converted to 

$$\int \dfrac{\cos x}{\sin x+\cos^2x}dx$$

But from here I get stuck. Using t substitution will get you into a mess. Are there any tricks  which can split the fraction into simpler forms? 
 A: As commented above the Weirstrass substitution 
$$
\begin{equation*}
t=\tan \frac{x}{2}\Leftrightarrow x=2\arctan t,\,dx=\frac{2}{
1+t^{2}}dt,
\end{equation*}
$$
can be applied to the given integral. The integrand becomes a rational
fraction in $t$, because
$$
\begin{equation*}
\cos x=\frac{1-\tan ^{2}\frac{x }{2}}{1+\tan ^{2}\frac{x}{2}}=\frac{1-t^{2}}{1+t^{2}},\,\quad\sin x=\frac{2\tan \frac{x }{2}}{1+\tan ^{2}
\frac{x }{2}}=\frac{2t}{1+t^{2}}.
\end{equation*}
$$
We have
$$
\begin{eqnarray*}
I &=&\int \frac{1}{\cos x+\tan x}\,dx,\qquad t=\tan \frac{x}{2} \\
&=&\int \frac{2}{\left( \frac{1-t^{2}}{1+t^{2}}+\frac{2t}{1-t^{2}}\right)
\left( 1+t^{2}\right) }\,dt \\
&=&\int \frac{2(1-t^{2})}{t^{4}+2t^{3}-2t^{2}+2t+1}\,dt.
\end{eqnarray*}
$$
Since
$$
\begin{equation*}
t^{4}+2t^{3}-2t^{2}+2t+1=\left( t^{2}+(1-\sqrt{5})t+1\right) \left( t^{2}+(1+\sqrt{5})t+1\right), 
\end{equation*}
$$
we can expand the integrand into partial fractions
$$
\begin{equation*}
\frac{2(1-t^{2})}{t^{4}+2t^{3}-2t^{2}+2t+1}=\frac{\sqrt{5}}{5}\left( \frac{2t+1+\sqrt{5}}{t^{2}+(1+\sqrt{5})t+1}-\frac{2t+1-\sqrt{5}}{t^{2}+(1-\sqrt{5})t+1}\right).
\end{equation*}
$$
Consequently,
$$
\begin{equation*}
I=\frac{\sqrt{5}}{5}\int \frac{2t+1+\sqrt{5}}{t^{2}+(1+\sqrt{5})t+1}\,dt-
\frac{\sqrt{5}}{5}\int \frac{2t+1-\sqrt{5}}{t^{2}+(1-\sqrt{5})t+1}\,dt.
\end{equation*}
$$
Set $u(t)=t^{2}+(1+\sqrt{5})t+1,v(t)=t^{2}+(1-\sqrt{5})t+1$. Then
$$
\begin{eqnarray*}
I &=&\frac{\sqrt{5}}{5}\int \frac{u^{\prime }(t)}{u(t)}\,dt-\frac{\sqrt{5}}{5}\int \frac{v^{\prime }(t)}{v(t)}\,dt \\
&=&\frac{\sqrt{5}}{5}\log \left\vert u(t)\right\vert -\frac{\sqrt{5}}{5}\log
\left\vert v(t)\right\vert +C \\
&=&\frac{\sqrt{5}}{5}\log \left\vert \frac{t^{2}+(1+\sqrt{5})t+1}{t^{2}+(1-\sqrt{5})t+1}\right\vert +C \\
&=&\frac{\sqrt{5}}{5}\log \left\vert \frac{\tan ^{2}\frac{x}{2}+(1+\sqrt{5})\tan \frac{x}{2}+1}{\tan ^{2}\frac{x}{2}+(1-\sqrt{5})\tan \frac{x}{2}+1}\right\vert +C.
\end{eqnarray*}
$$
A: $$\displaystyle\int \dfrac{\cos x}{\sin x+\cos^2x}dx = \displaystyle\int \dfrac{1}{\sin x+\cos^2x}d\sin x = \displaystyle\int \dfrac{1}{\sin x+(1-\sin^2x)}d\sin x$$
A: HINT:
$$I=\displaystyle\int \dfrac{\cos x}{\sin x+\cos^2x}dx$$
$$=\displaystyle\int \dfrac{\cos x}{\sin x+1-\sin^2x}dx$$
Put $\sin x=u, \cos xdx=du $
$$\implies I=\int \frac{du}{1+u-u^2}=\int \frac{4du}{5-(2u-1)^2}$$ 
Put $2u-1=v$ and use Partial Fraction Decomposition or  $$\int\frac{dx}{a^2-x^2}=\frac1{2a}\ln\left|\frac{a+x}{a-x}\right|+C $$
