I think the most straightforward way to do this is not to set prefix
at all but to instead do two things.
Ensure that --output-directory
is passed to the compiler when it is run by the externalisation process by overriding the default compilation command.
- This should ensure that all files generated when producing the externalised images are written to
build/
and not only those directly concerned with externalisation.
Ensure that TikZ searches in the correct place for the externalised images by overriding the default image inclusion command.
- This should ensure TeX looks in the correct place for the externalised images by directly manipulating the path used when including images rather than by setting
prefix
. prefix
won't work here because it will also be used when externalising, creating an unwanted cumulative effect when producing images (build/build/<image>
) but not when including them (build/<image>
), resulting in errors.
For example, you might want something like this (based on the information in your question and the default explained on page 609 of the TikZ manual and the information on page 616):
\begin{filecontents}{\jobname.bib}
@article{author-art,
author = {Author, A. N.},
title = {Believe It or Not \dots},
volume = 290,
year = 3056,
doi = {44.897/gje.x789},
pages = {x789},
eprinttype = {gje},
eprint = {x789},
eprintclass = {290},
journal = {Greatest Journal Ever}}
@article{author-anart,
author = {Author, A. N.},
title = {Suppose It or Not \dots},
volume = 78,
number = 3,
year = 3049,
pages = {22--29},
eprinttype = {jstor},
eprint = {12980258},
journal = {Second Best Journal Ever}}
\end{filecontents}
\documentclass[british]{article}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber]{biblatex}
\bibliography{\jobname}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{%
external/system call={pdflatex \tikzexternalcheckshellescape --halt-on-error --interaction=batchmode --output-directory=./build --jobname "\image" "\texsource"},
/pgf/images/include external/.code={%
\includegraphics{build/#1}%
},
}
\begin{document}
\Textcite{author-art,author-anart}
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\end{tikzpicture}
\printbibliography
\end{document}
I then compiled with
pdflatex --shell-escape --output-directory=./build <filename>.tex
biber --output-directory=./build <filename>
pdflatex --shell-escape --output-directory=./build <filename>.tex
This generated all files in build/
and seemed to compile successfully, using the externalised image rather than recompiling the TikZ code on the second run.
