我发现了一个案例,当这个 MWE
\documentclass[11pt]{scrbook}%
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.95\textwidth]{image.png}
\end{document}
给出错误
(/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}
?
这发生在一些图像文件。当我使用 make4ht main.mk4 配置文件时也会发生这种情况,当我width
仅使用规范时也会发生main.mk4
这种情况。
Make:htlatex {packages = "\\RequirePackage[dvipdfmx]{graphicx}"}
所以我认为这与它有关,但不确定。上面的 MWE 使用 lualatex 和 pdflatex 编译成功。可能是图像文件有问题,但为什么只有 出现错误make4ht
?
这是给出错误的命令
make4ht -e main.mk4 foo.tex
图片是一本书的图片。小 png 文件
>ls -l *.png
-rwxrwxrwx 1 me me 5421 Jul 11 07:31 image.png
我把图片文件(.png)和main.mk4
文件放在我的网站在这里如果有人想尝试一下,看看他们是否会遇到相同的错误。我在 Linux mint 17.3 上使用 TL 2016。
是什么原因导致了这个错误?为什么只有 tex4ht 会报告这个错误?在其他 png 图像上使用相同的命令,相同的文件可以正常工作。只有少数图像会导致此问题,并且只有tex4ht
。
这里也复制了 main.mk4(make4ht 文件的一部分。这不是我写的)
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
)
完整控制台输出:
>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}
?
编译时没有使用main.mk4
如make4ht foo.tex
,有如下消息
l.4 --- TeX4ht warning --- File `image.xbb' not found ---
l.4 --- TeX4ht warning --- Cannot determine size of graphic in image.xbb (no Bo
undingBox) ---
但无除以零的错误这仅显示何时使用main.mk4
哪些用途[dvipdfmx]{graphicx}
更新:
我只想明确说明,这个除以零的结果显示在这张 png 上。我还有更多使用相同代码处理的 png 图像,没有错误。多年来,我一直在使用 tex4ht 处理 png 图像。这是另一个随机 png 图像的示例,它使用相同的命令和相同的代码编译成功
\documentclass[11pt]{scrbook}%
\IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{image2.png}
\end{document}
完整控制台输出:
>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:
没有错误。我image2.png
把此处为同一文件夹与其他 png 文件
更新 2
根据评论。我为导致除以零的图像制作了 xbb 文件。但我仍然得到除以零的结果。这里是
>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}
?
答案1
你会得到这个结果,只需使用 latex,与 tex4ht 无关,latex 会给出你引用的警告Cannot determine size of graphic in image.xbb
它没有关于图像原始大小的信息,因此将其设置为零,缩放失败。