1

tikzexternalize works fine until I use the annotationimage environment (which itself doesn't work without disabling externalisation, for whatever reason):

\RequirePackage{mwe}
\documentclass{article}

\usepackage{graphicx}

\usepackage{tikz,pgfplots,tikz-imagelabels} \usetikzlibrary{external} \tikzexternalize[prefix=plot_]

\begin{document}

\tikzset{external/force remake} \tikzsetnextfilename{01} \begin{figure}[h] \centering% \begin{tikzpicture}%[trim axis left, trim axis right] \begin{axis} \addplot+ coordinates {% (0,20)% (60,-40)% (150,-40)% };% \end{axis} l \end{tikzpicture}% \end{figure}

%\tikzset{external/export next = {false}} %\begin{figure} % \centering% % \begin{annotationimage}{width = 4cm}{example-image-a} % \draw[coordinate label = {Annotation at (0.2,0.2)}]; % \end{annotationimage}% %\end{figure}

\end{document}

The log says system commands enabled (I am using --shell-scape).

If I uncomment the last part, I get the error below and the externalised PDF vanishes:

! Package tikz Error: Sorry, the system call 'lualatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "plot_01" "\def\tikzexternalrealjob{tikzex
ternalize}\input{tikzexternalize}"' did NOT result in a usable output file 'plo
t_01' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enab
led system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it 
is also named 'write 18' or something like that. Or maybe the command simply fa
iled? Error messages can be found in 'plot_01.log'. If you continue now, I'll t
ry to typeset the picture.

Is this a bug, or am I missing something?

Just for context: I am using TeXstudio on Windows 10 with no admin rights. I installed TL2023 in my home folder (something like %userprofile%\stuff\texlive). I have to enter the path down to %userprofile%\stuff\texlive\2023\bin\windows in TeXstudio as search path for tikzexternalize to find lualatex.

ehak
  • 35
  • as the documentation says ... so the only requirement is that every picture’s end is directly reachable from its beginning, without further macro expansion.. Your environment hides the \end{tikzpicture} and so the process fails. Disable externalization for this picture with e.g. \tikzexternaldisable. – Ulrike Fischer Oct 31 '23 at 13:41
  • Thanks, with the annotationimage figure inside of {\tikzexternaldisable …} it works. I thought I would be achieving the same by putting \tikzset{external/export next = {false}} before the figure environment. I took that from here: https://tikz.dev/library-external#sec-52.4.3. Should have read the part about \tikzexternaldisable, too … – ehak Oct 31 '23 at 17:52
  • Or use memoize .... – cfr Oct 31 '23 at 18:44

1 Answers1

1

Since Ulrike Fischer has already answered your question in comments, this answer addresses a different question which is how you can externalise annotated images.

memoize has no difficulty memoizing the annotationimage environment, memoization is faster and the process does not even require unrestricted shell escape. Two compilations are required to stabilise the document, but the second only needs to include the externalised (memoized) images. The production of these images is done as part of the first compilation run. Unlike TikZ's externalisation method, there is no separate compilation process.

\documentclass{article}
\usepackage{memoize}
\usepackage{tikz,pgfplots,tikz-imagelabels}
\mmzset{%
  auto={annotationimage}{memoize}
}
\pgfplotsset{compat=1.18}
\begin{document}

\begin{figure}% you don't want to use simply h for placement and latex will change it if you do \centering \begin{tikzpicture}%[trim axis left, trim axis right] \begin{axis} \addplot+ coordinates {% (0,20)% (60,-40)% (150,-40)% };% \end{axis} l \end{tikzpicture}% does the l here serve any purpose? \end{figure}

\begin{figure} \centering \begin{annotationimage}{width = 4cm}{example-image-a} \draw[coordinate label = {Annotation at (0.2,0.2)}]; \end{annotationimage}% \end{figure}

\end{document}

plot and annotate image externalised with memoization

See https://tex.stackexchange.com/a/698555/ for a very basic introduction to memoize.

cfr
  • 198,882
  • I have never heard of memoize (not even the word/concept itself). That seems to open up an entire new hall in the mansion of TeXing. I'm going to have a look at that as soon as possible, thanks! – ehak Nov 02 '23 at 09:51
  • @ehak It's one of two new packages for externalising things to hit CTAN recently. So not having heard of it is probably to be expected ;). – cfr Nov 02 '23 at 14:36