# TikZ & External: figure re-created for no apparent reason

I'm having an issue where only one out of multiple figures is recreated despite the use of the tikz/external library. I've created a MWE which shows the same effect with only two figures.

Below is my main file which is compiled with pdflatex -shell-escape file.

\documentclass{article}

\usepackage{tikz,pgfplots,tikzscale}
\usetikzlibrary{external}
\tikzexternalize[prefix=figures/]
\graphicspath{ {./figures/}{./figures-tikz/} }

\newcommand{\figFilename}{}

\begin{document}
\begin{figure}[t!]
\renewcommand{\figFilename}{scalability-plot-all-sbb-2-optima}
\centering
\tikzpicturedependsonfile{\figFilename.tikz}
\tikzsetnextfilename{\figFilename}
\includegraphics[width=\textwidth,axisratio=1]{\figFilename.tikz}
\caption{Scalability plot for dDE, MPC, dDE$^-$ and a hill climber on the Scalable-Building-Block problem.}
\label{fig:\figFilename}
\end{figure}

\begin{figure}[t!]
\renewcommand{\figFilename}{scalability-plot-all-sbb-2-optima-log-y}
\centering
\tikzpicturedependsonfile{\figFilename.tikz}
\tikzsetnextfilename{\figFilename}
\includegraphics[width=\textwidth,axisratio=1]{\figFilename.tikz}
\caption{Same as in Figure~\ref{fig:scalability-plot-all-sbb-2-optima}, but y axis is in logscale.}
\label{fig:\figFilename}
\end{figure}
\end{document}


The first figure is re-created every time I run pdflatex. I tried changing the ordering of the two, but it does not make a difference --- the figure with the filename scalability-plot-all-sbb-2-optima is the one that's always re-created even though the other figure is identical but with a semilogyaxis instead. The TikZ files for both are merely five addplot commands which load data from five different .dat files. Showing everything here would take up a lot of space, so here's a link to the whole directory structure, including the .tex, .tikz and .dat files.

I've found that if I keep only one addplot, the figure is not re-created. I was wondering whether this is a bug, whether LaTeX is confused by my directory structure, or whether it's simply a mistake on my part.

-
Is this really a MWE, do you need all those packages to reproduce the problem? –  Miguel de Val-Borro Jul 14 '13 at 18:35
I left it this way in case there was a package incompatibility issue. –  sudosensei Jul 14 '13 at 19:29

With my very limited LaTeX knowledge, I decided to inspect the log file (file.log) to try to identify what went wrong. I noticed that right after the convert command that causes the picture to be re-generated, there was an error of this sort:
Overfull \hbox (17.03157pt too wide) in paragraph at lines 1--76

This led me to believe that tikzscale was not capable of scaling the picture to the exact size I requested, and this caused a mismatch between what tikzscale thought the size of the picture was and what it actually was. So what I did was follow the instructions listed in this answer to remove the whitespace from around the x and y labels (basically try to help tikzscale).
The problem is now fixed. The Overfull \hbox warning no longer appears and the picture is not re-generated every time. I do not know whether this is the expected behaviour or whether this is a bug though.