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

\usepackage[utf8]{luainputenc}  %is this needed? tried with and without

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
! String contains an invalid utf-8 sequence.
<read 0> 
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.

1 Answer 1


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


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:


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:

  1. Use dvipdfmx driver for graphicx package:


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
    Commented Jul 14, 2015 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .