Hi Olivier, Olivier wrote:
Btw: could you add in the doc a simple example of how to set up an mplib instance (loading the format file) and typesetting a minimal graphic, and then use it from within plain TeX for instance; this is transparent to conTeXt users since there are files like mlib-run.lua but not easy for plain TeX users :P
Running mplib is easy enough to document, but that is only a part of the work: you also have to convert the image to pdf literals, and that is more work than I would like to put in the manual. Anyway, attached is a bunch of definitions I stripped out of context that will allow you to run mplib in plain tex provided that you also have context installed (you need mlib-pdf.lua for the PDF conversion) Best wishes, Taco metapost = (metapost or {}) function metapost.report (a) print ("\n" .. a) end function metapost.finder (name, mode, ftype) return (mode=="w" and name) or kpse.find_file(name, ftype) end function metapost.make(name, target, finder) local status = 2 -- higher numbers are errors finder = (finder or metapost.finder) local mpx = mplib.new ( { hash_size = 100000, main_memory = 2000000, max_in_open = 50, param_size = 100000, ini_version = true, find_file = finder, job_name = target, } ) if mpx then local result = mpx:execute("input " .. name .. "; dump;") if result then status = result.status end mpx:finish() end if status < 2 then metapost.report('mp message: created mem file ' .. target ) else metapost.report('mp error: mem file generation failed') end end function metapost.load(name, finder) finder = (finder or metapost.finder) local memname = finder("mplib-" .. name,"r","mem") if not memname then memname = finder("mplib-" .. name, "w", "mem") metapost.make(name, memname, finder) end metapost.report('mp message: using mem file ' .. memname) local mpx = mplib.new ( { ini_version = false, mem_name = memname, find_file = finder, } ) if not mpx then metapost.report('mp error: mem loading failed') end return mpx end function metapost.process(mpx, data) local result if mpx and data then result = mpx:execute(data) -- todo: error message if not result then metapost.report("mp error: no result object returned") elseif result.status > 0 then metapost.report("mp error:" .. (result.term or "no-term") .. "\n" .. (result.error or "no-error")) end end return result end