htlatex crops too much for picture environment

I use htlatex to convert a large latex file to html pages. All works with one exception. Anything drawn in the picture environment gets cropped. I have isolated the problem in the code example below. The three filled circles have parts missing at the top, the bottom, and on the left boundary.

\documentclass{book}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{picture}(1.2,1.2)
\put(0.1,0){\circle*{0.2}}
\put(0.1,0){\line(1,2){0.5}}
\put(0.6,1){\circle*{0.2}}
\put(1.1,0){\circle*{0.2}}
\end{picture}
\end{document}


It looks fine when the same source file is converted to a pdf instead.

The line that creates that png file appears to be the following:

gs -sDEVICE=pngalpha -sOutputFile=bugreport0x.png -r110x110 -dEPSCrop -dBackgroundColor=16#ffffff -dTextAlphaBits=2 -dGraphicsAlphaBits=2 -q -dbatch -dNOPAUSE zzbugreport.ps -c quit


I would use dvipng instead of default tex4ht image conversion, which goes in dvips -> gs route. It is slow and fragile.The image conversion process can be easily modifed with make4ht. You can configure it with Make:image command in a build file:

Make:htlatex {}
Make:image("png$", "dvipng -bg Transparent -T tight -o${output}  -pp ${page}${source}")


save it as filenameofyourtexfile.mk4 and run command:

make4ht filenameofyourtexfile


First parameter for Make:image is a Lua regular expression to match image filename, the second is command template to be executed, with \${variable} placeholders. All images to be converted are stored in special dvi file named filenameofyourtexfile.idv. Each page in this file is one image. Variables in the template are: output is file name of the generated image, page is page number of the image and source is filename of the .idv file.

• Strangely, I don't seem to be able to figure out how to install make4ht on my Mac. I have tex4ht, pandoc, and of course texlive through macports, but none of these come with make4ht. – Norbert Oct 19 '15 at 11:21
• @Norbert it is part of official TeX Live distribution, you can try to install it yourself. – michal.h21 Oct 19 '15 at 11:40
• Thank you for this! htlatex first uses dvips to create a postscript file from an idv file--this is where the trimming happens--and then gs to create the png file. Using dvipng to get from idv to png directly, appears to solve the problem. I think I'll write some shell script that that does things like dvipng -bg Transparent -T tight shell.idv -pp 3 -o shell1x.png – Norbert Oct 19 '15 at 11:42
• @Norbert you can find image file names and pages in the .lg file. but in this case I wouldn't use htlatex anyway, because it would compile the images twice – michal.h21 Oct 19 '15 at 11:49
• Thanks! Even better. I have it working now, using dvipng. – Norbert Oct 19 '15 at 21:41