2

This is related to tex4ht fails on including image with math in caption after loading hyperref package but fails under new conditions.

This is summary of what is going on. There was a bug in the above link where tex4ht failed when adding math in the caption of the image when hyperref was loaded. Thanks to michal.h21 this is fixed now in latest TL as I no longer get the error using the MWE in the above, which is

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

Using the command

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

No errors. Great. But once I added \centering, similar error came back from the same location of the file

\documentclass{article}
\usepackage{amsmath} 
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}

\begin{figure}
\centering
\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 the same command

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

Gives

[INFO]    mkparams: Output dir: 
[INFO]    mkparams: Compiler: dvilualatex
[INFO]    mkparams: Latex options: -jobname='foo'  
[INFO]    mkparams: tex4ht.sty: xhtml,mathjax,htm,charset=utf-8
[INFO]    mkparams: tex4ht:  -cmozhtf -utf8
[INFO]    mkparams: build_file: foo.mk4
[INFO]    mkparams: Output format: html5
[STATUS]  make4ht: Conversion started
....
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/unicode.4ht)
(/usr/local/texlive/2022/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/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)17 nil

[1] [2]
l.10 --- TeX4ht warning --- File `"example-image-a.xbb"' not found ---
l.10 --- TeX4ht warning --- Cannot determine size of graphic in "example-image-
a.xbb" (no BoundingBox) ---
! Argument of \@caption has an extra }.
<inserted text> 
\par 
l.15 \end{array}\right.\right) = 0$}
                                  
? 

Which is the similar error to the one fixed in the earlier question linked above which was

! Undefined control sequence.
<argument> \EndPicture 
            
l.14 \end{array}\right.\right) = 0$}

The above example compiles OK with lualatex giving

enter image description here

Any workaround for this new problem as I use \centering in my code.

TL 2022 Updated just 1/2 hr ago.

>which make4ht
/usr/local/texlive/2022/bin/x86_64-linux/make4ht
>make4ht --version
make4ht version v0.3l
>which tex4ht
/usr/local/texlive/2022/bin/x86_64-linux/tex4ht

Update

Thanks for the comment below by MadyYuvi, using \caption[short caption]{long caption with the math} makes tex4ht not give compile error. Here is MWE

\documentclass{article}
\usepackage{amsmath} 
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{example-image-a}
\caption[Phase plot]{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}

Now it compiles OK using same command. Still, I think tex4ht should not give an error as before, but this can be used as a workaround for now.

Link to tracking

3
  • 2
    If you don't want the caption in LOF, hope then \caption[]{...} will works, but not sure, just a try
    – MadyYuvi
    Dec 30, 2022 at 5:14
  • 2
    @MadyYuvi thanks for the suggestion. Yes this is a good workaround. Will add it as example. But I think tex4ht should still work with the math in there.
    – Nasser
    Dec 30, 2022 at 5:24
  • Thanks for your kind words, Yes I agree with you
    – MadyYuvi
    Dec 30, 2022 at 5:28

1 Answer 1

4

The issue is that the \centering command redefines \\, and this fails with TeX4ht's support for Nameref (which is required by Hyperref). This can be fixed using this config file:

\Preamble{xhtml}
\catcode`\:=11
\makeatletter
\long\def\@caption#1[#2]{%
    \gdef\NR:Type{\@currenvir}%
    \begingroup%
    \let\index\:gobble%
    \let\label\:gobble%
    \let\\\relax
    \protected@xdef\NR:Title{\a:newlabel{#2}}%
    \endgroup%
   \o:NR@@caption{#1}[{#2}]%
}
\makeatother
\catcode`\:=12
\begin{document}
\EndPreamble

In short, we need to disable the \\ when we define the \NR:Title command. It will not affect the rendering of the document, it is used only for the Nameref's purposes.

This is the result:

enter image description here

2
  • Thanks Michal. Would this fix become part of official tex4ht sources or do I need to keep this configuration in my .cfg all the time?
    – Nasser
    Dec 30, 2022 at 22:54
  • 2
    @Nasser yes, it will be included in sources. I will probably make a configuration to pass redefinitions of commands for caption
    – michal.h21
    Dec 30, 2022 at 23:10

You must log in to answer this question.

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