1

I am trying to compile a latex document that includes lua code with tex4ht. I also make4ht to for building latex to html.

According to help on make4ht the option --lua can be used to compile with lualatex.

The compilation works ok, except when an .png image is included in the document, then it gives an error. Here is a MWE

\documentclass{article}
\usepackage[utf8]{luainputenc}  %is this needed? tried with and without
\usepackage{graphicx}
\begin{document}
test 
\includegraphics{some_image.png}
\end{document}

when the above is compiled using make4ht -u foo5.tex then it compiles OK. But when compiled using

make4ht --lua  -u foo5.tex

then it fails:

Compiler:   dvilualatex
Latex options:   -jobname=foo5 
tex4ht.sty :    xhtml,,charset=utf-8
(/usr/local/texlive/2015/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2015/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo5.aux)
! String contains an invalid utf-8 sequence.
<read 0> 
   �PNG
l.6 \includegraphics{some_image.png}

I also tried

 make4ht --lua  foo5.tex

The problem shows only when including a .png image.

using TL 2015 64 bits on Linux mint.

3

This error probably doesn't have anything in common with tex4ht. Try to compile following file with dvilualatex:

\documentclass{article}
\usepackage[]{graphicx}
\begin{document}
\includegraphics{someimage.png}
\end{document}

The error message is the same.

The problem is that \includegraphics tries to determine the image bounding box and it reads the file for that information, which works in old 8-bit TeX engines, but it may confuse unicode engines as the image contents can contain values which aren't supported unicode characters. An error is shown for every unsupported character code and this easily exceeds error limit, causing the compilation to fail.

Because png images aren't supported in dvi mode, it isn't really supposed to work, but when you try to include png image in LaTeX, some more meaningful error message is shown:

! LaTeX Error: Cannot determine size of graphic in someimage.png (no BoundingBox).

and at least the document compiles. Maybe this behavior should be used also with dvilualatex.

To fix this issue, you can use two ways:

  1. Use graphics rules. Try following config file:

    \Preamble{xhtml}
    \DeclareGraphicsExtensions{.png,.jpg,.gif}
    \DeclareGraphicsRule{.png}{bmp}{.xbb}{}
    \DeclareGraphicsRule{.jpg}{bmp}{.xbb}{}
    \DeclareGraphicsRule{.gif}{bmp}{.xbb}{}
    \begin{document}
    \EndPreamble
    

if you create .xbb file for each image with

ebb -x imagename

then the included images will have even correct dimensions. You can also stop using image extension in the \includegraphics, just use:

\includegraphics{some_image}
  1. Use dvipdfmx driver for graphicx package:

     \usepackage[dvipdfmx]{graphicx}
    

note that you can't use it when you compile to pdf. so you should include it conditionally. Or better, use make4ht feature to insert LaTeX code before document inclusion. Use this simple mk4 file:

  Make:htlatex {packages = "\\RequirePackage[dvipdfmx]{graphicx}"}

so you don't have to modify your document now. We have to use \RequirePackage instead of \usepackage because the code is executed before \documentclass.

Regarding luainputenc: if you don't need unicode characters, you don't have to use it. Try to compile the document without the package and see if everything works.

  • thanks very much! I used your second method, modified my make4ht build file using \\RequirePackage[dvipdfmx]{graphicx} and it works very well. Now the lua code works and the result shows in the HTML which is really very good. – Nasser Jul 14 '15 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.