# Tikz externalize error when using tikzducks

I am using tikzducks for my footers, simply because I think they are brilliant. Because my document contains lots of other tikzpictures, I want to make use of \tikzexternalize. This works perfectly fine if I do not use the tikzducks. With the tikzducks, the tikzexternalize fails when generating the final duck. A simple solution would be to disable the tikzducks. But yeah... a report without a duck, that's a bridge too far. So could anyone help me out?

My MWE (document.tex):

\documentclass{article}
\usepackage{lipsum}                             %5 generate lorum ipsum text
\usepackage{fancyhdr}                           %% page headers and footers
\usepackage{tikzducks}                          %% ducks with tikz

\pagestyle{fancy}                               %% set page style

\usetikzlibrary{external}                       %% Create pdf figures from TikZ. Use PDFTeXify ...
\tikzexternalize[prefix=tikz/]                  %% ... with --tex-option=--shell-escape switch.

\begin{document}

\lipsum[1-10]

\end{document}


I use the following code for compilation:

pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape "document".tex


I get the following error:

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "tikz/document-figure1" "\def\tikzexternal
realjob{document}\input{document}"' did NOT result in a usable output file 'tik
z/document-figure1' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that
you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'.
Sometimes it is also named 'write 18' or something like that. Or maybe the com
mand simply failed? Error messages can be found in 'tikz/document-figure1.log'.
If you continue now, I'll try to typeset the picture.


This is what the log file says:

! Package tikz Error: Sorry, image externalization failed: the resulting image
was EMPTY. I tried to externalize 'tikz/document-figure1', but it seems there i
s no such image in the document!?
You are currently using 'mode=convert with system call'. This problem can ha
ppen if the image (or one of the images preceeding it) was declared inside of a
\label{} (i.e. in the .aux file): 'convert with system call' has no access to
the main aux file.
Possible solutions in this case:
(a) Try using 'mode=list and make',
(b) Issue the externalization command 'pdflatex -shell-escape -halt-on-error
-interaction=batchmode -jobname "tikz/document-figure1" "\def\tikzexternalreal
job{document}\input{document}"' *manually* (also check the preceeding externali
zed images, perhaps the file name sequence is not correct).
Repeat: the resulting image was EMPTY, your attention is required .

• Why don't you just disable externalisation before the last duck? Also, as the message you posted says: the details are in the file the message refers you to and which you can read, but we can't. – cfr Mar 7 '18 at 4:09
• That sounds as a solution. How can I do that? I added the error message in the log file (thanks for suggesting this) – EdG Mar 7 '18 at 4:10
• \tikzexternaldisable is sometimes enough, but sometimes I find I need \tikzset{external/export=false}, though I'm not sure why. – cfr Mar 7 '18 at 4:12
• Are you sure that the problem comes from tikzducks? Or may it be related to this question? (I'm just guessing, and the fix proposed here does not solve the problem.) – user121799 Mar 7 '18 at 7:49
• It is not related to tikzducks, you get the same problem with an arbitrary \tikz picture in the footer. – Ulrike Fischer Mar 7 '18 at 8:12

The log file says:

This problem can happen if the image (or one of the images preceeding it) was declared inside of a \label{} (i.e. in the .aux file)...

Could it be that the footer at the last page is inside a label{}? Because the error only appears at the last page. Since one can refer to the last page using the reference key LastPage, I think this might be the case.

Edit: based on a comment below, this is not the case. Nevertheless, we "are in the middle of the output routine and one should not do complicated things like externalization there".

Anyway, since the tikzducks do not have a big influence on the compilation of the document, it is not very important to "tikzexternalize" the ducks. I found the following workaround for the footer (based on the comment of cfr):

\fancyfoot[C]{%
\tikzset{external/export=false}