<s>[INST] Evaluate $\int \frac{x\tan(x) \sec(x)}{(\tan(x)-x)^2}$ Find value of following integral $$\int \frac{x\tan(x) \sec(x)}{(\tan(x)-x)^2}\text{dx}$$
the numerator is $\text{d[sec(x)]}$ but that isnt work due to $x$ in denominator. First we can simplify as $$\int\frac{x\sin(x)}{(\sin(x)-x\cos(x))^2} \text{dx} = \int \frac{x}{(\sin(x)-x\cos(x))} \text{dx}+\int \frac{x^2 \cos(x)}{(\sin(x)-x\cos(x))^2} \text{dx}$$
but again its not manipulative. Suggest a useful substitution or method.
Thanks a lot!
 [/INST] \begin{array}{rcl}
\displaystyle \int \dfrac{x \sec x \tan x \,dx}{(\tan x - x)^2} &=& \displaystyle\int\color{red}{\left(-x\csc x\right)}\cdot \color{blue}{\left(\dfrac{-\tan^2 x}{\left(\tan x - x\right)^2}\right)\,dx}\\
&=&\displaystyle \int \color{red}{(-x\csc x)\cdot \color{blue}{d\left(\dfrac{1}{\tan x - x}\right)}}\\
&=& \dfrac{x\csc x}{x-\tan x}-\displaystyle \int \dfrac{d(-x\csc x)}{\tan x - x}\\
&=& \dfrac{x\csc x}{x-\tan x}-\displaystyle \int \dfrac{x\csc x \cot x -\csc x}{\tan x - x}\,dx\\
&=& \dfrac{x\csc x}{x-\tan x}-\displaystyle \int \dfrac{\csc x \cot x\left(x - \tan x\right)}{\tan x - x}\,dx\\
&=& \dfrac{x\csc x}{x-\tan x} - \displaystyle \int \left(-\csc x \cot x\right)\,dx\\
&=& \dfrac{x\csc x}{x -\tan x} - \csc x + C\\
&=& \csc x \left(\dfrac{x}{x - \tan x} - 1\right)+C\\
&=& \dfrac{\csc x\tan x}{x - \tan x} + C\\
&=& \dfrac{\sec x}{x - \tan x} + C
\end{array}
</s>