[Tex/LaTex] Cannot set pixel density in standalone package for PNG output

pngstandalone

I want to output a PNG image with the standalone package. Here is a minimal working example:

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

\begin{document}
    Hello world
\end{document}

When I inspect the file properties of the resulting PNG file, I still get 72 dpi. Even without using the preview option, it's still at 72 dpi. However, if I convert to JPG using convert={density=300, outext=.jpg}, I'd get 300 dpi.

How can this be fixed? My particular requirement would be to use the preview option and use the PNG image format.

Best Answer

The package manual states that “the following default settings are used: PNG format, a density of 300dpi, no explicit size […].”

So there's no surprise that density=300 doesn't result in a different output.

I wouldn't trust the “file properties” of the resulting file. How should a picture viewer (or your OS) know what an inch is? It's just pixels at the output side now.

Consider the following example where I typeset a black 1 inch by 1 inch square.

The output .png is 300 pixels by 300 pixels.

Code

\documentclass[
    preview,
    convert% uses default settings: density=300 and png
]{standalone}

\begin{document}
    \rule{1in}{1in}
\end{document}

Output

enter image description here


To complement egreg's comment:

Code

\documentclass[preview,convert]{standalone}
\usepackage{printlen}\uselengthunit{in}
\newlength{\myWidth} \newlength{\myHeight}
\sbox0{Hello world}
\setlength{\myWidth}{\wd0}\setlength{\myHeight}{\ht0}
\begin{document}
\printlength\myWidth${}\times{}$\printlength\myHeight\ (\the\wd0 ${}\times{}$\the\ht0)
\end{document}

Output

enter image description here