答案1
TikZ 中的解决方案是将数学表达式的组成部分设置为一系列节点。然后将注释标签放置为节点。最后在节点之间绘制箭头。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{bookman}
\begin{document}
% \[
% \lambda x.\,(\lambda x.\, x\,y)\,
% (x\,(\lambda x.\,\lambda y.\,y\,z\,x))
% \]
\[
\begin{tikzpicture}[
inner sep=0pt,
outer sep=0pt,
baseline=(lx_1.base),
]
\path[every node/.append style={anchor=base west}]
(0, 0)
\foreach \name/\code in {
lx_1/\lambda x,
tmp/.\,(,
lx_2/\lambda x,
tmp/.\,,
x_1/x,
tmp/\,,
y_1/y,
tmp/)\,(,
x_2/x,
tmp/\,(,
lx_3/\lambda x,
tmp/.\,,
ly_1/\lambda y,
tmp/.\,,
y_2/y,
tmp/\,,
z_1/z,
tmp/\,,
x_3/x,
tmp/))%
} {
node (\name) {$\code$}
(\name.base east)
}
;
\path[
every node/.append style={
anchor=base,
font=\slshape\scriptsize,
},
]
% Annotation: frei
(y_1.base) -- node[above=1.2\baselineskip] (frei) {frei} (z_1)
% 4 annotations: gebunden
(lx_1.base) -- node[below=3\baselineskip] (geb_1) {gebunden} (x_2)
(lx_2.base) -- node[below=1.4\baselineskip] (geb_2) {gebunden} (x_1)
(lx_3.base) -- node[below=3\baselineskip] (geb_3) {gebunden} (x_3)
(ly_1.base) -- node[below=1.4\baselineskip] (geb_4) {gebunden} (y_2)
;
\begin{scope}[
>={Stealth[length=5pt]},
thick,
rounded corners=2pt,
shorten <=.3em,
shorten >=.3em,
]
\draw[->] (frei) -| (y_1);
\draw[->] (frei) -| (z_1);
\def\GebArrow#1#2#3{
\draw[->]
(#2.north) ++(0, .3em) coordinate (tmp)
(#1) |- (tmp) -| (#3)
;%
}
\GebArrow{x_2}{geb_1}{lx_1}
\GebArrow{x_1}{geb_2}{lx_2}
\GebArrow{x_3}{geb_3}{lx_3}
\GebArrow{y_2}{geb_4}{ly_1}
\end{scope}
\end{tikzpicture}
\]
\end{document}