TL 2021 中的 tex4ht 在使用 lualatex 编译成功后的代码出现错误

TL 2021 中的 tex4ht 在使用 lualatex 编译成功后的代码出现错误

这是一个重现它的 MWE

\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
The following is plot of solution 

\begin{figure}[h]
\centering
\includegraphics[scale=0.45]{example-image}
\caption{$\displaystyle {y \left(x \right) = -\frac{\left(\left(\left\{\begin{array}{cc}
{\mathrm e}^{-2 x} & x \le 1 
\\
 {\mathrm e}^{-2} & 1<x  
\end{array}\right.\right)-7\right) {\mathrm e}^{2 x}}{2}}$
}
\end{figure}                 
\end{document}

以上内容使用 lualatex 编译成功,并以 PDF 格式提供以下内容(以上数学部分由 CAS 自动生成,因此如果它不是最佳的 latex,请不要向我抱怨)。

在此处输入图片描述

tex4ht 中的同一个文件在 TL 2021 中出现此错误

(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)) (./foo3.aux)
[1] [2]
l.16 --- TeX4ht warning --- File `"example-image.xbb"' not found ---
l.16 --- TeX4ht warning --- Cannot determine size of graphic in "example-image.
xbb" (no BoundingBox) ---
! Argument of \im:g has an extra }.
<inserted text>
                \par
l.22 }

?

这是完整的屏幕输出。

(base) >which make4ht
/usr/local/texlive/2021/bin/x86_64-linux/make4ht

(base) >make4ht foo3.tex -a debug "htm,mathjax"

[INFO]    mkparams: Output dir:
[INFO]    mkparams: Compiler: latex
[INFO]    mkparams: Latex options: -jobname=foo3
[INFO]    mkparams: tex4ht.sty: xhtml,htm,mathjax,charset=utf-8
[INFO]    mkparams: tex4ht:  -cmozhtf -utf8
[INFO]    mkparams: build_file: foo3.mk4
[INFO]    mkparams: Output format: html5
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: foo3.tex
[INFO]    mkutils: Load extension       common_domfilters
[INFO]    mkutils: Cannot open config file      foo3.mk4
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param ext
[INFO]    make4ht-lib: Adding:  ext     dvi
[INFO]    htlatex: LaTeX call: latex --interaction=errorstopmode -jobname=foo3   '\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}}\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,htm,mathjax,charset=utf-8,html5.a.b.c.\input "\detokenize{foo3.tex}"'
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2021-06-01>
L3 programming layer <2021-06-01> (./foo3.tex
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/02/12 v1.4n Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/usepackage.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-def/dvips.def)))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/tex4ht.sty
l.855 --- TeX4ht warning --- nonprimitive \everypar ---
--- needs --- tex4ht foo3 ---
(./foo3.tmp) (./foo3.xref)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/mathjax-latex-4ht.4ht
(/usr/local/texlive/2021/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/expl3-hooks.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-dvips.def))
(/usr/local/texlive/2021/texmf-dist/tex/latex/environ/environ.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/trimspaces/trimspaces.sty))))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/article.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/graphicx.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/graphics.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/dvips.4ht
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2021/texmf-dist/tex/generic/tex4ht/html5.4ht)) (./foo3.aux)
[1] [2]
l.16 --- TeX4ht warning --- File `"example-image.xbb"' not found ---
l.16 --- TeX4ht warning --- Cannot determine size of graphic in "example-image.
xbb" (no BoundingBox) ---
! Argument of \im:g has an extra }.
<inserted text>
                \par
l.22 }

?

知道为什么它只在 tex4ht 中失败吗?是否有解决方法?

答案1

尝试以下配置文件:

\Preamble{xhtml} 
\fixmathjaxtoc\begin
\fixmathjaxtoc\end
\fixmathjaxtoc\\
\Css{p + figcaption{margin-top: 1em;}}
\begin{document} 
\EndPreamble

问题是\caption命令的内容需要特别待遇,因此您可以将其放在、和\protect之前,或者您可以使用TeX4ht 为此目的提供的命令。\begin\end\\\fixmathjaxtoc

我还添加了 CSS 代码以在图像和标题之间插入垂直空间,并.xbb使用 为图像创建了文件ebb -x example-image.png。这对于正确计算图像大小是必需的。

结果如下:

在此处输入图片描述

相关内容