How to make a standalone image with a transparent background

standalonetikz-pgftransparency

When I try to make a PNG image using TikZ by using the convert option for the standalone class, I cannot figure out how to make the background transparent.
I seem to recall some years ago that this happened by default; while I could be misremembering, other questions and answers on here seem to back up that memory (e.g. tikzpicture has clear background by default, this recent question stating that the TikZ standalone picture background was clear and asking how to make it white…).
In any case, the default behavior on my machine currently seems to be a white background.
Using a minimal example,

\documentclass[convert={density=300},tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{document}

I get a circle with a white background:

enter image description here

How can I make the background transparent?

It may be that software version details matter; I have the following setup:

  • OS: Ubuntu 21.10
  • LaTeX distribution: TeX Live 2020
  • (can provide other details on request, not sure what else to add)

Best Answer

You could use the command= suboption to convert= to further specify the convert command. Something like this should work:

\documentclass[convert={density=300,command=\unexpanded{{\convertexe\space -density \density\space \infile\space -transparent \space white \outfile}}},tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw [ultra thick] (0,0) circle (2.5cm);
\end{tikzpicture}
\end{document}

This is adapted from the example in the standalone documentation you linked to.

Be sure to run with --shell-escape.