答案1
像这样吗?
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
vardef ATdraw(text t) =
save n, edge;
numeric n; n = 0;
string edge[];
for s=t:
edge[incr n] = s;
endfor
save poly; path poly;
poly = for i=0 upto n-1: 80 down rotated (360/n*i-180/n) -- endfor cycle;
ahangle := 30;
image(
for i=1 upto n:
string sense, marker;
sense = substring (0, 1) of edge[i];
marker = substring (1, length edge[i]) of edge[i];
if sense = "+":
drawarrow subpath (i-1, i-1/2) of poly;
draw subpath (i-1/2, i) of poly;
else:
drawarrow subpath (i, i-1/2) of poly;
draw subpath (i-1/2, i-1) of poly;
fi
label("$" & marker & "$", 84 down rotated (360/n*(i-1)));
endfor
)
enddef;
beginfig(1);
draw ATdraw("+a_1","+a_2","+a_3","+a_4","+a_5","-a_1","-a_2","-a_3","-a_4","-a_5");
draw ATdraw("+b_{10}","+b_{20}","+b_{30}","-b_{40}","+b_{50}") shifted 200 right;
endfig;
\end{mplibcode}
\end{document}
编译它以lualatex
获得如下图片:
笔记
如果您的参数是字符串,则更容易。然后您可以拥有任意内容。否则每个参数都必须是有效的 MP 语法。在这种情况下,
a5-
例如无效。我已经将字符串定义为以
+
或为前导-
,后跟一些数学模式 TeX 作为边缘标签。要处理可变数量的参数,可以使用
text
参数说明符。这里使用它来将所有内容读入名为的变量中。然后,您可以使用所示的简单循环t
逐步执行。MP 将在每个逗号处自动拆分。t
t