最近的更新似乎破坏了 metapost。还有人遇到问题吗?以下是从用于编译的文档中摘录的 MWE。感谢您的帮助。
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[reqno]{amsmath}
\usepackage{amsthm}
\usepackage{fourier}
%% use option 'nowrite' if graphics are stable
\usepackage[shellescape,latex]{gmp}
\usempxclass{article}
\usempxpackage{amsmath}
\usempxpackage{fourier}
%% ---------------------------------------------------------------
\begin{document}
%% PROBLEM 1a
\begin{mpost}[name=1a]
numeric v, u, xmin, xmax, ymin, ymax;
numeric ix, iy, tx, ty;
numeric ahlen, ahpos;
numeric gridwidth, axeswidth;
picture xl[], yl[];
ix=1; iy=1;
tx=1; ty=1;
v=0.8725cm;
u:=(1/tx)*v;
xmin=tx*(-6)/ix; xmax=tx*(6)/ix;
ymin=ty*(-6)/iy; ymax=ty*(6)/iy;
gridwidth:=0.46; axeswidth:=4*gridwidth;
ahlen:=((4/72.27)*2.54*tx);
% default arrowhead length is 4pt, compensate for scaling by $tx
ahangle:=36;
% metapost default arrowhead angle is 45 degrees
ahpos:=1;
labeloffset:=3.125;
%%%% Draw the axes
pickup pencircle scaled (gridwidth*1.0pt);
for i=xmin upto xmax: draw (i,ymin)*u--(i,ymax)*u; endfor;
for i=ymin upto ymax: draw (xmin,i)*u--(xmax,i)*u; endfor;
def opencircle(expr z, d, rgb) =
begingroup%
save p;
path p; background=white;
p = fullcircle scaled (2.3333*d) shifted (z);
fill p withcolor background;
draw p withcolor (rgb) withpen currentpen scaled 0.5;
endgroup%
enddef;
def solidcircle(expr z, d, rgb) =
save p; path p;
p = fullcircle scaled (2*d) shifted (z);
filldraw p withcolor (rgb);
enddef;
%% Horizontal labels;
xl[0] = thelabel.bot(\btex\large $-6$ etex, (xmin + tx*0,0)*u);
unfill bbox xl[0];
draw xl[0];
xl[1] = thelabel.bot(\btex\large $-5$ etex, (xmin + tx*1,0)*u);
unfill bbox xl[1];
draw xl[1];
xl[2] = thelabel.bot(\btex\large $-4$ etex, (xmin + tx*2,0)*u);
unfill bbox xl[2];
draw xl[2];
xl[3] = thelabel.bot(\btex\large $-3$ etex, (xmin + tx*3,0)*u);
unfill bbox xl[3];
draw xl[3];
xl[4] = thelabel.bot(\btex\large $-2$ etex, (xmin + tx*4,0)*u);
unfill bbox xl[4];
draw xl[4];
xl[5] = thelabel.bot(\btex\large $-1$ etex, (xmin + tx*5,0)*u);
unfill bbox xl[5];
draw xl[5];
xl[6] = thelabel.bot(\btex\large $1$ etex, (xmin + tx*7,0)*u);
unfill bbox xl[6];
draw xl[6];
xl[7] = thelabel.bot(\btex\large $2$ etex, (xmin + tx*8,0)*u);
unfill bbox xl[7];
draw xl[7];
xl[8] = thelabel.bot(\btex\large $3$ etex, (xmin + tx*9,0)*u);
unfill bbox xl[8];
draw xl[8];
xl[9] = thelabel.bot(\btex\large $4$ etex, (xmin + tx*10,0)*u);
unfill bbox xl[9];
draw xl[9];
xl[10] = thelabel.bot(\btex\large $5$ etex, (xmin + tx*11,0)*u);
unfill bbox xl[10];
draw xl[10];
xl[11] = thelabel.bot(\btex\large $6$ etex, (xmin + tx*12,0)*u);
unfill bbox xl[11];
draw xl[11];
%% Vertical labels;
yl[0] = thelabel.lft(\btex\large $-6$ etex, (0,ymin + ty*0)*u);
unfill bbox yl[0];
draw yl[0];
yl[1] = thelabel.lft(\btex\large $-5$ etex, (0,ymin + ty*1)*u);
unfill bbox yl[1];
draw yl[1];
yl[2] = thelabel.lft(\btex\large $-4$ etex, (0,ymin + ty*2)*u);
unfill bbox yl[2];
draw yl[2];
yl[3] = thelabel.lft(\btex\large $-3$ etex, (0,ymin + ty*3)*u);
unfill bbox yl[3];
draw yl[3];
yl[4] = thelabel.lft(\btex\large $-2$ etex, (0,ymin + ty*4)*u);
unfill bbox yl[4];
draw yl[4];
yl[5] = thelabel.lft(\btex\large $-1$ etex, (0,ymin + ty*5)*u);
unfill bbox yl[5];
draw yl[5];
yl[6] = thelabel.lft(\btex\large $1$ etex, (0,ymin + ty*7)*u);
unfill bbox yl[6];
draw yl[6];
yl[7] = thelabel.lft(\btex\large $2$ etex, (0,ymin + ty*8)*u);
unfill bbox yl[7];
draw yl[7];
yl[8] = thelabel.lft(\btex\large $3$ etex, (0,ymin + ty*9)*u);
unfill bbox yl[8];
draw yl[8];
yl[9] = thelabel.lft(\btex\large $4$ etex, (0,ymin + ty*10)*u);
unfill bbox yl[9];
draw yl[9];
yl[10] = thelabel.lft(\btex\large $5$ etex, (0,ymin + ty*11)*u);
unfill bbox yl[10];
draw yl[10];
yl[11] = thelabel.lft(\btex\large $6$ etex, (0,ymin + ty*12)*u);
unfill bbox yl[11];
draw yl[11];
%%%% Place the labels
if ((xmax-xmin)*(ymax-ymin) > 99):
label.top(\btex {\Large $ x $} etex, (xmax*u+1.125*(24/64)*v,1.125(4/64)*v));
label.rt (\btex {\Large $ y $} etex, (1.125*(4/64)*v,ymax*u+1.125*(24/64)*v));
else:
label.top(\btex {\large $ x $} etex, (xmax*u+(24/64)*v,(4/64)*v));
label.rt (\btex {\large $ y $} etex, ((4/64)*v,ymax*u+(24/64)*v));
fi;
pickup pencircle scaled (axeswidth*1.0pt);
drawdblarrow (0,ymin-ahpos*ahlen)*u--(0,ymax+ahpos*ahlen)*u;
drawdblarrow (xmin-ahpos*ahlen,0)*u--(xmax+ahpos*ahlen,0)*u;
solidcircle((-5,4)*u,0.15*u,black);
solidcircle((-4,-2)*u,0.15*u,black);
solidcircle((-3,3)*u,0.15*u,black);
solidcircle((-2,-4)*u,0.15*u,black);
solidcircle((-1,2)*u,0.15*u,black);
solidcircle((2,-3)*u,0.15*u,black);
solidcircle((1,5)*u,0.15*u,black);
solidcircle((2,3)*u,0.15*u,black);
solidcircle((3,4)*u,0.15*u,black);
solidcircle((4,5)*u,0.15*u,black);
\end{mpost}
\usempost[width=3in]{1a}
\end{document}
答案1
给定的代码绝不有效:我尝试使用 2015 至 2019 年的 TeX Live 发行版,但总是出现相同的错误。
.mp
写出的文件显示
def opencircle(expr z, d, rgb) = begingroupsave p;
path p;
background=white;
p = fullcircle scaled (2.3333*d) shifted (z);
fill p withcolor background;
draw p withcolor (rgb) withpen currentpen scaled 0.5;
endgroupenddef;
这当然是错误的。请记住,使用 TeX 约定gmp
读取环境mpost
在,以便进行宏扩展。因此,和%
后面的符号隐藏了结束线,输出为begingroup
endgroup
begingroupsave
这当然是错误的。您可以在 Metapost 代码片段中添加注释,但请确保注释前面有一个空格,%
或者注释单独成一行。Metapost 本质上会忽略换行符,换行符只会被转换为空格。
删除错误的%
字符即可得到预期的结果。