beginfig(1);
numeric u;
path xaxis,yaxis;
Scale: 1=u
u=0.5in;
yaxis= (0,-4.1u)--(0,4.2u);
xaxis= (-4.1u,0)--(4.2u,0);
pickup pencircle scaled 1pt;
drawarrow xaxis;
drawarrow yaxis;
pickup pencircle scaled 0.1pt;
for i=0 upto 100: draw (-4+i*0.1,-4)*u--(-4+i*0.1,4)*u; endfor;
for i=0 upto 100: draw (-4,-4+i*0.1)*u--(4,-4+i*0.1)*u; endfor;
pickup pencircle scaled 0.25pt;
for i=0 upto 10: draw (-4+i,-4)*u--(-4+i,4)*u; endfor;
for i=0 upto 10: draw (-4,-4+i)*u--(4,-4+i)*u; endfor;
label.rt(btex $x$ etex, (4.2u,0));
label.top(btex $y$ etex, (0,4.2u));
endfig(1);
end.
答案1
OP 图像的代码有语法错误。幸运的是,程序metapost
给出了用户友好的提示来找到它们。程序metapost
对代码中的两行感到不满:第一个抱怨
>> Scale
! Isolated expression.
<to be read again>
:
l.4 Scale:
1=u
?
指出第 4 行(标记为 l.4)并表示这1=u
是一个孤立的表达式,即它在上下文中毫无意义。由于我们无法猜测该行代码的含义,因此最简单的修复方法是完全删除该行,或者(作为最小修正)只需在其前面加上 即可使其成为注释%
。
修复此问题后,metapost
程序的下一个抱怨是关于第 19 行的:
! Extra tokens will be flushed.
<to be read again>
(
l.19 endfig(
1);
?
这意味着该(
令牌不应该存在,解决方法是删除(1)
。
经过两次修正后,代码如下
beginfig(1);
numeric u;
path xaxis,yaxis;
%Scale: 1=u
u=0.5in;
yaxis= (0,-4.1u)--(0,4.2u);
xaxis= (-4.1u,0)--(4.2u,0);
pickup pencircle scaled 1pt;
drawarrow xaxis;
drawarrow yaxis;
pickup pencircle scaled 0.1pt;
for i=0 upto 100: draw (-4+i*0.1,-4)*u--(-4+i*0.1,4)*u; endfor;
for i=0 upto 100: draw (-4,-4+i*0.1)*u--(4,-4+i*0.1)*u; endfor;
pickup pencircle scaled 0.25pt;
for i=0 upto 10: draw (-4+i,-4)*u--(-4+i,4)*u; endfor;
for i=0 upto 10: draw (-4,-4+i)*u--(4,-4+i)*u; endfor;
label.rt(btex $x$ etex, (4.2u,0));
label.top(btex $y$ etex, (0,4.2u));
endfig;
end.
程序metapost
很乐意编译它。