summaryrefslogtreecommitdiff
path: root/tex/context/base/m-pstricks.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
committerMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
commit85b7bc695629926641c7cb752fd478adfdf374f3 (patch)
tree80293f5aaa7b95a500a78392c39688d8ee7a32fc /tex/context/base/m-pstricks.lua
downloadcontext-85b7bc695629926641c7cb752fd478adfdf374f3.tar.gz
stable 2010-05-24 13:10
Diffstat (limited to 'tex/context/base/m-pstricks.lua')
-rw-r--r--tex/context/base/m-pstricks.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/tex/context/base/m-pstricks.lua b/tex/context/base/m-pstricks.lua
new file mode 100644
index 000000000..35cae93f6
--- /dev/null
+++ b/tex/context/base/m-pstricks.lua
@@ -0,0 +1,73 @@
+if not modules then modules = { } end modules ['m-pstricks'] = {
+ version = 1.001,
+ comment = "companion to m-pstricks.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- The following will be done when I need ps tricks figures
+-- in large quantities:
+--
+-- + hash graphics and only process them once
+-- + save md5 checksums in tuc file
+--
+-- It's no big deal but has a low priority.
+
+local format, lower, concat, gmatch = string.format, string.lower, table.concat, string.gmatch
+local variables = interfaces.variables
+
+plugins = plugins or { }
+plugins.pstricks = plugins.pstricks or { }
+
+local template = [[
+\starttext
+ \pushcatcodetable
+ \setcatcodetable\texcatcodes
+ \usemodule[pstric]
+ %s
+ \popcatcodetable
+ \startTEXpage
+ \hbox\bgroup
+ \ignorespaces
+ %s
+ \removeunwantedspaces
+ \egroup
+ \obeydepth %% temp hack as we need to figure this out
+ \stopTEXpage
+\stoptext
+]]
+
+local modules = { }
+local graphics = 0
+
+function plugins.pstricks.usemodule(names)
+ for name in gmatch(names,"([^%s,]+)") do
+ modules[#modules+1] = format([[\readfile{%s}{}{}]],name)
+ end
+end
+
+function plugins.pstricks.process(n)
+ graphics = graphics + 1
+ local name = string.format("%s-pstricks-%04i",tex.jobname,graphics)
+ local data = buffers.collect("def-"..n)
+ local tmpfile = name .. ".tmp"
+ local epsfile = name .. ".ps"
+ local pdffile = name .. ".pdf"
+ local modules = concat(modules,"\n")
+ os.remove(epsfile)
+ os.remove(pdffile)
+ io.savedata(tmpfile,format(template,modules,data))
+ os.execute(format("mtxrun --script texexec %s --once --dvips",tmpfile))
+ if lfs.isfile(epsfile) then
+ os.execute(format("ps2pdf %s %s",epsfile,pdffile))
+ -- todo: direct call but not now
+ if lfs.isfile(pdffile) then
+ context.externalfigure( { pdffile }, { object = variables.no } )
+ else
+ logs.report("plugins","pstricks run failed, no pdf file")
+ end
+ else
+ logs.report("plugins","pstricks run failed, no ps file")
+ end
+end