Evaluate $\int \frac{\tan^3x+\tan x}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$ $$\int \frac{\tan^3x+\tan x}{\tan^3x+3 \tan^2x+2 \tan x+6} dx$$
My approaches so far has been using substitution with $\tan x = t$ and $\tan \frac x2 = t$ but the calculations has been harder than I think they should.
I've also tried using ordinary polynom integration to simplify the integral but I'm having problems with factorizing the denominator.

Given
$$
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx.
$$

Consider the substitution
$$
\boxed{\color{red}{\tan(x) = \sqrt{2} \tan(y)}},
$$
so
$$
\Big( \tan^2(x) + 1 \Big) dx = \sqrt{2} \Big( \tan^2(y) + 1 \Big) dy.
$$
so we obtain
$$
\begin{eqnarray}
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
&=& \int \frac{\tan(x) \Big( \tan^2(x) + 1 \Big)}
{ \Big( \tan(x) + 3 \Big) \Big( \tan^2(x) + 2 \Big) } dx\\
&=& \color{blue}{\int \frac{ \tan(y)}{ \sqrt{2} \tan(y) + 3 } dy}.
\end{eqnarray}
$$

Now
$$
\begin{eqnarray}
\int \frac{ \sqrt{2} -  3 \tan(y)}{ \sqrt{2} \tan(y) + 3 } dy
&=& \int \frac{ \sqrt{2} \cos(y) - 3 \sin(y) }{ \sqrt{2} \sin(y) + 3 \cos(y) } dy\\
&=& \int \frac{1}{ \sqrt{2} \sin(y) + 3 \cos(y) }
  d \Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)\\
&=& \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big),
\end{eqnarray}
$$
and
$$
\begin{eqnarray}
\int \frac{ \sqrt{2} \tan(y) + 3}{ \sqrt{2} \tan(y) + 3 } dy &=& y.
\end{eqnarray}
$$

We also have
$$
\begin{eqnarray}
\frac{\sqrt{2}}{11} \frac{ \sqrt{2} \tan(y) + 3}{ \sqrt{2} \tan(y) + 3 }
  - \frac{3}{11} \frac{ \sqrt{2} - 3 \tan(y)}{ \sqrt{2} \tan(y) + 3 } &=&
\frac{\tan(y)}{ \sqrt{2} \tan(y) + 3}.
\end{eqnarray}
$$

So we obtain
$$
\begin{eqnarray}
\color{blue}{\int \frac{\tan(y)}{ \sqrt{2} \tan(y) + 3} dy}
&=& \color{darkgreen}{\frac{\sqrt{2}}{11} y - \frac{3}{11} \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)}.
\end{eqnarray}
$$

The final result is
$$
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
= \color{darkgreen}{\frac{\sqrt{2}}{11} y - \frac{3}{11} \ln\Big( \sqrt{2} \sin(y) + 3 \cos(y) \Big)},
$$
where
$$
\color{red}{y = \arctan\left( \frac{ \tan(x) }{ \sqrt{2} } \right)}.
$$

Using the properties
$$
\begin{eqnarray}
\sin(\arctan(z)) &=& \frac{z}{\sqrt{1+z^2}},\\
\cos(\arctan(z)) &=& \frac{1}{\sqrt{1+z^2}},\\
\end{eqnarray}
$$
we obtain
$$
\boxed{
\begin{eqnarray}
\int \frac{\tan^3(x) + \tan(x)}{\tan^3(x) + 3\tan^2(x) + 2\tan(x)+6} dx
&=& \frac{\sqrt{2}}{11} \arctan\left( \frac{\tan(x)}{\sqrt{2}} \right)\\
&& \hspace{1em}
 + \frac{3}{11} \ln\left( \frac{ \tan(x) + 3 }{\sqrt{ 1 + \tan^2(x)/2 }} \right).
\end{eqnarray}}
$$
