[Tex/LaTex] Error using tikz externalize: can’t write md5 file

pgfplotstikz-externaltikz-pgf

I tried to use the externalize library. It worked fine when all my files where located in the same folder. Usually I am using a subfolder as build folder, where all generated files should be stored. Setting this up with the prefix for externalize, I get an error message that seems to me weird.

What am I doing wrong?

Here is a MWE that throws the error message ! I can't write on file `build/Test-figure0.md5'

I am using TexStudio and Texlive 2014. To compile I use the command:

pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape -output-directory=build %.tex

Here is a not working example:

\documentclass[english]{scrbook}

\usepackage{tikz} 
\usepackage{pgfplots}

\pgfplotsset{compat=newest}
\usepgfplotslibrary{external} 
\tikzset{external/up to date check={md5}}
\tikzset{external/mode=convert with system call} 
\tikzexternalize 
\tikzsetexternalprefix{build/}

\begin{document}

\usetikzlibrary{arrows}
\tikzstyle{myedgestyle} = [diamond-open diamond]
\begin{tikzpicture}

\node (v2) at (2,4) {};
\node (v1) at (-0.5,2) {};
\draw [diamond-open diamond] (v1) edge (v2);
\end{tikzpicture}

\end{document}

Until now I tried the following things:

  1. Try to run it without the prefix

It works, but all the files will be created in the main folder

  1. Using \tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -output-directory=build -interaction=batchmode -jobname "\image" "\texsource"}} without the prefix option to change the build location

It creates the pictures in the build directory but I will get this error: ===== Image 'Test-figure0' is up-to-date. ====== !pdfTeX error: pdflatex.exe (file Test-figure0.pdf): cannot find image file ==> Fatal error occurred, no output PDF file produced! –

  1. Using the former \tikzset and the prefix option together I will get the md5 massage again, if the picture wasn't created before. If I am not using the prefix option within the first run, the picture will be created in the build folder. Switching the prefix option back on in a second run it will generate no errors and use the previously generated pictures.

I think that this is a pretty dirty workaround. Is there a better solution?

  1. Changing the folder for the tikz pictures does not make any difference.

  2. Runing the example in draft mode and tikzset and prefix set will run with no errors, but the pictureboxes have a standard size.

Best Answer

Your issue occurs because you are using the flag -output-directory=build when running pdflatex.


In order to makes explanations less ambiguous, let's rename folders:

  • you are using the flag -output-directory=foo;
  • your .tex file is in a folder named root;
  • you are using following macro in your .tex file: \tikzexternalize[prefix=bar/].

What happens is that the externalization creates .pdf (as well as .log and .dpth files) in the folder root/bar/. However, the externalization also creates "output files" (actually .md5) and thus stores them into... root/foo/bar.

The error is raised because the folder root/foo/bar doesn't exist on your computer (you only have created root/bar). Creating it should solve the problem.