![加载 hyperref 包后,tex4ht 无法在标题中包含带有数学符号的图像](https://linux22.com/image/459043/%E5%8A%A0%E8%BD%BD%20hyperref%20%E5%8C%85%E5%90%8E%EF%BC%8Ctex4ht%20%E6%97%A0%E6%B3%95%E5%9C%A8%E6%A0%87%E9%A2%98%E4%B8%AD%E5%8C%85%E5%90%AB%E5%B8%A6%E6%9C%89%E6%95%B0%E5%AD%A6%E7%AC%A6%E5%8F%B7%E7%9A%84%E5%9B%BE%E5%83%8F.png)
这个 MWE 使用 lualatex 编译成功,但hyperref
添加后在 tex4ht 中失败。
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\begin{figure}
\includegraphics[width=0.5\textwidth]{example-image-a}
\caption{Phase plot $y^{\prime \prime}\left(t \right)+9 y \left(t \right)-\left(\left\{\begin{array}{cc}
8 \sin \left(t \right) & 0<t <\pi
\\
0 & \pi <t
\end{array}\right.\right) = 0$}
\end{figure}
\end{document}
现在
make4ht -ulm default -a debug foo.tex "mathjax,htm"
给出
/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
(./foo.aux) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
[1] [2]
l.9 --- TeX4ht warning --- File `"example-image-a.xbb"' not found ---
l.9 --- TeX4ht warning --- Cannot determine size of graphic in "example-image-a
.xbb" (no BoundingBox) ---
! Undefined control sequence.
<argument> \EndPicture
l.14 \end{array}\right.\right) = 0$}
?
删除hyperref
它可以编译干净。(注:我使用了上面的测试图像,因此它可以按原样编译)。使用真实图像文件会产生相同的错误。
有办法解决这个问题吗?
Linux 上的 TL 2022
供参考,票证链接添加。
答案1
这是因为TeX4ht 重新定义了\begin
和\end
,但这些命令并不是健壮的。加载 Hyperref 时,的扩展内容\caption
会保存在宏中以供进一步处理,这会导致此错误。修复方法是将\begin
和声明\end
为健壮的命令。修复内容latex.4ht
太大,无法在此处发布,但您可以使用此配置文件:
\Preamble{xhtml}
\catcode`\:=11
\makeatletter
\DeclareRobustCommand\begin[1]{\csname @begin:#1\endcsname
\choose:begin
{\let\choose:begin\@firstoftwo \ifx \EndPicture\:Undef
\PushStack\envn:list\n:list \SaveEverypar
\fi
\let\chk:pic\EndPicture
\ifx \EndPicture\:UnDef \list:save
\let\after:end\empty \csname before:begin#1\endcsname \fi
%
\UseHook{env/#1/before}%
\@ifundefined{#1}%
{\def\reserved@a{\@latex@error{Environment #1 undefined}\@eha}}%
{\def\reserved@a{%
\def\@currenvir{#1}%
\edef\@currenvline{\on@line}%
\ifx \EndPicture\:UnDef
\ifx \this:listConfigure\empty
\null:listConfigure \csname on#1:list\endcsname \fi
\fi
%
\@execute@begin@hook{#1}%
\csname #1\endcsname
%
%
}}%
\global\@ignorefalse
\begingroup
\@endpefalse
\reserved@a
}%
{\o:begin:{#1}}}
\DeclareRobustCommand\end[1]{\choose:begin
{%\IgnoreIndent
\ifvmode \ifx \EndPicture\:UnDef
\def\:temp{\def\:temp{%
\def\:temp{\IgnorePar
\ifx \:tempa\hline \expandafter\\\else\fi
}%
\futurelet\:tempa\:temp
}%
%
\expandafter\expandafter\expandafter\:temp}%
\expandafter\:temp
\fi
\fi
\UseHook{env/#1/end}%
\csname end#1\endcsname%
\@checkend{#1}%
\aftergroup\recall:afterend
\expandafter\endgroup\if@endpe\@doendpe\fi
\UseHook{env/#1/after}%
\ifx \chk:pic\:UnDef
\csname after:end\endcsname
\expandafter\let\csname after:end\endcsname\:UnDef
%
\PopStack\envn:list\:tempb
\ifnum \:tempb=\n:list \else
\def\:temp{#1}\def\:tempa{thebibliography}\ifx \:temp\:tempa
\else\:warning{\string\SaveEverypar's: \:tempb\space at
\string\begin{#1} and \n:list\space \string\end{#1}}%
\fi \fi
%
\list:recall
\else
\let\chk:pic\:UnDef
\fi
\if@ignore\global\@ignorefalse\ignorespaces\fi
}%
{\o:end:{#1}}}
\makeatother
\catcode`\:=12
\begin{document}
\EndPreamble
我还将在 TeX4ht 源中修复它,因此 TeX Live 更新后它就不再需要了。
结果如下: