How can I externalize TikZ in such a configuration? There is my MWE:


\documentclass[a4paper, 10pt]{article}
    \usepackage[left=30mm, right=10mm, top=15mm, bottom=25mm]{geometry}
    \usepackage[english, russian]{babel}
    \usepackage{amsmath, amssymb, mathrsfs, bm}
    \usepackage{indentfirst, graphicx}
    \usepackage[labelsep = period]{caption}



\setmathfont{XITS Math}



\tikzset{external/system call={lualatex -fmt=preamble.fmt \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}


    lorem ipsum $x^2 + y^2 = 4$

        \draw (0, 0) -- (2, 2);

Command lines:

luatex -ini -jobname="preamble" "&lualatex" mylatexformat.ltx preamble.tex
lualatex --shell-escape -synctex=1 -interaction=nonstopmode --fmt preamble --output-directory ./out "document".tex

Error message: document.log (excerpt):

\openout3 = picturrre.md5

\openout3 = document.auxlock
===== 'mode=convert with system call': Invoking 'lualatex -fmt=preamble.fmt -she
ll-escape -halt-on-error -interaction=batchmode -jobname "picturrre" "\def\tikze
xternalrealjob{document}\input{document}"' ========

\openout3 = document.auxlock

! Package tikz Error: Sorry, the system call 'lualatex -fmt=preamble.fmt -shell
-escape -halt-on-error -interaction=batchmode -jobname "picturrre" "\def\tikzex
ternalrealjob{document}\input{document}"' did NOT result in a usable output fil
e 'picturrre' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you h
ave enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Somet
imes it is also named 'write 18' or something like that. Or maybe the command s
imply failed? Error messages can be found in 'picturrre.log'. If you continue n
ow, I'll try to typeset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.

l.29    \end{tikzpicture}

This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.

picturrre.log (full):

    This is LuaTeX, Version 1.0.4 (TeX Live 2017/Debian)  (format=preamble 2019.12.3)  3 DEC 2019 12:54
     system commands enabled.
    Lua module: luaotfload-main 2017/01/29 2.80001 OpenType layout system.
    Lua module: lualibs 2017-02-01 2.5 ConTeXt Lua standard libraries.
    Lua module: lualibs-extended 2017-02-01 2.5 ConTeXt Lua libraries -- extended collection.(using write cache: /home/cloun/.texlive2017/texmf-var/luatex-cache/generic)(using read cache: /var/lib/texmf/luatex-cache/generic /home/cloun/.texlive2017/texmf-var/luatex-cache/generic)
    luaotfload | conf : Root cache directory is /home/cloun/.texlive2017/texmf-var/luatex-cache/generic/names.
    luaotfload | init : Loading fontloader “fontloader-2017-02-11.lua” from kpse-resolved path “/usr/share/texlive/texmf-dist/tex/luatex/luaotfload/fontloader-2017-02-11.lua”.
    Lua-only attribute luaotfload@state = 5
    Lua-only attribute luaotfload@noligature = 6
    Lua-only attribute luaotfload@syllabe = 7
    luaotfload | init : Context OpenType loader version “3.027”
    Inserting `luaotfload.node_processor' at position 1 in `pre_linebreak_filter'.
    Inserting `luaotfload.node_processor' at position 1 in `hpack_filter'.
    Inserting `luaotfload.define_font' at position 1 in `define_font'.
    Lua-only attribute luaotfload_color_attribute = 8
    luaotfload | conf : Root cache directory is /home/cloun/.texlive2017/texmf-var/luatex-cache/generic/names.
    Inserting `luaotfload.aux.set_sscale_dimens' at position 1 in `luaotfload.patch_font'.
    Inserting `luaotfload.aux.patch_cambria_domh' at position 2 in `luaotfload.patch_font'.
    Inserting `luaotfload.aux.fixup_fontdata' at position 1 in `luaotfload.patch_font_unsafe'.
    Inserting `luaotfload.aux.set_capheight' at position 3 in `luaotfload.patch_font'.
    Inserting `luaotfload.rewrite_fontname' at position 4 in `luaotfload.patch_font'.
    luaotfload | main : initialization completed in 0.094 seconds

    JOB NAME         : "picturrre"
    CUSTOMISED FORMAT: "preamble"
     article.cls    2014/09/29 v1.4h Standard LaTeX document class
      size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
    geometry.sty    2010/09/12 v5.6 Page Geometry
      keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
       ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
      ifvtex.sty    2016/05/16 v1.6 Detect VTeX and its facilities (HO)
     ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
       babel.sty    2018/02/14 3.18 The Babel package
     english.ldf    2017/06/06 v3.3r English support from the babel system
     amsmath.sty    2017/09/02 v2.17a AMS math features
     amstext.sty    2000/06/29 v2.01 AMS text
      amsgen.sty    1999/11/30 v2.0 generic functions
      amsbsy.sty    1999/11/29 v1.2d Bold Symbols
      amsopn.sty    2016/03/08 v2.02 operator names
     amssymb.sty    2013/01/14 v3.01 AMS font symbols
    amsfonts.sty    2013/01/14 v3.01 Basic AMSFonts support
    mathrsfs.sty    1996/01/01 Math RSFS package v1.0 (jk)
          bm.sty    2017/01/16 v1.2c Bold Symbol Support (DPC/FMi)
    indentfirst.sty    1995/11/23 v1.03 Indent first paragraph (DPC)
    graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
    graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
        trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
    graphics.cfg    2016/06/04 v1.11 sample graphics configuration
      luatex.def    2018/01/08 v1.0l Graphics/color driver for luatex
     caption.sty    2016/02/21 v3.3-144 Customizing captions (AR)
    caption3.sty    2016/05/22 v1.7-166 caption3 kernel (AR)
    subcaption.sty    2016/05/22 v1.1-161 Sub-captions (AR)
        umsa.fd    2013/01/14 v3.01 AMS symbols A
        umsb.fd    2013/01/14 v3.01 AMS symbols B
       ursfs.fd    1998/03/24 rsfs font definition file (jk)

    ! Emergency stop.
    <*> ...\tikzexternalrealjob{document}\input{document}

    Here is how much of LuaTeX's memory you used:
     6 strings out of 490450
     100000,154059 words of node,token memory allocated
     469 words of node memory still in use:
       6 hlist, 2 vlist, 2 rule, 1 dir, 5 glue, 1 kern, 6 attribute, 49 glue_spec, 6
     attribute_list, 1 write nodes
       avail lists: 2:14,3:1,4:2,5:9,7:1,8:2
     7965 multiletter control sequences out of 65536+600000
     57 fonts using 4052259 bytes
     9i,0n,26p,0b,31s stack positions out of 5000i,500n,10000p,200000b,100000s
    !  ==> Fatal error occurred, no output PDF file produced!

Those error messages are not informative, I can't find what I miss, hope you can help.

  • 1
    I've deleted my answer. You are right, it does not work. I'd made a mistake when trying to reproduce your issue + got confused by the fact that it does produce a correct-looking document.pdf - but the error is still there, and there's no picturrre.pdf. – Disenchanted Lurker Dec 3 at 13:35
  • Huh, you were right at one half, when you discussed different dirs. You could leave that answer here, it was somewhat useful after the main problem was eliminated. – StaticZero Dec 3 at 14:09
  • 1
    Here's a link to an answer that explains the issue with directories pretty well. I've tried looking into your problem some more, but all I can tell is that it's the precompiled preamble that's causing the issue. Unfortunately, I don't know enough about this to figure out what needs to be changed to make it work. – Disenchanted Lurker Dec 3 at 14:40
  • Answered myself. That answer actually didn't address secondary issue with ".pdf not being found" error, resolved by trial-and-error, but thanks though. – StaticZero Dec 3 at 14:58

I prepared my MWEs in order to illustrate the problem itself, but I would go deeper in the answer to be somewhat instructive.

At first, document.tex with a precompiled preamble is being compiled with --output-directory ./out, and this causes lualatex to divert its document-related rubbish into ./out directory, . being the project root.

It is phenomenological that one must use the \endofdump directive again when he calls external tikz syscall, an appropriate string turns to be

\tikzset{external/system call={lualatex --shell-escape --fmt preamble --halt-on-error --output-directory ./out -jobname "\image" "\endofdump\texsource"}}

However, if one specifies --output-directory ./out in that tikzset string again, compilation aborts with the following error:

! error:  (file picturrre.pdf) (pdf backend): cannot find image file 'picturrre.pdf'

It seems that brand new pdf with tikzpicture is expected to be at the project root, ., but it resides within ./out besides its .md5, .log and so on. Thus, there are two alternatives: one should either remove output dir from tikzset string, or write \tikzexternalize[prefix=out/].

The second variant causes tikz-externalized pdf image with its satellites to go to ./out/out dir, but they are expected at ./out, and the following error occurs:

! error:  (file out/picturrre.pdf) (pdf backend): cannot find image file 'out/picturrre.pdf'

So we try to remove --output-directory ./out from tikzset string while retaining tikz prefix to be out/. It causes tikz-externalized pdf image with its partners to go to ./out dir, where all other rubbish is located, but you still need ./out/out dir because .md5 files go there (their path is ./output-dir/externalize-prefix, but other files go just to ./externalize-prefix dir). The document compiles flawlessly.

However, if one uses gnuplot with tikz/pgf, .gnuplot and .table files will go to the project root because of --output-directory parameter being omitted from the tikzset string, hence it is not possible to divert gnuplot rubbish to ./out dir as well (but if one actually could, he would write

\pgfkeys{/pgf/plot/gnuplot call={cd out && gnuplot}}

after \begin{document} to force gnuplot to search for .gnuplot files automatically).

  • Ah, so for the original issue, the tl;dr is: use "\endofdump\texsource" in the system call, instead of just "\texsource". And the output directory was just an unrelated complication. Nice job figuring it out! – Disenchanted Lurker Dec 3 at 15:26

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.