2

I have a metapost file image.mp containing the following lines:

beginfig(0);
draw p0; 
externalfigure "/Users/dsg/tex/images/image.png" xyscaled r0 shifted r1; 
endfig;

When I run mptopdf scene.mp I get the following error:

MPtoPDF 1.4.1 : running 'mpost --mem=mpost   --tex=latex  scene.mp'
This is MetaPost, version 1.504 (kpathsea version 6.1.0)
(mpost.mp (/opt/local/share/texmf-texlive-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.004)) (./scene.mp
>> externalfigure
! Isolated expression.
<to be read again> 
                   "/Users/dsg/tex/images/image.png"
l.421 ...tex/images/image.png"
                                                   xyscaled r0 shifted r1;

I think it is being caused the new version of metapost on my new computer because this same file used to work on my old computer.

I'm not sure how to fix it. I've tried changing it to:

beginfig(0);
draw p0; 
draw externalfigure "/Users/dsg/tex/images/image.png" xyscaled r0 shifted r1; 
endfig;

But then I get:

MPtoPDF 1.4.1 : running 'mpost --mem=mpost   --tex=latex  scene.mp'
This is MetaPost, version 1.504 (kpathsea version 6.1.0)
(mpost.mp (/opt/local/share/texmf-texlive-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.004)) (./scene.mp
>> externalfigure
! Improper `addto'.
<to be read again> 
                   withpen
draw->...:also(EXPR0)else:doublepath(EXPR0)withpen
                                                  .currentpen.fi._op_
<to be read again> 
                   "/Users/dsg/tex/images/image.png"
l.421 ...images/image.png"
                                                   xyscaled r0 shifted r1;

(EDIT: added beginfig(0);)

SOLVED: you do not need draw externalfigure ... just externalfigure ..., but as @egreg put it, you need to run mptopdf -metafun

  • 1
    Could you please add a complete example, from beginfig to endfig? – egreg Feb 16 '13 at 22:03
  • 2
    Are you sure it is draw externalfigure and not only externalfigure? And are you running mptopdf -metafun? – egreg Feb 16 '13 at 22:12
  • Thanks @egreg, I was not running with the -metafun flag. It now works. – dsg Feb 16 '13 at 22:19
3

You have to announce the Metapost format you want to use (your log shows you're using the default plain.mp, also known as mpost.mp). So the call should be

mptopdf -metafun file

(see the man page at Contextgarden)

According to the documentation, it's just

externalfigure "file" ...;

not with draw in front. You find something in the section "Including graphics" of the Metafun manual, pages 350ff.

| improve this answer | |
  • Can you add a link to the documentation? – dsg Feb 16 '13 at 22:34
  • This answer might be outdated. At least nowadays externalfigure returns a picture, so you need to use draw with it. – Henri Menke May 24 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.