I've come to a philosophical quandary with respect to my use of LaTeX for scientific writeups. At first I tried to render all figures in LaTeX at compile-time, for example making a graph using PGFPlots instead of importing it from Excel. However as I started bigger projects my compile time got exponentially larger, and I heard that many prefer pre-rendered images in figures rather than figures rendered at compile-time. Which is better practice for large projects with many diagrams?
The project I'm working on now includes a couple of graphs and circuit diagrams in circuitikz, for a certain degree of context. I also am considering taking figures designed in LaTeX, exporting them as images, then reimporting them into the final document. Thanks.
Best Answer
standalone
can be set up to recompile included pictures only if required. Otherwise, it will include the previously compiled PDF. So it is not necessary to switch to\includegraphics
to benefit from pre-compilation.Here's a basic example.
The figure:
All that is really necessary here is the
tikzpicture
environment but the rest is handy while working on the image initially andstandalone
will ignore it when appropriate, so it might as well stay.Now the main file:
Provided compilation is done with
-shell-escape
, the following will happen:mytikz.pdf
which will then be included with\includegraphics{}
;\includegraphics{}
unless the source has changed, in which case it will be recompiled first.By altering the value of
mode=
, this behaviour can be customised as required.In all cases, I get a lovely blue cat:
However, you can use it with pictures of other cats, too. Even non-cat content works, or so I've been given to understand.
An alternative is to use the
external
TikZ library to externalise images. Again, this requires-shell-escape
and it can be configured. By default, it also recompiles a figure only if it has changed. However, this is obviously limited to PGF/TikZ pictures whereasstandalone
provides a more generalised approach.