Integration $\int \frac{\sec(x)}{\tan^2(x) + \tan(x)}$ How to evaluate the following integral $$\int \frac{\sec(x)}{\tan^2(x) + \tan(x)} \ dx$$
Thank you.
 A: HINT:
$$\dfrac{\sec x(\tan x+1-\tan x)}{\tan x(\tan x+1)}=\dfrac{\sec x}{\tan x}-\dfrac{\sec x}{\tan x+1}$$
$$\dfrac{\sec x}{\tan x+1}=\dfrac1{\sin x+\cos x}=\dfrac1{\sqrt2\sin\left(x+\dfrac\pi4\right)}\text {or }=\dfrac1{\sqrt2\cos\left(x-\dfrac\pi4\right)}$$
A: $$\int\frac{\sec{x}}{\tan^2x+\tan{x}}dx=\int\frac{\cos{x}}{\sin{x}(\sin{x}+\cos{x})}dx=$$
$$\int\left(\frac{1}{\sin{x}}-\frac{1}{\sin{x}+\cos{x}}\right)dx=-\int\left(\frac{d(\cos{x})}{\sin^2{x}}-\frac{d\left(\cos\left(\frac{\pi}{4}+x\right)\right)}{\sqrt2\sin^2\left(\frac{\pi}{4}+x\right)}\right)=$$
$$=-\int\left(\frac{d(\cos{x})}{(1-\cos{x})(1+\cos{x})}-\frac{d\left(\cos\left(\frac{\pi}{4}+x\right)\right)}{\sqrt2\left(1-\cos\left(\frac{\pi}{4}+x\right)\right)\left(1+\cos\left(\frac{\pi}{4}+x\right)\right)}\right)=$$
$$=-\ln\sqrt{\frac{1+\cos{x}}{1-\cos{x}}}+\frac{1}{\sqrt2}\ln\sqrt{\frac{1+\cos\left(\frac{\pi}{4}+x\right)}{1-\cos\left(\frac{\pi}{4}+x\right)}}+C=$$
$$=-\ln|\cot\frac{x}{2}|+\frac{1}{\sqrt{2}}\ln|\cot\left(\frac{\pi}{8}+\frac{x}{2}\right)|+C.$$
A: Note that:
\begin{align}
I = \frac{\sec x}{\tan^2x + \tan x} &= \frac{\frac{1}{\cos x}}{\frac{\sin^2x}{\cos^2x}+\frac{\sin x}{\cos x}}\\
&= \frac{\cos x}{\sin^2x+\sin x\cos x}\\
&=\frac{(\cos x + \sin x) - \sin x}{\sin x (\sin x + \cos x)}\\
&=\frac{1}{\sin x} - \frac{1}{\sin x + \cos x} \\
&= \csc x - \frac{1}{\sqrt{2}\sin(x+\frac{\pi}{4})}\\
&= \csc x - \frac{1}{\sqrt{2}}\csc(x+\frac{\pi}{4})
\end{align}
So that 
\begin{align}
\int \frac{\sec x}{\tan^2x + \tan x} dx&= \int \csc x - \frac{1}{\sqrt{2}}\csc(x+\frac{\pi}{4}) ~dx\\ &= -\ln|\csc x+\cot x| + \frac{1}{\sqrt{2}} \ln|\csc (x + \frac{\pi}{4})+\cot (x+\frac{\pi}{4})|+C
\end{align}
