I am preparing a thesis in the same manner as detailed in this question.
Namely, I am looking to write a thesis with the text appearing on the right (odd) page, and images appearing on the left (even) page.
The answer provided to the previous question works as desired for all images. However, if I use a tikzpicture environment and well as the externalization library I receive the following error:
Package tikz Error: Sorry, the system call 'pdflatex -shell-escape
-halt-on-error -interaction=batchmode -jobname "main-figure0"
"\def\tikzexternalrealjob{main}\input{main}"' did NOT result in a
usable output file 'main-figure0'
The externalization will work as long as the tikz code is not included in the provided insertpic command. However, then all the images will always appear on the right-hand page, which is not desired.
From my basic understanding of TeX, I believe the source of the error may be to do with the way the insertpic command seems to be collecting up the images before shipping them out, which I assume is somehow conflicting with the externalization library.
My question is then, is there any way to use the insertpic command and the externalization library together?
MWE
\documentclass[oneside]{book}
% See: <https://tex.stackexchange.com/questions/96343/>
\makeatletter
\def\@oddhead{ODD PAGE\hfill\thepage}
\long\def\grabfirst#1#2\@@{\toks@{#2}\xdef\insertlist{\the\toks@}#1}
\let\old@outputpage\@outputpage
\def\@outputpage{%
\ifx\insertlist\@empty
\shipout\vbox to\@colht {\vss}%
\else
\begingroup
\setbox\@outputbox\vbox to\@colht {%
\expandafter\grabfirst\insertlist\@@
}%
\def\@oddhead{\thepage A \hfill EVEN PAGE}
\old@outputpage
\addtocounter{page}{-1}%
\endgroup
\fi
\old@outputpage}
\gdef\insertlist{}
\long\def\insertpic#1{\g@addto@macro\insertlist{{#1}}}
\makeatother
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
Some text here.
A figure will be on the facing page.
\insertpic{
\begin{tikzpicture}
\draw[red] (0,0) -- (1,1);
\end{tikzpicture}
}
\end{document}