# tikzscale and \tikzsetnextfilename do not work together

\tikzsetnextfilename does not work with tikzscale package. In the MWE, included file is A.tikz which should produce A.pdf. MWE works if tikzscale is not used.

MWE:

\documentclass{report}
\usepackage{tikz,tikzscale}
\usetikzlibrary{external}
\tikzexternalize
%
\begin{filecontents}{A.tikz}
\begin{tikzpicture}
\draw (0,0) rectangle (2,2);
\end{tikzpicture}
\end{filecontents}
%
\begin{document}
\newcommand{\figFilename}{}
\renewcommand{\figFilename}{A}
\tikzsetnextfilename{\figFilename}
%\input{\figFilename.tikz}
\includegraphics[width=\linewidth]{\figFilename.tikz}
\end{document}

• @cyberSingularity main-figure0.pdf is created instead of A.pdf. I am using tex-live 2012 updated yesterday. – devendra Dec 19 '12 at 0:04
• Sorry, you are right. I hadn't checked carefully enough. It seems to be that calling \tikzexternalgetnextfilename (as the tikzscale package does) actually unsets the next filename. Perhaps a bug in tikz. Adding the following to the preamble fixes it: \let\oldtikzexternalgetnextfilename\tikzexternalgetnextfilename \renewcommand{\tikzexternalgetnextfilename}[1]{\oldtikzexternalgetnextfilename{#1}\expandafter\tikzsetnextfilename\expandafter{#1}} – cyberSingularity Dec 19 '12 at 0:37
• Actually, this seems to be the intended behaviour of \tikzexternalgetnextfilename. But probably tikzscale isn't aware of it, especially as I haven't found any documentation of the macro in tikz. So one probably shouldn't patch that macro, but the tikzscale package should restore the filename after querying it? Perhaps contact the package author? – cyberSingularity Dec 19 '12 at 0:54
• @cyberSingularity Will do that. – devendra Dec 19 '12 at 1:33
• @cyberSingularity, thank you both for your findings and suggestions. Unfortunately, at the moment either the file name setting or a test in the test-suite is broken (when the suggested workaround above is implemented), I cannot get both working at the same time. So instead adding a regression, I want to wait for Christian's answer, whom I contacted. My suggestion is, that he adds a macro \pgfexternalreadnextdpth, which encapsulates the behaviour so that tikzscale does not have to call the problematic \tikzexternalgetnextfilename at all. – Patrick Häcker Dec 19 '12 at 22:24

• @PatrickHäcker I used the new PGF release where the bug is fixed. However, the figures keep compiling in each run of LaTeX. seems that the PDFs generated by externalization are being recompiled. What is the way to fix this? – M.Reza Jun 30 '14 at 5:16