# TikZ externalized figures render incorrectly when eso-pic is used

I am having some trouble using eso-pic in conjunction with externalised tikz figures. Content added to other document pages using \AddToShipoutPicture*{} is drawn on the TikZ figure. This does not occur when the TikZ figures are compiled in-line.

The following is a minimum working example that results in this error (compile using pdflatex --shell-escape --write18 test.tex)

\documentclass{article}

\usepackage{eso-pic}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{external}
\pgfrealjobname{test}
\tikzexternalize
\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}

\begin{document}
\AddToShipoutPicture*{\put(0,480){\rule{\paperwidth}{2cm}}}
\vfil\null
\newpage

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=1.5]
\begin{axis}[xmin=0,xmax=5,ymin=0,ymax=3]
\draw [ultra thick,gray] (axis cs:0.5,0.5) to[out=80,in=200] (axis cs:1.5,2);
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


It appears that the shipout is not cleared when the TikZ externalise command is executed. Does anyone know how I could clear this in order to render the figures correctly?

## 1 Answer

Ok, I figured out that you can remove the externalized eso-pic calls to \AddToShipoutPicture by adding the option \tikzset{external/optimize command away=\AddToShipoutPicture} to the preamble. This seems to generate figures correctly now, without the eso-pic shipout contents.