The following is based on this note by Michael Goerz. There are a few steps:
-
In a latex file say
fig-generator.tex
make yourtikzpicture
(call it by any name, here we usefig-name
) inside apgfgraphicnamed
environment as follows:\beginpgfgraphicnamed{fig-name} \begin{tikzpicture} ... ; \end{tikzpicture} \endpgfgraphicnamed
-
Next, we compile the latex to create a
fig-name.dvi
filelatex --jobname=fig-name fig-generator.tex
-
Now we convert the
dvi
file to aneps
file:dvips -o fig-name.eps fig-name.dvi
-
Sometimes you will need a
ps
file instead of aneps
file and a simple hack is to just change the file extension usingmv
(if you want to keep theeps
file usecp
instead ofmv
)mv fig-name.eps fig-name.ps
-
In the
tex
file where you intend to use theps
figure add the following in the header:\usepackage{auto-pst-pdf}
. You may have to add the-shell-escape
argument to thelatexmk
command when compiling thetex
file where you use the figure. If using VS Code this stackoverflow thread explains how to add shell escape argument tolatexmk
.