Calculate this integral using most elementary methods: $\int \arctan^2 x \,\mathrm dx$ My attempt:
$$\int \arctan^2x \,\mathrm dx=\arctan x\left(x \arctan x-\dfrac{\ln|1+x^2|}{2}\right)-\int\dfrac{\left(x \arctan x-\frac{\ln|1+x^2|}{2}\right)}{1+x^2}\,\mathrm dx$$
I tried calculating this first
$$\displaystyle\int\dfrac{x\arctan x}{1+x^2}dx$$
For this last integral, let $u=\arctan x, \mathrm dx=\mathrm du(1+x^2)$   , then
$$\int\dfrac{x\arctan x}{1+x^2}\,\mathrm dx=\displaystyle\int u\tan u\,\mathrm du$$
For $\displaystyle\int u\tan u\,\mathrm du$ first try:
$$\displaystyle\int u\tan u\,\mathrm du=-u\ln|\cos u|+\displaystyle\int \ln|\cos u|\,\mathrm du$$
I couldn't do anything with this integral (only tried $\tan(u/2)=j$).
For $\displaystyle\int u\tan u \,\mathrm du$ second try:
$$\displaystyle\int u\tan u \,\mathrm du=\frac{u^2}{2}\tan u-\dfrac12\displaystyle\int u^2\sec^2u \,\mathrm du$$
Then we clearly see, we have nothing.
And... I couldn't even calculate $\dfrac12\displaystyle\int\dfrac{\ln|1+x^2|}{1+x^2}\,\mathrm dx$
 A: Write the arc tangent using logarithms to get:
$$I:= \int \arctan^2x \,\mathrm d x=-\frac 14\int \left( \ln (1+xi)-\ln(1-xi)\right)^2\,\mathrm d x=\\
\int \ln^2(1+xi)\,\mathrm dx-2\int \ln (1-xi)\ln(1+xi)\,\mathrm d x+\int \ln^2(1-xi)\,\mathrm d x
$$

The first integral can be solved by substituting $u=1+xi$ and then integrating by parts:
$$I_1:=\int \ln^2(1+xi)\,\mathrm dx=-i\int\ln^2(u)=-i\left(2\int \ln u\,\mathrm d u+u\ln^2u\right)=-i\left( u\ln^2u-2u\ln u+2u\right)=\boxed{-iu\ln^2u+2iu\ln u-2iu}$$

The third integral is a bit more difficult but similar - substitute $u=-1+xi$, $v=\ln u$ and then integrate by parts twice to get the result:
$$I_3:=\ln^2(1-xi)\,\mathrm d x=-i\int(\ln u+\ln(-1))^2\,\mathrm d u=-i\int e^v(v+\pi i)^2 \,\mathrm d v=\\
2i\int e^v(v+\pi i)\,\mathrm d v-ie^v(v+\pi i)=\boxed{-ie^v\left((v+\pi i)^2-2(v+\pi i)+2\right)}$$

The second integral however is much trickier and messier. First, integrate by parts:
$$-2I_2:=-2\int\ln(1-xi)\ln(1+xi)\,\mathrm d x \\
I_2=\int\ln(1-xi)\ln(1+xi)\,\mathrm d x=-\int\frac{(x-i)\ln(1+xi)-x+i}{x+i}\,\mathrm d x-\\
i(1+xi)\ln(1-xi)\left( \ln(1+xi)-1\right)
$$
$$-J:=-\int\frac{(x-i)\ln(1+xi)-x+i}{x+i}\,\mathrm d x$$
Expand:
$$J=\int\frac{(x-i)\ln(1+xi)}{x+i}\,\mathrm d x-\int\frac{x}{x+i}\,\mathrm dx+i\int\frac{1}{x+i}\,\mathrm dx=\int\frac{(x-i)\ln(1+xi)}{x+i}\,\mathrm d x+\\
(1-i)(\ln(x+i))+x$$
Subsitute $u=x+i$ and expand again:
$$K:= \int\frac{(x-i)\ln(1+xi)}{x+i}\,\mathrm d x =\int\frac{(u-2i)\left( \ln(u-2i)+\frac\pi 2 i\right)}{u}\,\mathrm d u=\\
-2i\int\frac{\ln(u-2i)}{u}\,\mathrm d u+\int\ln(u-2i)\,\mathrm d u-\pi\ln u+\frac\pi 2 iu
$$
The second integral is solved immediately after substituting $v=u-2i$:
$$K_2:=\int\ln(u-2i)\,\mathrm d u=v\ln v-v=(u-2i)\ln(u-2i)-u+2i$$
To solve the first one we can rewrite the integrand:
$$-2iK_1:=-2i\int\frac{\ln(u-2i)}{u}\,\mathrm d u \\
K_1=\int \frac{\ln\left( \frac{i}{2}u+1\right)}{u}\,\mathrm d u+\left( \log 2-\frac{\pi}{2}i\right)(\ln u)$$
and now substitute $v=-\frac i2 u$ to finish by seeing that the integral is a dilogarithm:
$$\int \frac{\ln\left( \frac{i}{2}u+1\right)}{u}\,\mathrm d u=-\int -\frac{\ln(1-v)}{v}\,\mathrm d v=-\mathrm{Li}_2 (v)=-\mathrm{Li}_2\left( -\frac{i}{2}u\right)$$

And thus our integral is solved. Plug in all the previously solved integrals and undo the substitutions to get the final, messy result which I won't be writing out here.
A: Let $x\in {\mathbb R}$ then integrating by parts we have:
\begin{eqnarray}
\int \arctan(x)^2 dx =x \arctan(x)^2 - \log(1+x^2) \arctan(x) + \frac{1}{(2 \imath) }\sum\limits_{\xi\in\{-1,1\}} \xi \left( \log(\imath \xi+ x) \log(\frac{1}{2}(1+\imath \xi x))+ Li_2(\frac{1}{2}(1-\imath \xi x)) - \frac{1}{2} \log(x+ \imath \xi)^2\right) \quad (i)
\end{eqnarray}
In[1023]:= (*Integrate[Log[1+x^2]/(1+x^2],x]*)
f[x_] := 1/(2 I) Sum[
    xi (Log[I xi + x] Log[1/2 (1 + I xi x)] + 
       PolyLog[2, 1/2 (1 - I xi x)] - 1/2 Log[x + I xi]^2), {xi, -1, 
     1, 2}];
D[x ArcTan[x]^2 - Log[1 + x^2] ArcTan[x] + f[x], x] // Simplify

Out[1024]= ((1 + x^2) ArcTan[x]^2 + Log[-I + x] + Log[I + x] - 
 Log[1 + x^2])/(1 + x^2)

Therefore for example:
\begin{equation}
\int\limits_{-1}^1 \arctan(x)^2 dx = \frac{1}{8} (\pi  (\pi +\log (16))-16 C)
\end{equation}
where $C$ is the Catalan constant.
Now having said all this if $x$ is complex things get much more complicated since, firstly $\log(x+\imath) + \log(x-\imath) \neq \log(1+x^2)$ and secondly the quantitities in the right hand side in $(i)$ can be discontinuous and therefore we need to compute any definite integrals by avoiding discontinuities, i.e. as a principal value.
