2

This MWE compiles OK with lualatex but fails in tex4ht once hyperref is added.

\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}

And now

 make4ht -ulm default -a debug  foo.tex "mathjax,htm"

gives

/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$}
                                  
? 

Removing hyperref it compiles clean. (ps. I used test image above so it can compile as is). Same error is generated with a real image file.

Is there a workaround for this?

TL 2022 on Linux

Fyi, link to ticket add.

3
  • Just out of curiosity: Why do you write y^{\prime \prime}, when y'' is both simpler and clearer? What is the purpose of writing \left(t \right) instead of (t)?
    – Mico
    Dec 25, 2022 at 3:43
  • @Mico the math is auto-generated by Maple. I just put the Latex translation of the equation there. This is how all CAS systems generate Latex. Same for left and right.
    – Nasser
    Dec 25, 2022 at 4:14
  • Hope \caption[]{...} also will works, but not yet tested
    – GowriSaro
    Dec 26, 2022 at 14:49

1 Answer 1

3

This is caused by the fact that \begin and \end are redefined by TeX4ht, but not as robust commands. When you load Hyperref, expanded contents of \caption are saved in a macro for further processing, which leads to this error. The fix is to declare \begin and \end as robust commands. The fixed latex.4ht is too huge to be posted here, but you can use this config file:

\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

I will also fix it in the TeX4ht sources, so it will be unnecessary after TeX Live update soon.

This is the result:

enter image description here

You must log in to answer this question.

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