[tex4ht] TeX4ht warning --- Cannot determine size of graphic in svg graphics. Does tex4ht support bounding box on svg?

Nasser M. Abbasi nma at 12000.org
Sat May 16 23:50:13 CEST 2015


On 5/16/2015 4:36 PM, Karl Berry wrote:
>      TeX4ht needs .eps format of
>      the figure since it works with dvips graphics driver and hence cannot
>      accept any other graphics file format.
>
> I use png and jpg with tex4ht all the time.  tex4ht.env has rules to
> convert them on the fly (highly problematic in itself, but anyway).
>

I used to use png also with tex4ht for images. But png is not
vector format so does not work as well as svg for different
resolutions of the web page. So I switched to SVG now.

> I see a rule in tex4ht.env for svg using dvips (??) and then pstoedit.
> Maybe that is what failed for Nasser, or maybe it never got run.  (It is
> darn hard to figure out what parts of tex4ht.env are executed on any
> given run, so far as I've ever been able to discern.  Maybe I am missing
> it in the logs ...)
>
> k

May be. I gave up trying to uderstand tex4ht.env long time ago with
having to add or remove a space and trying to figure which section
is actually active or which is not.

I am now making a small note to summarize all of this, will add it
to my tex4ht cheat sheet.  But basically the steps I use now are:

1. Generate PDF for the image (from the external graphics program, such
as visio or anyother tool. All support saving as pdf now.
2. Crop the PDF if needed to remove extra space around image
3. Use pdf2svg  to generate .svg from the .pdf
4. Use pdf2eps  to generate .eps from .pdf
5. Use this in Latex to include the graphics

\ifdefined\HCode
  \includegraphics[width=0.2\paperwidth]{p1.eps}
\else
  \includegraphics[width=0.5\paperwidth]{p.pdf}
\fi

6. Make sure to have .cfg file with these in it:

\Configure{Picture}{.svg}
\makeatletter
\Configure{graphics*}
{svg}
{
   {\Configure{Needs}{File: \Gin at base.svg}\Needs{}}
   \Picture[\csname a:GraphicsAlt\endcsname]
     {\csname Gin at base\endcsname.svg \csname a:Gin-dim\endcsname}
}
\makeatother


% Thanks to CVR for this below
\makeatletter
\Configure{graphics*}
   {eps}
   {\Picture[pict]{\csname Gin at base\endcsname.svg
        width="\expandafter\the\csname
           Gin at req@width\endcsname"
            height="\expandafter\the\csname
            Gin at req@height\endcsname"
       }%
    }
\makeatother

7. Now compile using htlatex using the above .cfg file

Now the HTML page will use the .svg image in it with
correct width/height and will resize well since it is
vector format and keep sharp at different resolutions.

--Nasser







More information about the tex4ht mailing list