@@ -0,0 +1,67 @@
4+Pandoc filter to process raw latex tikz environments into images.
5+Assumes that pdflatex is in the path, and that the standalone
6+package is available. Also assumes that ImageMagick's convert
7+is in the path. Images are put in the tikz-images directory.
15+from pandoc import toJSONFilter
16+from subprocess import Popen, PIPE, call
17+from tempfile import mkdtemp
19+imagedir = "tikz-images"
22+ return hashlib.sha1(x).hexdigest()
24+def tikz2image(tikz, filetype, outfile):
28+ f = open('tikz.tex', 'w')
29+ f.write("""\\documentclass{standalone}
34+ f.write("\n\\end{document}\n")
36+ p = call(["pdflatex", 'tikz.tex'], stdout=sys.stderr)
38+ if filetype == 'pdf':
39+ shutil.copyfile(tmpdir + '/tikz.pdf', outfile + '.pdf')
41+ call(["convert", tmpdir + '/tikz.pdf', outfile + '.' + filetype])
42+ shutil.rmtree(tmpdir)
44+def tikz(key, value, format):
45+ if key == 'RawBlock':
47+ if fmt['unFormat'] == "latex" and re.match("\\\\begin{tikzpicture}", code):
48+ outfile = imagedir + '/' + sha1(code)
51+ elif format == "latex":
55+ src = outfile + '.' + filetype
56+ if not os.path.isfile(src):
59+ sys.stderr.write('Created directory ' + imagedir + '\n')
62+ tikz2image(code, filetype, outfile)
63+ sys.stderr.write('Created image ' + src + '\n')
64+ return {'Para': [{'Image': [[], [src,""]]}]}
66+if __name__ == "__main__":