1

I would like to use the externalize library. So far it worked perfectly and created pdf documents. But now I want to get a "png" file instead. I tried, according to the externalize documentation, the following:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=,figure list=true] 

\tikzset{
    png export/.style={
        % First we call ImageMagick; change settings to requirements
        external/system call/.add={}{& magick.exe -density 300 "\image.pdf" "\image.png"},
        % Now we force the PNG figure to be used instead of the PDF
        /pgf/images/external info,
        /pgf/images/include external/.code={
            \includegraphics[width=\pgfexternalwidth,height=\pgfexternalheight]{##1.png}
        },
    }
}

\begin{document}
    \tikzset{png export}
    \tikzsetnextfilename{Figure-A}%
    \begin{tikzpicture}
        \draw (0,0) circle (2) ;
    \end{tikzpicture}
\end{document}

This though does lead to an error in Windows 11 + MiKTeX Console 4.9 + TeXstudio 4.5.2 (git 4.5.2) + ImageMagick 7.1.1-5 Q16-HDRI x64 + lualatex (LuaHBTeX, Version 1.16.0 (MiKTeX 23.1)):

Process: lualatex.exe -synctex=1 -interaction=nonstopmode -shell-escape "main".tex

Meldung: "Der Befehl "magick.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden." (English it means: "The command "magick.exe" is either misspelled or could not be found.")

Log: "Package luatex.def Error: File `Figure-A.png' not found: using draft setting. \end{tikzpicture}"

The Figure-A.log file doesn't show any error so far as I can see, but the main.log file shows an error at this line:

\openout4 = main.figlist

Writing 'Figure-A' to 'main.figlist'.

\openout3 = Figure-A.md5

\openout3 = main.auxlock
===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "Figure-A" "\def\tikzexternalrealjob{ma
in}\input{main}"& magick.exe -density 300 "Figure-A.pdf" "Figure-A.png"' ======
==

\openout3 = main.auxlock

LaTeX Warning: File `Figure-A.png' not found on input line 24.


! Package luatex.def Error: File `Figure-A.png' not found: using draft setting.


See the luatex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.24    \end{tikzpicture}
                     
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

Summary:

-) The Figure-A.pdf file has been created, but it seems there is a problem with the conversion from the "pdf" to "png" file.

-) If I run the process on the commandline instead of TeXStudio the same problem occurs.

-) When I try this on the command line 'magick.exe -density 300 "Figure-A.pdf" "Figure-A.png"' after one latex run (to generate Figure-A.pdf) it generates the image "Figure-A.png" perfectly.

-) I found out it works with pdflatex, so it seems to be a problem with lualatex. Although I don't know where the problem is and I would need it lualatex...

Would appreciate if someone could look into this and help me out.

4
  • I don't know why it would work with pdfTeX, but the problem is either the installation of ImageMagick or (more likely) a problem finding the executable. Try specifying the full path to the .exe file as it is not being found. Also double-check the name of the executable on your system.
    – cfr
    Jul 13, 2023 at 0:32
  • @cfr Thanks after I tried some stuff with the full path this worked: external/system call/.add={}{& "C:\\Program Files\\ImageMagick-7.1.1-Q16-HDRI\\magick.exe" -density 300 "\image.pdf" "\image.png"}, I don't really understand why I would need the full path (nor why I need the quotes) when I want to do it with lualatex, but as long as it does work... <3 Thanks. Jul 13, 2023 at 10:09
  • @cfr Since it works now with the full path and that's enough for me, meaning it's probably on my end something with finding the exe, as you said, should I close the question? :D Jul 13, 2023 at 11:56
  • You could just answer your question yourself if this might be of interest to others. I have no idea how Windows determines where to look, so I can't do any more to solve the mystery!
    – cfr
    Jul 13, 2023 at 23:39

1 Answer 1

0

As @cfr pointed out, using the full path to the executable solved the problem, meaning the following path in my case:

external/system call/.add={}{& "C:\\Program Files\\ImageMagick-7.1.1-Q16-HDRI\\magick.exe" -density 300 "\image.pdf" "\image.png"}

This generates first the pdf file, then the png file and includes the png in my document afterwards.

2
  • Have you play with your PATH environment variable such as to make the executable magick.exe launchable directly?
    – projetmbc
    Jul 14, 2023 at 18:38
  • 1
    @projetmbc In the environment variables the following is there: C:\Users\micha\AppData\Local\Programs\MiKTeX\miktex\bin\x64 and C:\Program Files\ImageMagick-7.1.1-Q16-HDRI Jul 14, 2023 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .