I am currently updating an illustrated dictionary of mathematical concepts. It includes a lot of 3D graphs and I knew that the compilation time was going to increase drastically if just leave the source code and generate them all each time the document is compiled.
So my solution was this:
I created a separate tex file, called "DrawTest.tex" in order to write the source code for the graphs and figures that are to be included in the dictionary. Once I am satisfied with the way the figure looks like, I generate two files: a PDF with the figure and a source code file without the preamble and the \end{document}
line. Both files have to have the same name. And by means of the following instruction:
%
% Instruction to decide if a PDF has to be added
% or the corresponding source code
%
\newcounter{final}
\setcounter{final}{0}
\newcommand{\insertfigure}[1]{
\ifthenelse{\thefinal=1}{\input{./source/#1}}{\pgfimage{./gallery/#1.pdf}}
}
when I create the PDF corresponding to the draft of the dictionary, the PDF files are inserted as images. When I am done with the whole document (i.e., when I finish the dictionary), the last time I am going to generate it, I just need to switch the value of the counter final
, (I usually change it to zero) and the figures are generated from its latex source code.
From the previous code, it goes without saying that the tex files are saved into a folder called "source" and the PDF's are located at the folder named "gallery".
The source code for the file "DrawTest.tex" is something like:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{math}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0.1pt}
%
\begin{document}
%
\begin{center}
%
\begin{tikzpicture}
% Include here the lines of code for the figure.
\end{tikzpicture}
\end{center}
%
\end{document}
Generate the PDF file for the figure, and copy the PDF into the folder "gallery".
And from that code, just delete the preamble, including the \begin{document}
line, together with the last line, including the \end{document}
instruction, and that is the file that is needed in the folder titled "source". Just remember to name both files exactly equal.
This is the way I use to avoid time consumption because of the compilation of the figures.
If anybody comes up with a better approach, I will be glad to copy the strategy.
external
library,standalone
... there are ways to set things up so things are compiled only when necessary (mostly, anyway). But... it all depends. There are surely figures you ought not try to produce using TeX regardless of compilation time ! You have limited accuracy, for example, and extremely limited capacity for 3D rendering. Summary: what @egreg said. – cfr Jul 16 '15 at 22:13