<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] The denominator suggests that maybe an integration by parts will help where $v=\frac{1}{x-\arctan x}$.  This may make for a strange looking $dv$ that is not readily apparent from the given integral.
$$\frac{d}{dx}\left(\frac{1}{x-\arctan x}\right)=\frac{-\frac{x^2}{1+x^2}}{(x-\arctan x)^2}$$
So let's try $dv=\frac{-\frac{x^2}{1+x^2}}{(x-\arctan x)^2}$ and $u =-\arctan^2x\frac{1+x^2}{x^2}$.
Note  that $u = -\left(\frac{1}{x^2}+1\right)\arctan^2 x$.
Computing $du$, we have \begin{align}
du &=\left[-\left(\frac{1}{x^2}+1\right)\frac{2\arctan x}{1+x^2}+\frac{2\ \arctan^2x}{x^3}\right]dx\\
&=\frac{2\arctan x}{x^3}\left(\arctan x-x\right)\ dx\end{align}
Applying the integration by parts formula $\int u\,dv=uv-\int v\,du$, the given intergal is equal to $$-\left(\frac{1}{x^2}+1\right)\arctan^2 x\frac{1}{x-\arctan x}+\int\frac{2\arctan x}{x^3}\,dx$$
The new integral can be handled with another integration by parts where $u$ is $\arctan x$ and $dv$ is $2x^{-3}$.  That will leave you with a rational function in $x$, which can be integrated using partial fraction decomposition.  Once all of the integration is complete, the terms should add together to give what you know the antiderivative to be (perhaps with a constant difference).  These next steps are "ugly" details, but follow the description above.  We have 
\begin{align}&-\frac{\left(\frac{1}{x^2}+1\right)\arctan^2 x}{x-\arctan x}-\frac{\arctan x}{x^2}+\int\frac{1}{x^2(1+x^2)}\ dx\\
=&-\frac{\left(\frac{1}{x^2}+1\right)\arctan^2 x}{x-\arctan x}-\frac{\arctan x}{x^2}+\int\frac{1}{x^2}\ dx-\int\frac{1}{x^2+1}\ dx\\
=&-\frac{\left(\frac{1}{x^2}+1\right)\arctan^2 x}{x-\arctan x}-\frac{\arctan x}{x^2}-\frac{1}{x}-\arctan x+C\\
=&\frac{1+x\arctan x}{x^2(x-\arctan x)}-\frac{\arctan x(x-\arctan x)}{x^2(x-\arctan x)}\\&-\frac{x(x-\arctan x)}{x^2(x-\arctan x)}-\frac{x^2(x-\arctan x)\arctan x}{x^2(x-\arctan x)}+C\\
\\
=&-\frac{\left(1+x^2\right)\arctan^2 x}{x^2(x-\arctan x)}-\frac{\arctan x(x-\arctan x)}{x^2(x-\arctan x)}\\&-\frac{x(x-\arctan x)}{x^2(x-\arctan x)}-\frac{x^2(x-\arctan x)\arctan x}{x^2(x-\arctan x)}+C\\
\\
=&\frac{-x^2-x^3\arctan x}{x^2(x-\arctan x)}+C\\
=&-\frac{1+x\arctan x}{(x-\arctan x)}+C\\
\end{align}
</s>