diff options
author | Hans Hagen <pragma@wxs.nl> | 2013-12-24 17:52:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2013-12-24 17:52:00 +0100 |
commit | aa4a1c3b114d386a588677f02f9adf7a81229ccf (patch) | |
tree | e917d8e041c043c6d71a6d87d80d8d9ec996a7e8 /tex/context/base/mlib-pps.lua | |
parent | 7782983431dad86a7ee371ea6638b948a599e8c6 (diff) | |
download | context-aa4a1c3b114d386a588677f02f9adf7a81229ccf.tar.gz |
beta 2013.12.24 17:52
Diffstat (limited to 'tex/context/base/mlib-pps.lua')
-rw-r--r-- | tex/context/base/mlib-pps.lua | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/tex/context/base/mlib-pps.lua b/tex/context/base/mlib-pps.lua index 535c9ff9d..865f76018 100644 --- a/tex/context/base/mlib-pps.lua +++ b/tex/context/base/mlib-pps.lua @@ -674,37 +674,48 @@ local start = [[\starttext]] local preamble = [[\def\MPLIBgraphictext#1{\startTEXpage[scale=10000]#1\stopTEXpage}]] local stop = [[\stoptext]] +local mpyfilename = nil + +function makempy.registerfile(filename) + mpyfilename = filename +end + function makempy.processgraphics(graphics) - if #graphics > 0 then - makempy.nofconverted = makempy.nofconverted + 1 - starttiming(makempy) - local mpofile = tex.jobname .. "-mpgraph" - local mpyfile = file.replacesuffix(mpofile,"mpy") - local pdffile = file.replacesuffix(mpofile,"pdf") - local texfile = file.replacesuffix(mpofile,"tex") - io.savedata(texfile, { start, preamble, metapost.tex.get(), concat(graphics,"\n"), stop }, "\n") - local command = format("context --once %s %s", (tex.interactionmode == 0 and "--batchmode") or "", texfile) + if #graphics == 0 then + return + end + if mpyfilename and io.exists(mpyfilename) then + report_metapost("using file: %s",mpyfilename) + return + end + makempy.nofconverted = makempy.nofconverted + 1 + starttiming(makempy) + local mpofile = tex.jobname .. "-mpgraph" + local mpyfile = file.replacesuffix(mpofile,"mpy") + local pdffile = file.replacesuffix(mpofile,"pdf") + local texfile = file.replacesuffix(mpofile,"tex") + io.savedata(texfile, { start, preamble, metapost.tex.get(), concat(graphics,"\n"), stop }, "\n") + local command = format("context --once %s %s", (tex.interactionmode == 0 and "--batchmode") or "", texfile) + os.execute(command) + if io.exists(pdffile) then + command = format("pstoedit -ssp -dt -f mpost %s %s", pdffile, mpyfile) + logs.newline() + report_metapost("running: %s",command) + logs.newline() os.execute(command) - if io.exists(pdffile) then - command = format("pstoedit -ssp -dt -f mpost %s %s", pdffile, mpyfile) - logs.newline() - report_metapost("running: %s",command) - logs.newline() - os.execute(command) + if io.exists(mpyfile) then local result, r = { }, 0 - if io.exists(mpyfile) then - local data = io.loaddata(mpyfile) - if data and #data > 0 then - for figure in gmatch(data,"beginfig(.-)endfig") do - r = r + 1 - result[r] = formatters["begingraphictextfig%sendgraphictextfig ;\n"](figure) - end - io.savedata(mpyfile,concat(result,"")) + local data = io.loaddata(mpyfile) + if data and #data > 0 then + for figure in gmatch(data,"beginfig(.-)endfig") do + r = r + 1 + result[r] = formatters["begingraphictextfig%sendgraphictextfig ;\n"](figure) end + io.savedata(mpyfile,concat(result,"")) end end - stoptiming(makempy) end + stoptiming(makempy) end -- -- the new plugin handler -- -- |