[tex4ht] SVG or PNG ?

Michal Hoftich michal.h21 at gmail.com
Sun Jan 24 16:10:38 CET 2021


Dear Tomáš,


>   can someone please explain what are pros and cons of using graphics 
>in PNG or SVG for the LaTeX to HTML conversion? Naively I would guess 
>SVG is better since it is vectorized format, but after playing with 
>that I encounter the following issues:
>

Yes, SVG is better in general, unless you deal with EPS pictures that 
contain bitmap data, as you found (I didn't know about it)

>[INFO]    make4ht-lib: executing: t4ht  "pictures_t4h.dvi"
>GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
>dvipng warning: No image output from inclusion of raw PostScript GPL 
>Ghostscript 9.53.3: Unrecoverable error, exit code 1
>dvipng warning: No image output from inclusion of raw PostScript GPL 
>Ghostscript 9.53.3: Unrecoverable error, exit code 1
>
>Is that a t4ht issue?

It is a dvipng issue. It seems that it sometimes fails due to unknown 
PostScript instructions. It is possible to configure make4ht to use 
different tool, see 

https://www.kodymirus.cz/make4ht/make4ht-doc.html#x1-210005.4

but I don't think you can find any easier to use tool than dvipng for 
the bitmap conversion.


>2. svg with make4ht -a debug -u pictures_t4h.tex "svg"
>
>In this approach the 2nd picture comes out perfectly ok, but there are 
>some non-vector EPS files that do not convert to SVG, like the third 
>plot. The EPS -> PDF conversion proceeds well, but then pdf2svg 
>results in an empty white picture of the corresponding size. I also 
>tried to use inkscape for the latter conversion, with the same result.

I see. The generated SVG file contains some data, but they are not shown 
at all. I tried to convert the PDF and EPS files using ImageMagick and 
the resulting SVG file didn't work as well. So it seems like general 
issue.

The conversion to PNG works, so it seems like the way to go in this 
case.  I got much better results using GhostScript:

gs -dSAFER    -dBATCH    -dNOPAUSE    -dEPSCrop    -r100    
-sDEVICE=pngalpha -sOutputFile=street_stevenson_layout.png 
street_stevenson_layout.eps

than with ImageMagick.

>As a possible workaround I can think of converting the problematic EPS 
>files to PNG manually and account for that in the LaTeX code by e.g.
>
>\ifpdf \includegraphics{myfigure.eps} \else 
>\includegraphics{myfigure.png}\fi
>
>But probably there is a smarter way to go?

Yes, don't use the image extension at all, LaTeX will choose best image 
automatically.


>One more general question - with the "svg" option, all graphics (i.e. 
>math, plots etc) are converted to SVG instead of PNG, right? There is 
>no way to force e.g. plots to appear in PNG and math in SVG, or is 
>there?

In general yes, but you can choose different extension for the included 
EPS files, for example with the following configuration file:

%%%%%%%%%%%%%%%%%%%%%%
\Configure{xhtml}
\makeatletter
\Configure{graphics*}
   {eps}
   {\openin15=\csname Gin at base\endcsname.png\relax
    \ifeof15
    % put command that converts EPS to PNG here:
       \Needs{"convert \csname Gin at base\endcsname.eps
                       \csname Gin at base\endcsname.png"}%
                            \fi
    \closein15
    \Picture[pict]{\csname Gin at base\endcsname.png}%
   }
\makeatletter
\begin{document}
\EndPreamble
%%%%%%%%%%%%%%%%%%%%%

Note that it converts the EPS file only if the destination PNG file 
doesn't exist yet, so remove the PNG file first when you change the 
conversion parameters.

Best regards,
Michal


More information about the tex4ht mailing list.