Substitute #t = tanx#, so that: #x=arctant# and #dx =(dt)/(1+t^2)#
#int tanx/(1+tanx+tan^2x)dx = int (tdt)/((1+t^2)(1+t+t^2)#
Separate the rational function:
#t/((1+t^2)(1+t+t^2) ) = A/(1+t^2)+B/(1+t+t^2)#
#t = A+At+At^2 +B +Bt^2#
#t = (A+B) +At +(A+B)t^2#
So #A=1#, #B=-1# and:
#int tanx/(1+tanx+tan^2x)dx = int (dt)/(1+t^2) - int (dt)/(1+t+t^2)#
The first integral is immediate:
# int (dt)/(1+t^2) = arctant+C#
For the second, complete the square at the denominator:
#int (dt)/(1+t+t^2) = int (dt)/((t+1/2)^2+3/4)#
#int (dt)/(1+t+t^2) = 4/3 int (dt)/(((2t+1)/sqrt3)^2+1)#
#int (dt)/(1+t+t^2) = 2/sqrt3 int (d((2t+1)/sqrt3))/(((2t+1)/sqrt3)^2+1)#
#int (dt)/(1+t+t^2) = 2/sqrt3 arctan((2t+1)/sqrt3)+C#
so:
#int tanx/(1+tanx+tan^2x)dx =arctant-2/sqrt3 arctan((2t+1)/sqrt3)+C#
and undoing the substitution:
#int tanx/(1+tanx+tan^2x)dx =x-2/sqrt3 arctan((2tanx+1)/sqrt3)+C#