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.)

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*}
