1

Using TL 2023, this command works

lualatex --shell-escape  --file-line-error index.tex

Gives no error:

...
/usr/local/texlive/2023/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "images/my_image_file" "\def\tikzextern
alrealjob{index}\input{index}"' ========
This is LuaHBTeX, Version 1.16.0 (TeX Live 2023) 
 system commands enabled.
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}<./imag
es/my_image_file.pdf>] (./index.aux))

But this gives error

lualatex --shell-escape  --file-line-error -jobname=LUA index.tex

This error happens when the latex file is trying to save tikzpicture to pdf file using the externalization package of tikz. It give this error

/usr/local/texlive/2023/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "images/my_image_file" "\def\tikzextern
alrealjob{LUA}\input{LUA}"' ========
This is LuaHBTeX, Version 1.16.0 (TeX Live 2023) 
 system commands enabled.

./index.tex:15: Package tikz Error: Sorry, the system call 'lualatex -shell-esc ape -halt-on-error -interaction=batchmode -jobname "images/my_image_file" "\def \tikzexternalrealjob{LUA}\input{LUA}"' did NOT result in a usable output file ' images/my_image_file' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify th at you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape '. Sometimes it is also named 'write 18' or something like that. Or maybe the c ommand simply failed? Error messages can be found in 'images/my_image_file.log' . If you continue now, I'll try to typeset the picture.

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

l.15 \end{tikzpicture}

?

It is using the jobname which is causing the problem. Otherwise externalization works, and the pdf of the tikzpicture is created correctly.
I needed to use -jobname option because I also build tex4ht in same folder and this option helps keeps auxiliary and temp file names separated and not clash when I compile to pdf and html in same folder.

In images/my_image_file.log it says

......
Inserting `luaotfload.rewrite_fontname' in `luaotfload.patch_font'.
Inserting `tracingstacklevels' in `input_level_string'.
! Emergency stop.
<read *>

<*> \def\tikzexternalrealjob{LUA}\input{LUA}

I think the problem is that it looking for LUA.tex file in the above command, but there is no LUA.tex file. This is supposed to be just the jobname, not not the input file name ! So the above command should have been

\def\tikzexternalrealjob{LUA}\input{index}

Below is MWE to reproduce this. This is on Linux virtual box running latest TL 2023

\documentclass[12pt]{article}
\usepackage{shellesc} %need for lualatex!       
\usepackage{tikz} 
\usetikzlibrary{external}
\tikzexternalize[prefix=images/]

\begin{document}

%this command saves pic to images/my_image_file.pdf %make sure to create images/ folder first as it will not do it \tikzsetnextfilename{my_image_file}

\begin{tikzpicture} \node[] at (0,0) {some text}; \end{tikzpicture}

\end{document}

When running these commands, please make sure to have images/ folder created and empty each time in order to see the problem.

I found that if I have the image file there before, then no error shows up when using jobname option because it sees the pdf image file already and will not attempt to create it again.

Question is: It is possible to use -jobname with lulatex and also use tikz externalization?

Nasser
  • 20,220
  • @cfr thanks. But this is not my workflow. I need to put all images in images/ folder, and then give each pic an image file name. The document could have 10 pics, and each is saved to different pdf file in the images/ folder. But I tried what you showed and got an error ./index.tex:18: Package tikz Error: Sorry, image externalization failed: the re sulting image was EMPTY. I tried to externalize 'LUA', but it seems there is no such image in the document!? What does \tikzexternalize[]{index} supposed to actually do? – Nasser Oct 25 '23 at 02:17
  • Yes, I tried it too and got the same. I thought it was supposed to override the default assumption about the file to input, but I misread it. Sorry. Should have tested first. I don't see what relevance your workflow has. Oh, I see. I just put [] rather than bothering to copy your prefix option i.e. [] is just whatever you want. So you need to specify the entire externalisation command, I think. This has nothing to do with latexmk. See 52.4.5. – cfr Oct 25 '23 at 02:29
  • @cfr I also tried with \tikzexternalize[prefix=images/]{index} and got error also. so far only solution I found is not to use -jobname when using tikz externalization. – Nasser Oct 25 '23 at 02:31
  • \tikzset{external/system call={lualatex -shell-escape -halt-on-error -interaction=batchmode -jobname "images/my_image_file" "\def\tikzextern alrealjob{LUA}\input{index}"}} maybe? I haven't tested this either yet. – cfr Oct 25 '23 at 02:32
  • 1
    Are you interested in an alternative which works out of the box, doesn't require shell-escape, is faster and can externalise images which the external library can't? – cfr Oct 25 '23 at 02:53
  • Hello @cfr Sure. That will be great. As I mentioned, I just need solution which still uses -jobname with latexmk and saves names images to my images/ folder. I use \tikzsetnextfilename{my_image_file} before each tikzpicture. I could have 10 or 20 different tikzpics in the file and each will have different name. In the MWE I have above, I only showed one tikzpic. This all works now if I do not use -jobname with latexmk. – Nasser Oct 25 '23 at 03:00
  • Custom naming is the missing feature, from my point of view. Tell Sašo I'm not the only one who wants this! (I have a library which automates naming after filenames for external.) It's not as bad as TikZ because inserting images doesn't cause later images to be renamed but, still, it would be easier, for sure. – cfr Oct 25 '23 at 03:07
  • 1
    Note you could simplify this by removing latexmk and might get more attention to the problem in that case. – cfr Oct 25 '23 at 04:53
  • @cfr fyi, updated the question. removed latexmk. You are right, this error comes from lualatex when using -jobname – Nasser Oct 25 '23 at 05:22
  • well sure, the external library has no chance to know that the picture code is hidden inside index.tex if you change jobname. Adapt as suggested the system call. Btw: the shellesc package should imho not be needed. – Ulrike Fischer Oct 25 '23 at 08:40

1 Answers1

2

I propose an alternative which is faster, more secure and more robust than the external library. It doesn't require full shell escape (only restricted, which is default) and works in this case out-of-the-box. Oh, and it will make the directory for you.

\documentclass[12pt]{article}
\usepackage[extract=perl]{memoize}
\mmzset{% perl is default
  path={dir=images},
  mkdir,
}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} \node[] at (0,0) {some text}; \end{tikzpicture}

\end{document}

Compiled with

$ TEXMFHOME=/d lualatex -jobname="lua" prawf

Files produced after two compilations:

$ ls lua.* images/
lua.aux  lua.log  lua.mmz  lua.mmz.log  lua.pdf

images/: lua.EEA66177700E896EF689C961311611CD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.memo lua.EEA66177700E896EF689C961311611CD.memo lua.EEA66177700E896EF689C961311611CD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.pdf

What you cannot do, at present, is assign custom names. (I've started lobbying for this ;.) The need for them is somewhat less acute because inserting an image at the beginning of the document won't cause all images to change names, but I would prefer my images to include a human-readable name for convenience.

There are three extraction methods. You may need to install a couple of libraries for perl or python, assuming you have the interpreter available already. TeX Live requires perl, so that's the default. The TeX method requires shell escape and is slowest.

cfr
  • 198,882
  • You lobbying works, I'm working on it. But in the interest of precision, custom names do work, even at the moment, use \mmzset{path={prefix=foo-}} to set filename prefix foo-. What does not currently (v1.0.0) work is setting the prefix by \mmznext, i.e. \mmzset{path={prefix=foo-}}, which would of course be very useful. But this will be easily fixed, it's just an grouping issue I overlooked. – Sašo Živanović Oct 25 '23 at 19:23
  • Another feature currently missing is conversion to .png and such. I should find the time for that in a couple of months. – Sašo Živanović Oct 25 '23 at 19:24
  • A couple of remarks on --prune above. First, an easier way to append it to the options is perl extraction options/.append={\space--prune}. (\space is required because pgfkeys trims spaces around key values.) – Sašo Živanović Oct 25 '23 at 19:32
  • 1
    Second, setting perl extraction options with mmzset in the preamble has no effect whatsoever :) because extraction happens while loading Memoize. This setting was meant to be used in memoize.cfg (or as a package option, although that's cumbersome as you can't use spaces there). – Sašo Živanović Oct 25 '23 at 19:39
  • Third, having --prune for internal extraction (i.e. when Memoize does the extraction for you while being loaded) is kind of pointless, as the nicely pruned PDF is immediately overwritten by the compilation :) This option can be useful if you have a compilation script which first compiles the document and then immediately extract the externs from it and prune it. This way, you don't ever seen the ugly extern pages (or at most for a moment). – Sašo Živanović Oct 25 '23 at 19:42
  • Incidentally, I also have an inference rule called Prune :D – Sašo Živanović Oct 25 '23 at 19:42
  • @SašoŽivanović Thanks. I'm now incredibly confused, though. – cfr Oct 25 '23 at 21:47
  • @SašoŽivanović See https://tex.stackexchange.com/q/699289/. My current answer is horrible, but it's the first version I've got to give me stable output on compilation. – cfr Oct 25 '23 at 22:36
  • @SašoŽivanović At least, I thought it was horrible. It feels like cheating. But now somebody is copying it into a library .... We hope you will have time to have a look. – cfr Oct 26 '23 at 03:07
  • Why can't you use spaces in package options? You say on page 71 this is a 'constraint imposed by LaTeX itself' but I'm not sure why. I just wrote a very silly package modname and had no trouble doing \usepackage[my spaced option=apple]{modname}. @SašoŽivanović – cfr Oct 26 '23 at 03:26
  • Afaik, LaTeX strips spaces from package options. Your experiment should fail if you parse package options using pgfopts. – Sašo Živanović Oct 26 '23 at 05:29
  • @SašoŽivanović pgfopts must be the difference. – cfr Oct 26 '23 at 13:52