Question

I'm trying to plot a simple graphic by MetaPost ,which comes along with the TexLive2013.iso .The code listed below is supposed to create an oval with some label .

beginfig(1);
a=.7in; b=.5in;
z0=(0,0);
z1=-z3=(a,0);
z2=-z4=(0,b);
draw z1..z2..z3..z4..cycle;
draw z1--z0--z2;
label.top("a", .5[z0,z1]);
label.lft("b", .5[z0,z2]);
dotlabel.bot("(0,0)", z0);
endfig;
end;

Howerver,when I opened the output flie 5.1 with okular ,it was blank.I opened the output file again with kate,listed below is the code:

%!PS
%%BoundingBox: -51 -37 51 37 
%%HiResBoundingBox: -50.64978 -36.25 50.64978 36.25 
%%Creator: MetaPost 1.802
%%CreationDate: 2013.09.08:1009
%%Pages: 1
%*Font: cmr10 9.96265 9.96265 61:8
%%BeginProlog
%%EndProlog
%%Page: 1 1
0 0 0 setrgbcolor 0 0.5 dtransform truncate idtransform setlinewidth pop
[] 0 setdash 1 setlinejoin 10 setmiterlimit
newpath 50.39978 0 moveto
50.39978 23.04858 25.56044 36 0 36 curveto
-25.56044 36 -50.39978 23.04858 -50.39978 0 curveto
-50.39978 -23.04858 -25.56044 -36 0 -36 curveto
25.56044 -36 50.39978 -23.04858 50.39978 0 curveto closepath stroke
1 setlinecap
newpath 50.39978 0 moveto
0 0 lineto
0 36 lineto stroke
22.70921 3 moveto
(a) cmr10 9.96265 fshow
showpage
%%EOF

If I comment

label.top("a", .5[z0,z1]);
label.lft("b", .5[z0,z2]);
dotlabel.bot("(0,0)", z0);

Then an oval without label can be seen.For all the codes above,MetaPost did not give any warning or error message.So the question is:

  1. Why did my MetaPost output an empty graphic when using label ?
  2. How to fix it ?
Was it helpful?

Solution

Quoting the MetaPost manual, chapter 3 (The MetaPost Workflow):

If your graphics contain text labels, you might want to set variable prologues to 3 to make sure the correct fonts are used under all possible circumstances.

So, I added the following as the first line of your code:

prologues := 3;

What it essentially does here is embed the font into the output, which grows to ~20 Kbytes as a result.

After that, I can see the picture with labels in GSview. Without that, it complains like Error: /undefined in cmr10. Perhaps okular also had trouble locating fonts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top