The answer by corey979 has a little problem. The "Numerator" command in "complex[w]" function will be ill-behaved if w have several separated parts after "Together".
So that, the "Numerator" cannot extract the desired numerator out.
I haven't check the carefully, but when I used a very complicated w, the simplified form after "Together" are a sum of several fractions, which means "Together" doesn't work well, so that the "Numerator" doesn't work.
So, be sure to check is the result after "Together" and "Numerator".
For a corrected version, I suggest using the following one: