<s>[INST] What is $\int \frac1{1+(a\tan x)^2}dx$? What is $\int \frac1{1+(a\tan x)^2} \mathrm dx$?
This is a difficult integral. If you can, please give a step-by-step solution - I would be delighted. 
 [/INST] It's not that hard if you take the suggestion from Clayton:
$u=a \tan{x}$; $x = \arctan{(u/a)}$; $dx=a\, du/(u^2+a^2)$.  Then the integral is
$$a \int \frac{du}{(u^2+a^2)(u^2+1)} $$
Assume $a \ne 1$.  Use partial fractions:
$$\frac{1}{u^2+a^2}-\frac{1}{u^2+1} = \frac{1-a^2}{(u^2+a^2)(u^2+1)}$$
so the integral becomes
$$\frac{a}{1-a^2} \int du \left (\frac{1}{u^2+a^2}-\frac{1}{u^2+1} \right ) = \frac{a}{1-a^2} \left (\frac{1}{a} \arctan{\frac{u}{a}} - \arctan{u} \right )+C$$
Therefore
$$\int \frac{dx}{1+a^2 \tan^2{x}} = \frac{1}{1-a^2} \left (x - a \arctan{(a \tan{x})}\right )+C $$
When $a=1$, however, we get that the integral is
$$\int \frac{dx}{1+\tan^2{x}} = \int dx \cos^2{x} = \frac{x}{2} + \frac12 \sin{x} \cos{x} + C$$
</s>