7

I'm having a hard time getting TikZ externalize and Forest to play nicely. Here is a MWE (text.tex):

\documentclass{article}
\usepackage[external]{forest} 
\tikzexternalize
\tikzset{
  external/system call={
    xelatex \tikzexternalcheckshellescape -halt-on-error -interaction=nonstopmode -jobname 
    "\image" "\texsource"
  }
}
\begin{document}

\begin{forest}
  [a
    [b]
    [c]
  ]
\end{forest}

\end{document}

I compile by invoking latexmk -xelatex -pvc test.tex --shell-escape. The first time, everything works: I get a pdf output, and the tree is externalized as its own pdf. However, all subsequent compiles fail, with the following error:

! Argument of \tikzexternal@externalizefig@systemcall@uptodatecheck has an extra }.
<inserted text>
                \par
l.17 \end{forest}

?

I'm using xelatex, but an identical error is present with a pdflatex compile.

The issue seems to be due to the interaction of Forest and TikZ: replacing the forest environment in the MWE with a tikzpicture environment fails to reproduce the error.

I'm using MacTeX-2015 and pgf version 3.0.0, along with the latest version of Forest (so says tlmgr). Thanks for any help you can offer.

EDIT (Addition by cfr)

I can reproduce the problem with the following minimal example

\documentclass{article}
\usepackage[external]{forest}
\tikzexternalize
\begin{document}
\begin{forest}
  [a[b][c]]
\end{forest}
\end{document}

with pdflatex --shell-escape on GNU/Linux with TeX Live 2015 updated a couple of hours ago.

The error on second compilation is:

(./prawf3.for)
! Argument of \tikzexternal@externalizefig@systemcall@uptodatecheck has an extr
a }.
<inserted text> 
                \par 
l.13 \end{forest}

Gonzalo Medina can reproduce this.

  • Welcome! I use forest and externalisation with TikZ extensively. I have never once successfully externalised a forest. I'm not saying it can't be done - clearly it is possible - but I decided it was not worth further energy trying to resolve the issues and just switch externalisation off for forest environments. Note that I get multiple errors even if I don't run with shell escape so that it falls back to non-externalisation. – cfr Jul 10 '15 at 2:07
  • Thanks! The recent forest user manual suggests that it is possible (p.20), as you say, and prior threads on here indicate that it worked in principle, at least once upon a time (e.g.). Seems like a bug or incompatibility was introduced somewhere along the way, perhaps relatively recently. – Simon C Jul 10 '15 at 2:13
  • 1
    I just downloaded version 1.03 from the link provided in the answer you linked to. If I use that rather than the current version, it still fails even if I add \usepackage{etex} (which is necessary to work around an incompatibility between current TL and previous versions of forest). So I'm not sure that it can be that the bug has been reintroduced.... Unless my brain is the buggy bit. – cfr Jul 10 '15 at 2:31
  • 1
    I've abused the comments system to leave a couple of messages for people, including the package author. Maybe somebody will bite ;). – cfr Jul 10 '15 at 2:41
  • 1
    I hope you will not mind that I have added a couple of further data points to your question. (You can roll back my edit if you object.) – cfr Jul 10 '15 at 2:53
5

This error is due to an internal change in pgf.

Can you confirm that adding the following code to the preamble solves your problem. If it does, I'll post a new version of forest on ctan.

\makeatletter
\def\forest@includeexternal@check#1{%
  \tikzsetnextfilename{#1}%
  \IfFileExists{\tikzexternal@filenameprefix/#1}{\tikzexternal@file@isuptodatetrue}{\tikzexternal@file@isuptodatefalse}%
}
\makeatother

Apology #1: I know it's bad practice to rely on the internals of other packages, but there was no other way I could make externalization work ...

Apology #2: I have had this fix included in a new version of forest I'm preparing, but forgot to include it in the patches of the old version.

  • Thank you, that worked like a charm! Compiling, and super-speedily now. Appreciate the quick reply, and all your hard work on forest. – Simon C Jul 10 '15 at 10:19
  • Just posted the patched version to ctan. – Sašo Živanović Jul 10 '15 at 12:16
  • Appreciate this and looking forward to beta testing the new version when you're ready! – cfr Jul 10 '15 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.