What is the solution to this peculiar Integral: $\int \tan \left(\frac 1 x\right) \, dx$? I tried to integrate:
$$\int \tan \left(\frac 1 x\right) \, dx$$
using integration by parts, and also by universal substitution but to no avail. WolframAlpha reports that "no result found in terms of standard mathematical functions."
What could it be? 
 A: I will note you never stated you wanted a closed form. I will solve the integral using a summation expansion. I will also use this reference on properties of the tangent function. $B_y$ are Bernoulli numbers:
$$\mathrm{\int tan\left(\frac1x\right)dx=\int \frac{dx}{e^\frac ix-1}-\int\frac{dx}{e^\frac ix+1}-ix=\int i+2i\sum_{n=0}^\infty(-1)^n e^\frac{2in}{x}dx=ix+ \sum_{n=0}^\infty(-1)^n 2i\int e^\frac{2in}{x}dx}$$
There is a way to integrate for $|x|\ge\frac2\pi$:
It is seen in this

reference

that:
$$\mathrm{\int\frac{dx}{\tan^{-1}(x)}=\frac{x}{\tan^{-1}(x)}+ln\left(\tan^{-1}(x)\right)-\frac12 \sum_{n=2}^\infty\frac{(-4)^n\left(4^n-1\right)B_{2n} \left(\tan^{-1}(x)\right)^{2(n-1)}}{(n-1)(2n)!}+C=ln\left(tan^{-1}(x)\right)+\frac{x}{tan^{-1}(x)}-\frac{4}{\pi^2}\sum_{n\in \Bbb Z}\frac{ln\left(\pi(2n+1)-2tan^{-1}(x)\right)}{(2n+1)^2}+C}$$
graphical proof. Using the Inverse Function Integral theorem:
$$\mathrm{\int tan\left(\frac 1x\right)dx=C+x\, tan\left(\frac 1x\right)-\frac{tan\left(\frac 1x\right)}{tan^{-1}\left(tan\left(\frac 1x\right)\right)}-ln\left(tan^{-1}\left(tan\left(\frac 1x\right)\right)\right)+ \frac12 \sum_{n=2}^\infty\frac{(-4)^n\left(4^n-1\right)B_{2n} \left(\tan^{-1}(tan\left(\frac 1x\right))\right)^{2(n-1)}}{(n-1)(2n)!}= C+x\, tan\left(\frac 1x\right)-\frac{tan\left(\frac 1x\right)}{tan^{-1}\left(tan\left(\frac 1x\right)\right)}-ln\left(tan^{-1}\left(tan\left(\frac 1x\right)\right)\right)+ \frac{4}{\pi^2}\sum_{n\in \Bbb Z}\frac{ln\left|\pi(2n+1)-2tan^{-1}\left(tan\left(\frac 1x\right)\right)\right|}{(2n+1)^2}}$$
For a simplified integral of $|x|\ge\frac2\pi$,evaluate using $x^{2-2n}\to b^{2-2n}-a^{2-2n}$ and not $x^{2-2n}\to \frac{1}{b^{2n-2}-a^{2n-2}}$. This integral needs no constant for the definite integral in the graph. Unfortunately, I cannot simply using the sum of logarithm expression. Let’s name the integral t(x) for fun:
$$\mathrm{t(x)=\int tan\left(\frac1x\right)dx=C+ln(x)+\frac12\sum_{n=2}^\infty \frac{(-4)^n (4^n-1) B_{2n}x^{2-2n}}{(2n)!(n-1)}}$$
There should be others ways to integrate it though.
Also see this great answer for a modified simplified version of the other sum expression:

Integral of $\tan(1/x)$

