1

Putting a cross-reference inside a caption prompts a bunch of scary error messages from make4ht, though somehow the example still converts. In a larger document, it would abort or hang.

Take this document, 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}

It compiles fine with pdflatex. Try converting with make4ht ref. I get this console output:

[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

Line 50, referred to in the error messages, is the final line of the second figure.

1 Answer 1

1

TeX4ht writes the contents of the \caption command to an auxiliary file for later use in list of tables, etc. The \ref command as redefined by TeX4ht is not robust, so you will get this error. I will fix this in the sources, so it shouldn't be a problem soon. Until then, you can use this configuration file:

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

It should compile without errors now. This is the result:

enter image description here

2
  • But the <span> HTML tag is missing in the HTML file? How to active this?
    – Balaji
    Aug 12, 2022 at 7:42
  • @Balaji where is it missing?
    – michal.h21
    Aug 12, 2022 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .