Q:

Expressing fomula in terms of Tan instead of Cos and Sin

I have the following formula in Mathematica: 
$$\frac{c \rho  S \left(\text{Z0} \cos \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)+i c \rho  S \sin \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)\right)}{c \rho  S \cos \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)+i \text{Z0} \sin \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)}$$
Code: 
(c S \[Rho] (Z0 Cos[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)] + 
   I c S \[Rho] Sin[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)]))/(
c S \[Rho] Cos[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)] + 
 I Z0 Sin[(5 (1 + 2 n) \[Pi] x)/(6 a + 10 L)])

I would like to manipulate it in Mathematica by dividing the numerator and denominator by $\cos \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)$ so that I get the same expression in terms of two Tan functions. Is there an easy way to do this? I've had a good look in the docs and can't seem to find anything!

A:

I like to use ComplexityFunction when possible.  For example, this seemed to work well in this case:
FullSimplify[expr, 
 ComplexityFunction -> 
  Function[e, 
   100 Count[e, _Cos | _Sin | E, {0, Infinity}] - 
    10 Count[e, _Tan, {0, Infinity}] + LeafCount[e]]]

$$\frac{c \rho  S \left(\text{Z0}+i c \rho  S \tan \left(\frac{5 \pi  (2 n+1) x}{6 a+10
   L}\right)\right)}{c \rho  S+i \text{Z0} \tan \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)}$$

A:

May be there is an easier way to automate this, but will let someone else figure it out.
Here is my attempt
expr = (c S ρ (Z0 Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)] + 
   I c S ρ Sin[(5 (1 + 2 n) π x)/(6 a + 
        10 L)]))/(c S ρ Cos[(5 (1 + 2 n) π x)/(6 a + 
      10 L)] + I Z0 Sin[(5 (1 + 2 n) π x)/(6 a + 10 L)]);

Now
divid = Cos[(5 (1 + 2 n) π x)/(6 a + 10 L)];
Expand@(Numerator[expr]/divid)/Expand@(Denominator[expr]/divid)

$$
\frac{c \rho  S \text{Z0}+i c^2 \rho ^2 S^2 \tan \left(\frac{5 \pi  (2 n+1) x}{6 a+10
   L}\right)}{c \rho  S+i \text{Z0} \tan \left(\frac{5 \pi  (2 n+1) x}{6 a+10 L}\right)}
$$

