I'm trying to make a command that will take in a function name, domain, codomain, arbitrary element, and what that element is mapped to, and output a diagram. The first line of the diagram will be the standard f:X-> Y. The second line will be rotated membership symbols for the domain and codomain. The third line will be something like x \mapsto f(x).
So far this is what I've tried:
\usepackage{graphicx}
\newcommand{\rotin}{\rotatebox[origin=c]{90}{$\in$}}
\begin{tikzpicture}
\node (functionName) at (0, 0) {f:};
\node[right = of functionName] (domain) {A};
\node[below = 1mm of domain] (rotinleft) {$\rotin$};
\node[below = 1mm of rotinleft] (element) {x};
\node[right = 1cm of domain] (codomain) {B};
\node[below = 0.5mm of codomain] (rotinright) {$\rotin$};
\node[below = 0.5mm of rotinright] (image) {f(x)};
\draw[->] (domain) -- (codomain);
\draw[|->] (element) -- (image);
\end{tikzpicture}
I'm new to relative positioning and this doesn't look very good. I want to be able to do something like the above, but have it so the spacing and arrow lengths will automatically adjust. I never want super short arrows.