<s>[INST] 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.
 [/INST] 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}
</s>