标题中的引用,make4ht 错误

标题中的引用,make4ht 错误

在标题内放置交叉引用会提示一堆可怕的错误消息make4ht,尽管该示例仍然转换。在较大的文档中,它会中止或挂起。

以这个文件为例ref.tex

\documentclass{article}
\begin{document}
\section{An Airplane}
See figure \ref{fig:airplane}.

\begin{figure}
    \caption{Airplane}
    \label{fig:airplane}
    \begin{center}
    \begin{picture}(200,100) % thanks, @DavidCarlisle
        \put(30,40){\line(1,0){150}}
        \put(30,40){\line(0,1){60}}
        \put(30,100){\line(1,0){20}}
        \put(50,100){\line(1,-4){10}}
        \put(60,60){\line(1,0){100}}
        \put(160,60){\line(1,-1){20}}
        \put(100,50){\line(0,-1){80}}
        \put(130,50){\line(0,-1){80}}
        \put(100,-30){\line(1,0){30}}
        \put(100,61){\line(0,1){49}}
        \put(130,61){\line(0,1){49}}
        \put(100,110){\line(1,0){30}}
    \end{picture}
    \end{center}
\end{figure}

\section{A Smaller Airplane}

See figure \ref{fig:airplane2}.

\begin{figure}
    \caption{Smaller airplane (cf. figure \ref{fig:airplane})}
    \label{fig:airplane2}
    \begin{center}
    \begin{picture}(100,50)
        \put(15,20){\line(1,0){75}}
        \put(15,20){\line(0,1){30}}
        \put(15,50){\line(1,0){10}}
        \put(25,50){\line(1,-4){5}}
        \put(30,30){\line(1,0){50}}
        \put(80,30){\line(1,-1){10}}
        \put(50,25){\line(0,-1){40}}
        \put(65,25){\line(0,-1){40}}
        \put(50,-15){\line(1,0){15}}
        \put(50,30){\line(0,1){25}}
        \put(65,30){\line(0,1){25}}
        \put(50,55){\line(1,0){15}}
    \end{picture}
    \end{center}
\end{figure}

\end{document}

使用 可以很好地编译pdflatex。尝试使用 进行转换make4ht ref。我得到了以下控制台输出:

[37m[STATUS]  [0mmake4ht: Conversion started
[37m[STATUS]  [0mmake4ht: Input file: ref
[31m[ERROR]   [0mhtlatex: Compilation errors in the htlatex run
[31m[ERROR]   [0mhtlatex: Filename  Line    Message
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Incomplete \iffalse; all text was ignored after line 50.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: Compilation errors in the htlatex run
[31m[ERROR]   [0mhtlatex: Filename  Line    Message
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Incomplete \iffalse; all text was ignored after line 50.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: Compilation errors in the htlatex run
[31m[ERROR]   [0mhtlatex: Filename  Line    Message
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Incomplete \iffalse; all text was ignored after line 50.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[31m[ERROR]   [0mhtlatex: ./ref.tex     50   Forbidden control sequence found while scanning text of \write.
[37m[STATUS]  [0mmake4ht: Conversion finished

错误消息中提到的第 50 行是第二张图的最后一行。

答案1

TeX4ht 将命令的内容写入\caption辅助文件,以便稍后在表格列表等中使用。TeX4ht\ref重新定义的命令不够强大,因此您会收到此错误。我将在源代码中修复此问题,因此它不会很快成为问题。在此之前,您可以使用此配置文件:

\Preamble{xhtml}
\catcode`\:=11
\DeclareDocumentCommand\:ref{s}{\IfBooleanTF{#1}{\Protect\::ref}{\Protect\::ref}}
\catcode`\:=12
\begin{document}
\EndPreamble

现在应该可以编译了,没有错误。结果如下:

在此处输入图片描述

相关内容