Tex4ht: Non-existent graphic files in the html-output

Having run htlatex on a LaTeX file (without any configuration files), I've got a lot of references to non-existent graphic files in the html-output. Usually these non-existent graphic files come in pairs, e.g.

< img src="sample23x.png" alt="PICT" >

< img src="sample28x.png" alt="PICT" >

What causes that, and how that can be avoided?

An example (AMS-LaTeX):

\documentclass[12pt,reqno]{amsart}

\usepackage{pdfpages}

\begin{document}

$$\begin{pmatrix} x \\ y \\ u(x,y) \end{pmatrix} \in \Lambda \subseteq \mathrm{dom}(a) \cap \mathrm{dom}(b) \cap \mathrm{dom}(c)$$

\end{document}


The grapic file for this formula is produced, but the html-file contains references for two more, which are non-existent. Once pdfpages is removed, everything seems to be OK.

• We need full example of source code that cause this behaviour – michal.h21 Dec 2 '16 at 19:30
• Please see an example above. – Olod Dec 2 '16 at 20:35
• is is caused by pdfpages package. do you include PDF files in your document? – michal.h21 Dec 2 '16 at 21:48
• Yes, I did. Now I'll do without. Thanks for your input. – Olod Dec 2 '16 at 23:21

The blank images are caused by the pdfpages package, respective eso-pic, which is called by pdfpages. eso-pic is used for placing objects at arbitrary places on the page, it uses picture mode for this task. Unfortunately, the picture is converted to image by tex4ht, even when it's empty.

There is also another problem: \includepdf command doesn't work. So we have two issues to fix. First one can be fixed by preventing the eso-pic package from loading, the second one with some patches for pdfpages.

Here is modified version of your TeX file:

\documentclass[12pt,reqno]{amsart}

\makeatletter
\ifdefined\HCode
\@nameuse{:dontusepackage}{eso-pic}
\newif\ifESO@texcoord
\fi
\usepackage{pdfpages}
\makeatother
\begin{document}

$$\begin{pmatrix} x \\ y \\ u(x,y) \end{pmatrix} \in \Lambda \subseteq \mathrm{dom}(a) \cap \mathrm{dom}(b) \cap \mathrm{dom}(c)$$

\includepdf[pages={1,2,3}]{pdfsample.pdf}
\includegraphics[page=1]{pdfsample.pdf}

\end{document}


The important code is:

\ifdefined\HCode
\@nameuse{:dontusepackage}{eso-pic}
\newif\ifESO@texcoord
\fi


It prevents eso-pic from loading and some basic macros used by pdfpages are defined. For pdfpages configuration, we can create pdfpages.4ht configuration file:

\let\pdf@page\relax
\define@key{Gin}{page}[]{\edef\pdf@page{\the\numexpr #1-1\relax}}

\def\AM@findfile#1{%
\AM@findfile@i{#1}{pdf}%
\AM@findfile@ii{#1}%
}
\catcode\:=12
\renewcommand\AM@output[1]{%
\@for\@pages:=\AM@pagestemp\do{\includegraphics[page=\@pages]{\AM@currentdocname}}
}
\catcode\:=11

\AtBeginDocument{
\Configure{graphics*}
{pdf}
{
\ifx\pdf@page\relax\def\pdf@page{0}\fi
\def\current@pdf@file{\Gin@base.pdf[\pdf@page]}
\def\current@png@file{\Gin@base-\pdf@page.png}%
\expandafter\Needs\expandafter{"convert \current@pdf@file\space %\csname Gin@base\endcsname.pdf
\current@png@file"}%
\Picture[pict]{\current@png@file}%
\special{t4ht+@File: \csname current@png@file\endcsname}
\let\pdf@page\relax
}
}
\Hinput{pdfpages}
\endinput


In this file, first of all we declare page option for \includegraphics command, because it isn't defined in the DVI mode:

\let\pdf@page\relax
\define@key{Gin}{page}[]{\edef\pdf@page{\the\numexpr #1-1\relax}}


We then can request inclusion of particular pages:

\renewcommand\AM@output[1]{%
\@for\@pages:=\AM@pagestemp\do{\includegraphics[page=\@pages]{\AM@currentdocname}}
}


\@for is internal LaTeX command which can be used for looping over comma separated lists. In this case we loop over \AM@pagestemp, where requested pages are stored.

Finally, we need to add support for PDF images for tex4ht:

\AtBeginDocument{
\Configure{graphics*}
{pdf}
{
\ifx\pdf@page\relax\def\pdf@page{0}\fi
\def\current@pdf@file{\Gin@base.pdf[\pdf@page]}
\def\current@png@file{\Gin@base-\pdf@page.png}%
\expandafter\Needs\expandafter{"convert \current@pdf@file\space %\csname Gin@base\endcsname.pdf
\current@png@file"}%
\Picture[pict]{\current@png@file}%
\special{t4ht+@File: \csname current@png@file\endcsname}
\let\pdf@page\relax
}
}


\pdf@page contains the requested page, this macro is stored by \includegraphics page option. We can convert particular pdf page using Imagemagick's convert command in the form:

 convert filename.pdf[page number] filename.png


The converted image is then included using \Picture command. \special is used to register the output file in tex4ht, so it can be copied to the destination directory, for example.

• Michal, you are thorough as always. Thank you very much indeed. – Olod Dec 6 '16 at 17:27
• @Olod you are welcome. I will add support for PDF page inclusion to tex4ht itself soon – michal.h21 Dec 6 '16 at 19:16