1

I found a case, when this MWE

\documentclass[11pt]{scrbook}%
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.95\textwidth]{image.png}
\end{document}

Gives the error

(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux)

! Package graphics Error: Division by 0.

See the graphics package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.4 ...ludegraphics[width=0.95\textwidth]{image.png}                                                  
? 

This happens on some image files. And also happens when I use the make4ht main.mk4 configuration file, and also happens when I use the width specification only. main.mk4 does this

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

So I assume this has something to do with it, but not sure. The above MWE compiles OK with lualatex and pdflatex. May be there is something wrong with the image file, but why the error only with make4ht?

This is the command which gives the error

   make4ht  -e main.mk4 foo.tex

The image is a picture of a book. Small png file

>ls -l *.png
-rwxrwxrwx 1 me me 5421 Jul 11 07:31 image.png

Mathematica graphics

I put the images file (.png) and main.mk4 file on my site here if someone likes to try it and see if they get same error. I am using TL 2016 on Linux mint 17.3.

What causes this error? And why only tex4ht reports it? The same file work ok using same commands on other png images. It is only that few cause this problem and only with tex4ht.

Copy of main.mk4 here also (part of make4ht files. I did not write this)

Make:add("dvisvgm","dvisvgm -v1 -n -c 1.15,1.15 -p 1- ${input}.idv")
Make:htlatex {packages = "\\RequirePackage[dvipdfmx]{graphicx}"}
local max_count = 10
local image_format = "${input}-${zeroes}${page}.${ext}"
local oneimage_format = "${input}.${ext}"


local function file_exists(fn)
  local f = io.open(fn,"r")
  if f ==  nil then return false else f:close() return true end
end

local function locate_file(par,ext, count)
  local count = count or 0
  par.ext = ext
  local zeroes = string.rep("0",count)
  par.zeroes = zeroes
  if count > max_count then 
        local one = oneimage_format % par
        if file_exists(one) then
            return one
        else
          return false, "max_count exceeded" 
        end
    end
  local fn = image_format % par
  if file_exists(fn) then 
    return fn
  else 
    return locate_file(par, ext, count+1)
  end
end

Make:htlatex{}
Make:htlatex{}
Make:htlatex{}
Make:tex4ht{}
Make:t4ht{}

Make:dvisvgm{}
Make:image("svg$",function(arg)
   arg.input = arg.source:gsub(".idv$","")
   local fn,msg = locate_file(arg, "svg")  
   if not fn then
     print("Image processing error: "..msg)
   else
     arg.filename = fn
     local cmd = "mv ${filename} ${output}" % arg
     print(cmd)
     os.execute(cmd)
   end
 end
)

Complete console output:

>make4ht  -e main.mk4 foo.tex
Output dir:     
Compiler:   latex
Latex options:   -jobname=foo 
tex4ht.sty :    xhtml,
tex4ht  
build_file  main.mk4
Using build file    main.mk4
setting param correct_exit
Adding:     packages    \RequirePackage[dvipdfmx]{graphicx}
setting param correct_exit
setting param correct_exit
setting param correct_exit
setting param ext
setting param ext
Adding:     ext dvi
LaTeX call: latex  -jobname=foo  '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}\RequirePackage[dvipdfmx]{graphicx}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,.a.b.c.\input foo'
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2016/03/31> patch level 2
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(./foo.tex
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbook.cls
Document Class: scrbook 2016/06/14 v3.21 KOMA-Script document class (book)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrlfile.sty
Package scrlfile, 2016/06/14 v3.21 KOMA-Script package (loading files)
                  Copyright (C) Markus Kohm

))) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/typearea.sty
Package typearea, 2016/06/14 v3.21 KOMA-Script package (type area)
                  Copyright (C) Frank Neukam, 1992-1994
                  Copyright (C) Markus Kohm, 1994-

)) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/usepackage.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/dvipdfmx-def/dvipdfmx.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/scrbook.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/graphicx.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/graphics.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux)

! Package graphics Error: Division by 0.

See the graphics package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.4 ...degraphics[width=0.95\textwidth]{image.png}

? 

When compiling without using main.mk4 as in make4ht foo.tex, there are messages such as

l.4 --- TeX4ht warning --- File `image.xbb' not found ---
l.4 --- TeX4ht warning --- Cannot determine size of graphic in image.xbb (no Bo
undingBox) ---

But no division by zero error This only shows when using main.mk4 which uses [dvipdfmx]{graphicx}


Update:

I just want to make it clear that this division by zero shows on this one png. I have many more png images that are processed with same code with no error. I have been using tex4ht with png images for years. Here is example of another random png image, it compiles OK with same command and same code

\documentclass[11pt]{scrbook}%
 \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{image2.png}
\end{document}

Full console output:

>cat foo.tex
\documentclass[11pt]{scrbook}%
 \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{image2.png}
\end{document}

>ls -l image2.png
-rwxrwxrwx 1 me me 709199 Jul 11 11:29 image2.png

>make4ht  -e main.mk4 foo.tex
Output dir:     
Compiler:   latex
Latex options:   -jobname=foo 
tex4ht.sty :    xhtml,
tex4ht  
build_file  main.mk4
Using build file    main.mk4
setting param correct_exit
Adding:     packages    \RequirePackage[dvipdfmx]{graphicx}
setting param correct_exit
setting param correct_exit
setting param correct_exit
setting param ext
setting param ext
Adding:     ext dvi
LaTeX call: latex  -jobname=foo  '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}\RequirePackage[dvipdfmx]{graphicx}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,.a.b.c.\input foo'
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=latex)
 restricted \write18 enabled.
 .....
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/graphics.4ht
(./foo.aux) [1] (./foo.aux) )
....
Output written on foo.dvi (1 page, 10044 bytes).
[1 file foo.html
.....
 file foo.css
 file foo.tmp
]
Execute script `foo.lg'
Make4ht: t4ht  -p "foo.dvi"
----------------------------
t4ht.c (2012-07-25-19:28 kpathsea)
t4ht -p 
  foo.dvi 
(/usr/local/texlive/2016/texmf-dist/tex4ht/base/unix/tex4ht.env)
Entering foo.lg
Entering foo.css
Entering foo.tmp
Make4ht: dvisvgm -v1 -n -c 1.15,1.15 -p 1- foo.idv
Make4ht: tex4ht  "foo" can be executed only 1x
Make4ht: t4ht  -p "foo.dvi" can be executed only 1x
Parse LG
parse_lg process file: foo.html
outdir: 
parse_lg process file: foo.css
outdir: 
parse_lg process file: foo.tmp
tmp file
parse_lg process file: image2.png
outdir: 

No error. I put the image2.png in same folder here with the other png file

Mathematica graphics


Update 2

Based on comment. I made xbb file for the image which causes division by zero. and I still get division by zero. Here it is

>ebb -x image.png
>ls image.xbb
image.xbb

>cat image.xbb
%%Title: image.png
%%Creator: extractbb 20160307
%%BoundingBox: 0 0 0 0
%%HiResBoundingBox: 0.000000 0.000000 0.198206 0.311246
%%CreationDate: Mon Jul 11 11:58:55 2016

>cat foo.tex
\documentclass[11pt]{scrbook}%
 \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{image.png}
\end{document}

>make4ht  -e main.mk4 foo.tex
Output dir:     
Compiler:   latex
Latex options:   -jobname=foo 
tex4ht.sty :    xhtml,
tex4ht  
build_file  main.mk4
Using build file    main.mk4
setting param correct_exit
Adding:     packages    \RequirePackage[dvipdfmx]{graphicx}
setting param correct_exit
setting param correct_exit
setting param correct_exit
setting param ext
setting param ext
Adding:     ext dvi
LaTeX call: latex  -jobname=foo  '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}\RequirePackage[dvipdfmx]{graphicx}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,.a.b.c.\input foo'
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2016/03/31> patch level 2
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(./foo.tex
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbook.cls
Document Class: scrbook 2016/06/14 v3.21 KOMA-Script document class (book)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrlfile.sty
Package scrlfile, 2016/06/14 v3.21 KOMA-Script package (loading files)
                  Copyright (C) Markus Kohm

))) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/typearea.sty
Package typearea, 2016/06/14 v3.21 KOMA-Script package (type area)
                  Copyright (C) Frank Neukam, 1992-1994
                  Copyright (C) Markus Kohm, 1994-

)) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/usepackage.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/dvipdfmx-def/dvipdfmx.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2016/texmf-dist/tex/generic/luatex85/luatex85.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/scrbook.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/graphicx.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/graphics.4ht
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux)

! Package graphics Error: Division by 0.

See the graphics package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \includegraphics[width=\textwidth]{image.png}

? 
  • try to create the .xbb files for the images using ebb -x *.png – michal.h21 Jul 11 '16 at 16:55
  • @michal.h21 I just did. And still get division by zero. Will update with this information so it is all in one place. AGain, I never had to do any of this before. (i.e. make xbb) – Nasser Jul 11 '16 at 16:57
  • @michal.h21 it might be just that there is something in this png images which tex4ht do not like. It is old image of a book cover. – Nasser Jul 11 '16 at 17:05
2

You would get that just using latex, nothing to do with tex4ht, latex gives the warning that you quote Cannot determine size of graphic in image.xbb

It has no information about the original size of the image so sets it to zero, so scaling then fails.

  • But this error do not show up on other png files. I have thousands of png images and never get an error with the same exact code. They are png images. I'll post examples. Just need few minutes. I have been using tex4ht with png images for years, same code. No division by zero. Why this image? Just tried another png image, same code. No error. – Nasser Jul 11 '16 at 16:24
  • @Nasser does the script make image.xbb files in the working cases? – David Carlisle Jul 11 '16 at 16:32
  • No it does not. >ls *.xbb ls: cannot access *.xbb: No such file or directory If I have seen this error before, I would know. But I use tex4ht with png images all day. This error is new and I have not seen before. – Nasser Jul 11 '16 at 16:39
2

I found the problem. The image had resolution of 32767.00 pixels per inch.

Mathematica graphics

Changing it to 300 pixels/inch and compiling with tex4ht, same command, same latex file, now there is no error:

Mathematica graphics

>rm *.xbb
rm: cannot remove ‘*.xbb’: No such file or directory

>cat foo.tex
\documentclass[11pt]{scrbook}%
 \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{image.png}
\end{document}

>make4ht --lua -e main.mk4 foo.tex
Output dir:     
Compiler:   dvilualatex
Latex options:   -jobname=foo 
tex4ht.sty :    xhtml,
tex4ht  
build_file  main.mk4
Using build file    main.mk4
setting param correct_exit
     outdir: 
.....
parse_lg process file: foo.tmp
tmp file
parse_lg process file: image.png
outdir: 

No error! So the problem was the image had a bad pixels per inch, and for some reason, this only cause tex4ht to give division by zero and not pdflatex.

Case closed. Next time this happens, I will check pix/inch first thing.

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.