Solution (source code)

= Solution

Use $\tan^2x=\sec^2x-1$ and the derivative of the <tangent>:
$$
\boxed{\int\tan^2x\,dx=\tan x-x+C.}
$$
The antiderivative applies on each interval avoiding the poles of $\tan x$.