standalone package: reconstruction of the command line

With current version of ImageMagick, ImageMagick 7.0.7-21 Q16 x64 2018-01-06 application filename is long ago magick so the standalone package should be invoked by something like this:

\documentclass[convert={convertexe=magick,density=200,outext=.png}]{standalone}


which sends command

magick -density 200 filename.pdf filename.png


to the prompt. Now this procedure results with PNGs with a transparent background. To avoid transparence prompt command should be changed to

magick -density 200 filename.pdf -alpha remove filename.png


that is, -alpha remove should be put between two filenames. This means that -alpha remove cannot be simply attacked to density=200, as proposed elsewhere: converting a table to png using standalone.

I went through the standalone package, and Pg. 17 of the manual suggests that command prompt could be reconstructed using sub-option command. So what I actually tried to do is this:

\documentclass[tikz,convert={convertexe=magick,density=200,outext=.png,command={\convertexe\space -density \density\space \infile\space -alpha remove\space \outfile}}]{standalone}


However, it seems that command reconstruction does not work, as PdfLatex compiler from Miktex returns ! Undefined control sequence. upon invoking \convertexe.

The example in the manual reads:

command={\convertexe\space -density \density\space \infile\space \ifx\size\empty\else -resize \size\fi\space -quality 90 \outfile}


What is wrong? Did I misread the instructions?

1 Answer

If I have the following test.tex file

\documentclass[tikz,convert]{standalone}

\begin{document}

\begin{tikzpicture}
\draw (0,0) rectangle (2,1) node [midway] {Example};
\end{tikzpicture}

\end{document}


along with the following standalone.cfg file in the same directory

\standaloneconfig{
multi=false,
crop,
convert={
convertexe=magick,
density=200,
outext=.png,
command={%
\convertexe\space
-density \density\space
\infile\space
-alpha remove\space
\outfile
}
}
}


then running

pdflatex -shell-escape test


results in calling the external program

magick -density 200 test.pdf -alpha remove test.png


as can be seen in the test.log file by looking for runsys. Indeed, if I ask for information about the file, I get

> file test.png
test.png: PNG image data, 1700 x 2200, 4-bit grayscale, non-interlaced


Update

You can specify the commands also in the options, but with a small tweak:

\documentclass[
tikz,
multi=false,
crop,
convert={
convertexe=magick,
density=200,
outext=.png,
command=\unexpanded{%
\convertexe\space
-density \density\space
\infile\space
-alpha remove\space
\outfile
},
},
]{standalone}

\begin{document}

\begin{tikzpicture}
\draw (0,0) rectangle (2,1) node [midway] {Example};
\end{tikzpicture}

\end{document}


In the log file I find

runsystem(magick -density 200 conv.pdf -alpha remove conv.png)...executed.


and the generated file reports

> identify test.png
test.png PNG 159x80 159x80+0+0 8-bit Gray 16c 900B 0.000u 0:00.000

• @Pygmalion Add crop to the options, see the edit – egreg Feb 5 '18 at 11:50
• Thanks for your effort. But it is the bug that this does not work in [] brackets? The specification with brackets would be much more flexible. If so, I'll keep the question open, maybe author will fix the bug. – Pygmalion Feb 5 '18 at 11:57
• @Pygmalion If it is a bug, you'd be better off contacting the author directly. Not all authors haunt TeX SE. – cfr Feb 5 '18 at 23:40
• @cfr Well, the author is a moderator of this site. ;-) – egreg Feb 5 '18 at 23:41
• @egreg Couldn't remember who wrote it. But it is still reasonable advice as a general policy. And even moderators don't actually live here. For a terrible moment, though, I thought you meant an author of something else. So glad you did not. – cfr Feb 6 '18 at 0:12