I need to save the result of a tikzpicture
to disk in code.
Basically I have written some optimization routines for other things that only create the image if it does not exist on disk. I want to apply the same thing to tikzpictures. I do not want to use externalize(mine is faster and more useful to me).
So, given a tikzpicture:
\begin{tikspicture}[...]
...
\end{tikzpicture}
I need some way to save it to disk as a png or jpg or whatever(png is preferable).
Something like:
\begin{tikspicture}[save=filename,...]
...
\end{tikzpicture}
or
\begin{tikspicture}[...]
...
\end{tikzpicture}
\savelasttikzpicture{filename}
(tikz externalize does not work because it doesn't seem to play nice with lualatex. I have code essentially like this:
\directlua{ drawTikzFig(arg); }
in lua:
function drawTikzFig(arg)
tex.print('\\begin{tikzpicture} ... \\directlua{getValue(arg);} ... \\end{tikzpicture}')
end
In fact, I don't know if this is exactly what is breaking tikz externalize or not but it gives errors at \directlua{}
Thanks
Best Answer
You could use the
preview
package to create a single page from everytikzpicture
environment using the\PreviewEnvironment
(or similar, see the manual) macro. The resulting PDF can then be converted to multiple PNGs if required (but I suggest keeping the diagrams vector graphics!). However, this will only number all images and does not allow you to label them. You will run into trouble if the order or number oftikzpictures
changes.