Yes, fortunately it is! And it is even quite easy.
For this Christian has created a library called
external which has made it into the
tikz package and is accessible through that package.
Whatever, is shown below also works for
pgfplots as they are typeset within a
What it does is, the following:
Check if an image file corresponding to the currently reached image is found:
- If image found insert the image and do nothing more (without checking for changing in the code)
- If image is not found do the following:
- Invoke a new shell with your executable and create the image
- Insert image in the document
This means that for each image that is externalized you will get a new compiled document with additional log, aux files etc. I.e. many new files.
A most basic example is to do the following:
% Load the library
% Enable the library !!!>>> MUST be in the preamble <<<!!!!
\draw (0,0) -- (1,1);
This will create one additional file called
<document name>-figure0.pdf. Which is the first occurring
tikzpicture environment in the file.
This has the disadvantage of reading the
0 file even if you rearrange your
For this there is a command:
\tikzsetnextfilename which can be used to force the following
tikzpicture environment to a specific file name.
This ensures the correct loading order of the figures. I would encourage you to do this on each picture.
So for instance this:
% Default the externalized name to 'hello'
\draw[red] (0,0) -- (-1,1);
external library creates the images within the current directory. This means that you will have a very cluttered folder of many files (as it compiles many sub documents only containing the images).
A common way to bypass this is to add a prefixed directory to the output of the files. You do that by the command:
\tikzsetexternalprefix which is pretty self-explanatory. So a small example:
% Load the library
% Enable the library
% Default all images in the subfolder `figs/`
\draw[green] (0,0) -- (1,-1);
% You are allowed to rearrange your images to separate folders
\draw[red] (0,0) -- (1,-1);
\draw[blue] (0,0) -- (1,-1);
This can thus also be used to sort your images by chapter, or style, or etc..... :)
Otherwise search for the
external tag here, or see the manual.
In general it is always a good custom to delete all your externalised images before doing your final compilation. This ensures that images are updated etc.