It is given that
∫x tan2 x dx
We can write it as
tan2 x = sec2 x – 1
So we get
∫xtan2 x dx = ∫x( sec2 x – 1) dx
By further simplification
= ∫ x sec2 x dx – ∫ x dx
Taking first function as x and second function as sec2 x
∫ x sec2 x dx – ∫ x dx
We get

By integration w.r.t x
= {x tan x – ∫tan x dx} – x2/ 2
It can be written as
= x tan x – log |sec x| – x2/ 2 + c
So we get
= x tan x – log |1/cos x| – x2/ 2 + c
Here
= x tan x + log |cos x| – x2/ 2 + c