<s>[INST] integrate square of $\arctan x$.  Tricky $$\int \left(\frac{\tan^{-1}x}{x-\tan^{-1}x}\right)^{2}dx$$
I ran across an integral I am having a time solving.
The solution merely works out to $\displaystyle\frac{1+x\tan^{-1}x}{\tan^{-1}x-x}$, but for the life of me I can not find a suitable method to tackle it.
Does anyone have any hints on a good strategy, substitution, parts, etc?. Thanks much.
 [/INST] With $x = \tan(u)$, $\mathrm{d}x = \frac{1}{\cos^2(u)}\mathrm{d} u$, thus
$$
    \int \left(\frac{\tan^{-1}x}{x-\tan^{-1}x}\right)^{2} \mathrm{d}x = 
    \int \left( \frac{u}{\tan(u) - u} \cdot \frac{1}{\cos(u)} \right)^2 \mathrm{d} u =
    \int \left( \frac{u}{\sin(u) - u \cdot \cos(u)}  \right)^2 \mathrm{d} u
$$
Now, observe that
$$
  \mathrm{d} \left( \frac{1}{\sin(u)-u \cos(u)} \right) = \frac{-u \sin(u) \mathrm{d} u }{(\sin(u)-u \cos(u))^2}
$$
This allows to integrate by parts:
$$
 \begin{eqnarray}
 I &=& \int \left( \frac{u}{\sin(u) - u \cdot \cos(u)}  \right)^2 \mathrm{d} u = 
  \int \left( -\frac{u}{\sin(u)} \right) \mathrm{d}\left( \frac{1}{\sin(u)-u \cos(u)}
   \right)  \\
&=&  -\frac{u}{\sin(u)\left(\sin(u)-u \cos(u) \right)} + \int \frac{1}{\sin(u)-u \cos(u)} \mathrm{d} \left( \frac{u}{\sin(u)}  \right) \\
  &=& -\frac{u}{\sin(u)\left(\sin(u)-u \cos(u) \right)} + \int \frac{\mathrm{d}u}{\sin^2(u)} \\
  &=& -\frac{u}{\sin(u)\left(\sin(u)-u \cos(u) \right)} - \frac{1}{\tan(u)} + C \\
  &=& -\frac{\arctan(x)}{\frac{x}{\sqrt{1+x^2}} \left(\frac{x}{\sqrt{1+x^2}} -\arctan(x) \cdot \frac{1}{\sqrt{1+x^2}} \right)} - \frac{1}{x} + C  \\
  &=& -\frac{1}{x} \left( 1+  \frac{(1+x^2) \arctan(x) }{x -  \arctan(x)}\right) + C =
      -\frac{ 1 + x \arctan(x) }{x - \arctan(x)} + C
  \end{eqnarray}
$$
</s>