[metapost] Running mpost as a unix daemon?

Dave Crossland dave at lab6.com
Wed Feb 26 04:00:25 CET 2014


On 20 February 2014 18:50, Hans Hagen <pragma at wxs.nl> wrote:
> On 2/20/2014 6:12 PM, Dave Crossland wrote:
>>
>> On 20 February 2014 08:35, Hans Hagen <pragma at wxs.nl> wrote:
>>>
>>> unless you have a limited well known application you still have to
>>> restart
>>> the mp session from scratch as macros can rewrite themselves, variables
>>> can
>>> be set, and one run can influence an upcoming one.
>>
>>
>> We're just using it to calculate glyph outlines with very simple
>> variables, not hand written metafont code, so metaprogramming and
>> inter-run changes won't happen.
>>
>> So we can use LuaTeX's sockets to send in a simple mf description of a
>> glyph, with a preamble setting some variables, and see returned a new
>> glyph with different point co-ordinates, and no start up time cost?
>
>
> yes

So, Frank Trampe (a C developer in USA) looked into the options I
started this thread with, and he said that writing Python bindings for
MPLib's 'main' loop seemed best.

This means instead of
https://github.com/metapolator/metapolator/blob/master/metapolator/views.py#L876
:

    import subprocess
    subprocess.Popen(["mpost", "-progname=mpost", "-ini", "mf2pt1", "\\dump"],
                     cwd=working_dir())

then we can have something like:

    import mpost
    progname = "mpost"
    ini = 1
    something = "mf2pt1"
    mode = "dump"
    args = [progname, ini, something, mode]
    cwd = working_dir()
    mpost(args, cwd)

Frank found the Metapost build system to be a bit more cryptic than he
had expected, and adding a library target is not as simple as adding a
line to a Makefile.

However, in https://www.tug.org/TUGboat/tb29-3/tb93hoekwater.pdf there is this:

- - - - - - - - 8< - - - - - - - -
4.1 Examples

Here is a minimalistic but complete example that uses the mpost
emulation method in C code:

#include <stdlib.h>
#include "mplib.h"
int main (int argc, char **argv) {
  MP mp;
  MP_options *opt = mp_options();
  opt->command_line = argv[1];
  mp = mp_initialize(opt);
  if (mp) {

     int history = mp_run(mp);
     mp_finish(mp);
     exit (history);

  } else {
     exit (EXIT_FAILURE);
  }
}
- - - - - - - - 8< - - - - - - - -

so Frank will make a new python binding based on that example, and
offer it to Taco, Hans and Luigi to consider taking upstream, since
you good folks are more familiar with the Makefile layout :)

Any comments welcome! :)

-- 
Cheers
Dave



More information about the metapost mailing list