metapost

Is it possible to include one MetaPost file into another?


I have two metapost files:

% test1.mp
beginfig(1):

% foobar code

% code specific to test1

endfig;
end;

% test2.mp
beginfig(1):

% foobar code    

% code specific to test2

endfig;
end;

As a programmer, I naturally hate duplication. Is there a way of moving the "foobar code" into a foobar.mp file, and then including this file in both test1.mp and test2.mp? For example...

% test1.mp
beginfig(1):

% for illustration...
Include.foobar("foobar.mp");

% code specific to test2

endfig;
end;

Solution

  • % test1.mp
    beginfig(1):
    input foobar
    endfig;
    end;