[Tex/LaTex] Setting image size in html output of tex4ht

dimensionsgraphicshtmltex4ht

I have a complex document which I'm trying to convert to html with tex4ht and TeXLive under Ubuntu, but I'm not able to coherently control the image size of jpg and eps images. In html output, jpg images get direct reference to original image and seems to display at 1 to 1 pixel, while eps images are converted into a png image whose size is specified in html but seems to display too small. In both (or at least some) cases the original \includegraphics[width=mymeasure]{myimage.jpg-eps} specification isn't respected. I've tried a lot of tricks, configurations and snippets (like this and this) without success.

Is it possible to transfer the size specified for images in LaTeX source to html output?

Here is my MWE:

\documentclass{book}
\usepackage{graphicx}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisici elit:
\begin{centering}
\includegraphics[width=0.5\textwidth]{myimage.jpg}

\includegraphics[width=1.0\textwidth]{myimage.jpg}

\includegraphics[width=0.5\textwidth]{myimage.eps}

\includegraphics[width=1.0\textwidth]{myimage.eps}
\end{centering}
\end{document}

which I compile with htlatex myfile.

And here is the html output.

enter image description here

As you can see, the big (as well as the small) jpg and eps images should have the same (100%) width, whereas they don't (in html, but they do in the pdf).

Also, the two jpg images should have one the half width of the other, whereas they don't (in html, but they do in the pdf).

Best Answer

Edit: This answer is quite old. Look here for a more recent information.


This works correctly for me with TeX Live 2012 on Linux.

\documentclass{book}
\usepackage{graphicx}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisici elit:    

\begin{centering}
\includegraphics[width=.7\textwidth]{myimage.eps}\\
\includegraphics[width=.3\textwidth]{myimage.eps}\\
\includegraphics[width=1.0\textwidth]{myimage.eps}\\
\end{centering}

\the\dimexpr .7\textwidth\relax
\end{document}

Resulting html:

<p class="noindent" ><img 
src="epss0x.png" alt="PIC" class="graphics" width="241.49895pt" height="169.62851pt"  /><!--tex4ht:graphics  
name="epss0x.png" src="myimage.eps"  
--><br />
<img 
src="epss1x.png" alt="PIC" class="graphics" width="103.50105pt" height="72.6991pt"  /><!--tex4ht:graphics  
name="epss1x.png" src="myimage.eps"  
--><br />
<img 
src="epss2x.png" alt="PIC" class="graphics" width="345.0pt" height="242.3276pt"  /><!--tex4ht:graphics  
name="epss2x.png" src="myimage.eps"  
--><br />
</p><!--l. 13--><p class="indent" >   241.49895pt</p>

Note that width=.7\textwidth and \the\dimexpr .7\textwidth\relax are producing the same value: 241.49895pt.

enter image description here

Regarding jpg images, dimension information isn't saved for some reason. But we can use custom config file:

\Preamble{xhtml}
\Configure{graphics*}
        {jpg}
        {%  
           \Picture[pict]{\csname Gin@base\endcsname .jpg
              \space width="\the\dimexpr \expandafter\csname Gin@req@width\endcsname * 1.5"
}%  
         }
\Configure{graphics*}
        {png}
        {%  
           \Picture[pict]{\csname Gin@base\endcsname .png
              \space width="\expandafter\the\csname Gin@req@width\endcsname"
}%  
         }
\begin{document}
\EndPreamble

This will increase seze of the included image by factor os 1.5. Save it as myconf.cfg and compile the source file with

htlatex myfile myconf
Related Question