Consider the function tanx=a0+a1x+a2x^2+...+a(n)x^n where a(n) is the coefficient of x^n.
We need to find a(n). We can do this by applying calculus (effectively Taylor's theorem). If we integrate tanxdx we get -ln(cosx). If we integrate the power series we get C+a0x+a1x^2/2+a2x^3/3+...+a(n)x^(n+1)/(n+1), where C is a constant of integration. This is a power series for -ln(cosx) or strictly, -ln|cosx|, because we can only take logs of positive numbers. Also cosx can only assume values between 0 and 1, so the log is negative, and we can write -ln|cosx| as ln|secx|. |secx| is always 1 or more.
Going back to the expansion for tanx, we know tan0=0, so a0=0. Therefore ln|secx|=C+a1x^2/2+...+a(n)x^(n+1)/(n+1). We'll see this pop up later when we integrate xtanx by parts.
The derivative of tanx is sec^2x=S(na(n)x^(n-1)) where S is the sum of n terms (from n=1), since a0=0. When x=0, sec^2x=1 and when x=(pi)/2, sec^2x=0. The only term for S not containing x is a1, so a1=1. So far the series for tanx is: x+S(na(n)x^(n-1)) for n>2. Not much to go on yet.
The next derivative is 2sec^2tanx=S(n(n-1)x^(n-2)) for n>2 (differentiation by substitution: let u=secx; du=secxtanxdx; d/dx=d/du*du/dx=2u*secxtanx=2sec^2xtanx). When x=0, tan0=0 so this derivative is zero, making 2a2=0, so a2=0.
The next derivative is 4sec^2xtan^2x+2sec^4x (differentiation by parts: u=2sec^2x, v=tanx; du=4sec^2xtanxdx, dv=sec^2xdx; d(uv)=vdu+udv=(tanx)(4sec^2xtanxdx)+(2sec^2x)(sec^2xdx)). This derivative is 2 when x=0, so 6a3=2 and a3=1/3 (from n(n-1)(n-2)a(n)x^(n-3) where n=3).
The 4th derivative is 8tanxsec^3x+8sec^2tan^3+8sec^4xtanx, which is zero when x=0 and a4=0.
The 5th derivative is:
8tanx(3sec^3xtanx)+8sec^3x(sec^2x)+8sec^2x(3tan^2sec^x)+8tan^3(2sec^2tanx)+8sec^4x(sec^2x)+8tanx(4sec^4tanx)
This derivative is 16 when x=0. The relevant term is 120a5, so a5=16/120=2/15.
tanx=x+x^3/3+2x^5/15+...
xtanx=x^2+x^4/3+2x^6/15+...
integrate: x^3/3+x^5/15+2x^7/105+...
Another way of approaching the series is to use the power series for sinx and cosx because tanx=sinx/cosx.
Just as we found the coefficients of the power series for tanx, we can do the same for sinx, when we get sinx=x-x^3/3!+x^5/5!-x^7/7!+... And cosx is derivative of sinc, so cosx=1-x^2/2!+x^4/4!-... Also tanx*cosx=sinx, so we can use this identity to derive the coefficients for tanx. (a0+a1x+a2x^2+...)(1-x^2/2!+x^4/4!-...)=x-x^3/3!+x^5/5!-...=a0+a1x+...+a1x-a1x^3/2!+a1x^5/4!-...+a2x^2-a2x^4/2!... By equating the coefficients for a particular power of x we can work out the unknown coefficients a(n). For example, because there are no even powers of x in the expansion of sinx, a0=0 (which we already discovered), a2, a4, etc. are all zero. to find a1, we need all terms involving x. Since a1x is the only one, a1=1; to find a3, we have -a1x^3/2=-x^3/6 so a1=1/3; a1x^5/24-a3x^5/2+a5x^5=x^5/120, 1/24-1/6+a5=1/120, a5=1/120-1/24+1/6=(1-5+20)/120=16/120=2/15, as we discovered earlier. What is a7? To get the coefficient of x^7 we need to combine x with x^6, x^3 with x^4, x^5 with x^2 and x^7. The coefficients are a1, a3, a5 and a7 from tanx; -1/6!, 1/4!, -1/2! from cosx; -1/5040 from sinx. -a1/720+a3/24-a5/2+a7=-1/5040;
-1/720+1/72-1/15+a7=-1/5040;
a7=1/720-1/72+1/15-1/5040=(7-70+336-1)/5040=272/5040=17/315.
Now we return to integral xtanxdx. Let u=x, then du=dx; dv=tanxdx, then v=ln|secx|, as we discovered earlier. d(uv)=vdu/dx+udv/dx=ln|secx|dx+xtanxdx.
So integral(xtanxdx)=xln|secx|-integral(ln|secx|dx)=xln|secx|-(x^3/3+x^5/15+2x^7/105+...)+C.