Converting PDF to PNG using ImageMagick or Ghostscript

Basically this:

convert -density 300 $FILE.pdf $FILE.png
where -density sets the size of the output image (in DPI, so experiment to get the required size).

This should make a white background transparent:

convert -density 300 $FILE.pdf -transparent white $FILE.png
but it doesn't work well with anti-aliasing.

Using Ghostscript directly seems much better for transparency:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -dEPSCrop -sOutputFile=$FILE.png $FILE.pdf
where -r sets the output size equivalently to -density above.