How to calculate the integral $\int \frac{a\tan^2{x}+b}{a^2\tan^2{x}+b^2} dx$? How to calculate the integral $\displaystyle\int \dfrac{a\tan^2{x}+b}{a^2\tan^2{x}+b^2} dx$?
It seems like a $\arctan$ of what else... but I can not work it out.
I have previously asked how to calculate the definite integral between $0$ and $\pi$ here, but the answers there only use complex analysis, so they are of no help for the indefinite integral.

Note that:
$$\begin{align}
\left(a+b\right)\left(a\tan^2{x}+b\right) & =a^2\tan^2{x}+b^2+ab\left(1+\tan^2{x}
\right) \\[5pt] & = \color{blue}{a^2\tan^2{x}+b^2}+ab\sec^2x\end{align}$$
So we then have:
$$\begin{align}\int \frac{a\tan^2{x}+b}{\color{blue}{a^2\tan^2{x}+b^2}} \,\mbox{d}x 
& = \frac{1}{a+b}\int\frac{\color{blue}{a^2\tan^2{x}+b^2}+ab\sec^2x}{\color{blue}{a^2\tan^2{x}+b^2}} \,\mbox{d}x \\[8pt]
& = \frac{1}{a+b}\int\left( 1 + \frac{ab\sec^2x}{a^2\tan^2{x}+b^2} \right) \,\mbox{d}x \tag{$\star$}\\[8pt]
& = \frac{1}{a+b}\Bigl( x+\arctan\left( \tfrac{a}{b}\tan x\right) \Bigr) +C 
\end{align}$$

Where $(\star)$ is a standard integral, or follows after $t=\tfrac{a}{b}y$, here with $y=\tan x$:
$$\int\frac{y(x)'}{a^2y(x)^2+b^2}\,\mbox{d}x = \frac{1}{ab}\arctan\left(\tfrac{a}{b}y\right)+C$$
