我正在播放第 15 页中的以下代码通过实践学习 METAPOST
prologues := 3;
outputtemplate := "%j-%c.eps";
beginfig(1);
save arrowhead;
vardef arrowhead(expr p) =
save A,u,a,b; pair A,u; path a,b;
A := point length(p)/2 of p;
u := unitvector(direction length(p)/2 of p);
a := A{-u}..(A - ahlength*u rotated 30);
b := A{-u}..(A - ahlength*u rotated -30);
(a & reverse(a) & b & reverse(b))--cycle
enddef;
u:=2cm; ahlength:=0.3cm;
drawarrow (0,0)..(u,u)..(-u,u);
endfig; end;
但是运行mpost arrow.mp
总是出现以下错误:
This is MetaPost, version 2.00 (TeX Live 2019) (kpathsea version 6.3.1)
(/usr/local/texlive/2019/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2019/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./arrow.mp
! Missing argument to arrowhead.
<to be read again>
_apth
_finarr->...._apth(TEXT0);filldraw.arrowhead._apth
(TEXT0)
<to be read again>
;
l.15 drawarrow (0,0)..(u,u)..(-u,u);
?
我的 Tex 设置:
$ brew cask info mactex
mactex: 2019.0508
谁可以帮我这个事?
答案1
您使用的教程是 2005 年的,因此您可能会发现它与当前 METAPOST 版本存在一些不兼容之处。在这种情况下,只需删除定义中的括号即可arrowhead
。
梅威瑟:
prologues := 3;
outputtemplate := "%j-%c.eps";
beginfig(1);
save arrowhead;
vardef arrowhead expr p =
save A,u,a,b; pair A,u; path a,b;
A := point length(p)/2 of p;
u := unitvector(direction length(p)/2 of p);
a := A{-u}..(A - ahlength*u rotated 30);
b := A{-u}..(A - ahlength*u rotated -30);
(a & reverse(a) & b & reverse(b))--cycle
enddef;
u:=2cm; ahlength:=0.3cm;
drawarrow (0,0)..(u,u)..(-u,u);
endfig; end;
结果:
请参阅其他示例http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html,我用它来找到这个答案的正确语法。
答案2
这里有一个小改进,将箭头放在路径的中间,而不是中间点:
vardef arrowhead expr p =
save A,u,a,b,t; pair A,u; path a,b; numeric t;
t = arctime 1/2 (arclength p + ahlength) of p;
A := point t of p;
u := unitvector(direction t of p);
a := A{-u}..(A - ahlength*u rotated 30);
b := A{-u}..(A - ahlength*u rotated -30);
(a & reverse(a) & b & reverse(b))--cycle
enddef;
像这样:
新事物
arclength p
返回路径的长度p
(以 PostScript 点为单位)(而不是 MP“时间”)arctime x of p
p
返回达到给定长度的时间x
。