Recall the the angle sum identity for cosine.
[tex]\cos(\theta+\varphi)=\cos\theta\cos\varphi-\sin\theta\sin\varphi[/tex]
[tex]\cos(\theta-\varphi)=\cos\theta\cos\varphi+\sin\theta\sin\varphi[/tex]
Adding the two equations together gives
[tex]\cos(\theta+\varphi)+\cos(\theta-\varphi)=2\cos\theta\cos\varphi[/tex]
while subtracting gives
[tex]\cos(\theta+\varphi)-\cos(\theta-\varphi)=-2\sin\theta\sin\varphi[/tex]
Replacing [tex]\theta=3x[/tex] and [tex]\varphi=-x[/tex], you get
[tex]\dfrac{\cos2x-\cos4x}{\cos2x+\cos4x}=\dfrac{\cos(3x+(-x))-\cos(3x-(-x))}{\cos(3x+(-x))+\cos(3x-(-x))}=\dfrac{-2\sin3x\sin(-x)}{2\cos3x\cos(-x)}[/tex]
Finally, [tex]\cos(-x)=\cos x[/tex], so you get the second expression.