1

I would like a vardef macro to return the pair of a picture and a bounding box. I don't want to use the setbound operator, because as soon as I do that, I cannot access the components of the picture anymore with pathpart.

I found metapost vardef returning multiple values but that is about returning multiple values of the same numeric type. Is it possible to have vardef return a set of (picture, path) or (picture, picture) in some way? If not, I need to make two vardef macros for each result type.

I tried many things, amongst which:

vardef Foo( expr w, h)
% define pic
pic
end group,begingroup
% define pic
pic
endif

picture foo[]; foo = Foo( 2, 4);
1

1 Answer 1

2

If you don't completely ignore all the syntax rules of MetaPost, as you did in your original post, then this works without a problem.

vardef Foo(expr w, h) =
    image (
        draw fullcircle xyscaled(w, h) ;
    )
endgroup, begingroup
    image (
        draw fullsquare xyscaled(w, h) ;
    )
enddef;

beginfig(0) ;
for p := Foo(2cm, 4cm):
    draw p ;
endfor ;
endfig ;

end ;

I'm using the MetaFun format here, so mpost has to be told to load it:

$ mpost -mem=metafun test.mp

enter image description here

2
  • Thanks. This doesn't filly answer my question, as I need to do something like mypic := <firstvalue>; mypth := <secondvalue>, so the for loop will be hard for me to do.
    – gctwnl
    Mar 17, 2020 at 8:05
  • @gctwnl If you had asked a more useful question, you would have received a more useful answer, but I saw that you already got answers on the ConTeXt list. Mar 17, 2020 at 8:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .