Real and imaginary part of $\tan(a+bi)$ When dealing with complex trigonometric functions, it is quite natural to ask how the real/imaginary part of $\tan(a+bi)$ can be expressed using $a$ and $b$.
Of course, since $\tan z$ and $\tanh z$ are tightly linked for complex variables, we could derive the real/imaginary part for hyperbolic tangent from  the corresponding results for $\tanh(a+bi)$ and vice-versa. (We have $\tanh(iz)=i\tanh z$ and $\tan(iz)=i\tanh(z)$.)
I was not able to find this in a few basic sources I looked at. For example, I do not see it in the Wikipedia articles Trigonometric functions (current revision) and Hyperbolic function (current revision). (And List of trigonometric identities (current revision) does not mention much about complex trigonometric functions other than the relation to the exponential function.)
I have at least tried to find what are a results for some specific value of $a$ and $b$. I have tried a few values in WolframAlpha, for example, tangent of $2+i$, tangent of $1+2i$, tangent of $1+i$.
On this site I found this question: Calculate $\tan(1+i)$.
I have tried to calculate this myself, probably my approach is rather cumbersome - I post it below as an answer. I will be grateful for references, different derivations, different expressions for this formula. (And I will also be grateful if I receive some corrections to my approach - but do not treat this primarily as a solution-verification question, it is intended as a general question.)
 A: We want to express $\tan(a+bi)$ in the form
$$\tan(a+bi)=A(a,b)+B(a,b)i,$$
the two functions $A(a,b)$ and $B(a,b)$ are what we are looking for.
We have
\begin{align*}
\tan(a+bi)&=\frac{\sin(a+bi)}{\cos(a+bi)}\\
&\overset{(1)}=\frac{\sin a\cos(bi)+\cos(a)\sin(bi)}{\cos a\cos(bi)-\sin a\sin(bi)}\\
&\overset{(2)}=\frac{\sin a\cosh b+i\cos a\sinh b}{\cos a\cosh b-i\sin a\sinh b}\\
&=\frac{(\cos a\cosh b+i\sin a\sinh b)(\sin a\cosh b+i\cos a\sinh b)}{\cos^2a\cosh^2b+\sin^2a\sinh^2b}\\
&=\frac{\cos a\sin a(\cosh^2b-\sinh^2b)+i(\cos^2a+\sin^2a)\cosh b\sinh b}{\cos^2a\cosh^2b+\sin^2a\sinh^2b}\\
&=\frac{\cos a\sin a+i\cosh b\sinh b}{\cos^2a\cosh^2b+\sin^2a\sinh^2b}
\end{align*}
$(1)$: Using sum angle formulas.
$(2)$: Using $\cos iz=\cosh z$ and $\sinh i = i\sinh z$.
We would like to simplify this further, it seems that double argument formulae might help. In the numerator we can use that $\cos a \sin a = \frac{\sin 2a}2$ and $\cosh b \sinh b = \frac{\sinh2b}2$. For the denominator let us try that from the double angle formulas $\cos2x=\cos^2x-\sin^2x=2\cos^2x-1=1-2\sin^2x$ and $\cosh2x=\cosh^2x+\sinh^2x=2\cosh^2x-1=2\sinh^2x+1$ we can get that
\begin{align*}
\cos^2x&=\frac{1+\cos2x}2\\
\sin^2x&=\frac{1-\cos2x}2\\
\cosh^2x&=\frac{\cosh2x+1}2\\
\sinh^2x&=\frac{\cosh2x-1}2\\
\end{align*}
Now we have for the denominator $D$:
\begin{align*}
D&=\cos^2a\cosh^2b+\sin^2a\sinh^2b\\
&=\frac{1+\cos2a}2\cdot\frac{\cosh2b+1}2+\frac{1-\cos2a}2\cdot\frac{\cosh2b-1}2\\
&=\frac{1+\cos2a+\cosh2b+\cos2a\cosh2b}4+\frac{1+\cos2a-\cosh2b-\cos2a\cosh2b}4\\
&=\frac{\cos2a+\cosh2b}2
\end{align*}
So altogether we get that
$$\tan(a+bi)=\frac{\cos a\sin a+i\cosh b\sinh b}{\cos^2a\cosh^2b+\sin^2a\sinh^2b} = \frac{\sin2a+i\sinh2b}{\cos2a+\cosh2b}.$$
So for the real and imaginary part we get
\begin{align*}
A(a,b)&=\frac{\sin2a}{\cos2a+\cosh2b}\\
B(a,b)&=\frac{\sinh2b}{\cos2a+\cosh2b}
\end{align*}
A: By definition,
$$
\tan z=\frac{\sin z}{\cos z}
$$
Note that $\sin\bar{z}=\overline{\sin z}$ and $\cos\bar{z}=\overline{\cos z}$, so the real part is
$$
\frac{1}{2}\left(\frac{\sin z}{\cos z}+\frac{\sin\bar{z}}{\cos\bar{z}}\right)=
\frac{\sin(z+\bar{z})}{\cos z\cos\bar{z}}
$$
and similarly the imaginary part is
$$
\frac{1}{2i}\frac{\sin(z-\bar{z})}{\cos z\cos\bar{z}}
$$
If $z=a+bi$, then $z+\bar{z}=2a$ and $z-\bar{z}=2bi$, whereas
$$
\cos z=\cos a\cosh b-i\sin a\sinh b
$$
because $\cos(ib)=\cosh b$ and $\sin(ib)=i\sinh b$. Also
$$
\cos z\cos\bar{z}=\lvert\cos z\rvert^2=
\cos^2a\cosh^2b+\sin^2a\sinh^2b
$$
Therefore
$$
\tan(a+bi)=\frac{\sin a\cos a}{\cos^2a\cosh^2b+\sin^2a\sinh^2b}+
i\frac{\sinh b\cosh b}{\cos^2a\cosh^2b+\sin^2a\sinh^2b}
$$
A: Another option is the compound angle formula, viz. $$\tan(a+bi)=\frac{\tan a+\tan bi}{1-\tan a\tan bi}=\frac{\tan a+i\tanh b}{1-i\tan a\tanh b}=\frac{(\tan a +i\tanh b)(1+i\tan a\tanh b)}{1+\tan^2 a\tanh^2 b}.$$The real part is $\frac{\tan a (1-\tanh^2 b)}{1+\tan^2 a\tanh^2 b}=\frac{\tan a \operatorname{sech}^2 b}{1+\tan^2 a\tanh^2 b}$; the imaginary part is $\frac{\tanh b(1+\tan^2 a)}{1+\tan^2 a\tanh^2 b}=\frac{\tanh b\sec^2 a}{1+\tan^2 a\tanh^2 b}$.
A: Use the formula
$$\tan( \alpha + \beta) = \frac{\sin 2\alpha + \sin 2 \beta}{\cos 2 \alpha + \cos 2 \beta}$$
(the geometric interpretation: the complex number $e^{i 2 \alpha} + e^{i 2 \beta}$ has argument $\alpha + \beta$ - draw a picture!)
We get
$$\tan(x+ i y) = \frac{\sin 2x + \sin i 2 y}{\cos 2x + \cos i 2 y} = \frac{\sin 2x + i \sinh 2y}{\cos 2x + \cosh 2y}$$
