1

Here is the MWE:

    \documentclass[12pt]{article}

    \usepackage[compatibility=false]{caption}
    \usepackage{subcaption}

    \begin{document}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc aliquam,
    ex et sollicitudin aliquet, magna elit mattis nunc, sed blandit sapien
    mi vel risus. Sed sed efficitur nibh. Lorem ipsum dolor sit amet,
    consectetur adipiscing elit.

    \begin{figure}%
    \subcaptionbox{\label{foo}(a)}{}
    \subcaptionbox{(b)}{}
    \caption{(a) Lorem ipsum dolor sit amet, consectetur adipiscing elit;
    (b) nunc aliquam, ex et sollicitudin aliquet, magna elit mattis nunc.}
    \end{figure}

    Morbi pretium (fig.~\ref{foo})%
    , turpis sit amet tristique luctus,
    sapien ipsum feugiat diam, et volutpat erat sapien ac massa. Aliquam
    erat volutpat.

    \end{document}

This compiles correctly with pdflatex (in two passes, obviously), and also with htlatex if I remove the \ref. With the \ref, htlatex gets through the first LaTeX pass all right, then on the second pass I get this:

    ! Missing \endcsname inserted.
    <to be read again> 
                       \protect 
    l.20 Morbi pretium (fig.~\ref{foo}
                                      )%
    ? 

    Package caption Warning: \label without proper reference on input line 14.
    See the caption package documentation for explanation.

    LaTeX Warning: Reference `foo' on page 4 undefined on input line 20.

    ! Extra \endcsname.
    \:::HRefTag ...sname cw:)Q\aXrefFile #1\endcsname 
                                                      \relax \:warning {\string ...
    l.20 Morbi pretium (fig.~\ref{foo}
                                      )%
    ?

I'm guessing the problem has something to do with the catcode of :? Or maybe not, but, anyway, I don't know what to do about it.

BTW I at first tried using subfigure, but I found that the \caption command inside a subfigure doesn't result in a span of a distinctive class in the HTML output, so there was no way to apply CSS to the subcaptions.

  • This will point you in the right direction I think---https://tex.stackexchange.com/questions/122290/htlatex-and-subcaption-can-htlatex-be-extended and---https://tex.stackexchange.com/questions/66131/control-the-p-tags-added-by-tex4ht/66172#66172 – js bibra Nov 29 '19 at 15:43
  • which TeX distribution do you use? Your example compiles without error in up to date TeX Live. – michal.h21 Dec 01 '19 at 09:52
  • Oops my bad. I am using the latest distribution, but when I looked in my log I found that an old 4ht file somehow got into the path. With that removed it compiles correctly. – Abe Stone Dec 01 '19 at 14:32
  • that's great! I think we can close the question then :) – michal.h21 Dec 01 '19 at 22:05

0 Answers0