Integration of secant $$\begin{align}
\int \sec x \, dx 
&= \int \cos x \left(  \frac{1}{\cos^2x} \right)  \, dx \\
&= \int \cos x \left(  \frac{1}{1-\sin^2x} \right) \, dx \\
& = \int\cos x\cdot\frac{1}{1-\frac{1-\cos2x}{2}} \, dx \\
&= \int \cos x \cdot\frac{2}{1+\cos2x} \, dx 
\end{align}$$
I am stuck in here. Any help to integrate secant?

\begin{align*}\int\sec x\,\mathrm dx&=\int\frac1{\cos x}\,\mathrm dx\\&=\int\frac{\cos x}{\cos^2x}\,\mathrm dx\\&=\int\frac{\cos x}{1-\sin^2x}\,\mathrm dx.\end{align*}
Now, doing $\sin x=t$ and $\cos x\,\mathrm dx=\mathrm dt$, you get $\displaystyle\int\frac{\mathrm dt}{1-t^2}$. But\begin{align*}\int\frac{\mathrm dt}{1-t^2}&=\frac12\int\frac1{1-t}+\frac1{1+t}\,\mathrm dt\\&=\frac12\left(-\log|1-t|+\log|1+t|\right)\\&=\frac12\log\left|\frac{1+t}{1-t}\right|\\&=\frac12\log\left|\frac{(1+t)^2}{1-t^2}\right|\\&=\log\left|\frac{1+t}{\sqrt{1-t^2}}\right|\\&=\log\left|\frac{1+\sin x}{\sqrt{1-\sin^2x}}\right|\\&=\log\left|\frac1{\cos x}+\frac{\sin x}{\cos x}\right|\\&=\log|\sec x+\tan x|.\end{align*}
