# babel causing cref mistakes to labels when compiled with htlatex

by EngBIRD   Last Updated January 14, 2018 01:23 AM

Summary

• Document with cref and figure environments
• Custom figure environment is setup to let me build a complex paneled figure (considerable code not shown)
• The figure caption may include an enumerated list
• The overall figure label has trouble being referenced** when there is an enumerate environment in the figure caption
• The "\cref{figure}" reference is, for some reason with htlatex and babel is not being applied to the figure label, but is being recognized as the last label used in the enumerate environment
• Strangely the \label location in the caption doesn't matter; it can follow the list and this will still fail
• This problem does not appear following pdf compilation
• This problem only appears in htlatex when babel is used

So this MWE should compile just fine with xelatex it does on my computer. Unfortunately while it compiles completely with htlatex as well, I get a problem with the cref command. I only get this problem if I include babel, otherwise the htlatexcompile result is accurate as well.

In the html file, where I would expect to see (like the pdf):

Reference: Fig. 1

Reference: item (iii)

Which tells me that somehow the environment I've created/used is using the last possible label from the enumerate.

MWE - Including customizations that may interfere with solution

%%!TEX encoding = UTF-8 Unicode
\NeedsTeXFormat{LaTeX2e}

\documentclass[10pt, oneside, letterpaper]{article} %oneside twoside

\usepackage{xparse,xpatch}
\usepackage{graphicx,caption,float,grffile}
\usepackage[format=hang,singlelinecheck=0,font={sf,small},labelfont=bf]{subfig}

\makeatletter
\captionsetup[subfigure]{
subrefformat=simple,
labelformat=simple,
listofformat=subsimple
}%

\captionsetup[figure]{
%labelfont={bf},
labelformat={default},
labelsep=period,
name={Fig.}
}%

\captionsetup[subfloat]{farskip=0mm,captionskip=0mm}%

\renewcommand\thesubfigure{\Alph{subfigure}}
\makeatother

\newcounter{HTMLalternative}

\DeclareDocumentCommand{\PanelledFigure}{ O{7.0625 in} o O{1.25}}
{%% THIS WILL BREAK ENDFLOATS
\def\ImagePanelSize{#1}%
\def\AlternateHTMLImage{#2}
\def\ColSepSize{#3}%
\begin{figure}%
\centering%
\begin{minipage}{#1}%{\textwidth}
}%
\def\endPanelledFigure
{%
\end{minipage}%
\end{figure}%
%\clearpage%
\setcounter{HTMLalternative}{0}%
}%

%%%%%%%%%%%%%% CULPRIT LINE %%%%%%%%%%%%%%%%%%%%
\usepackage[english,hungarian]{babel}%
%%%%%%%%%%%%%% CULPRIT LINE %%%%%%%%%%%%%%%%%%%%

\usepackage{enumerate}
\usepackage[shortlabels,inline]{enumitem}

\usepackage{cleveref}
\crefname{figure}{Fig.}{Figs.}
\Crefname{figure}{Fig.}{Figs.}

\begin{document}
\noindent
\selectlanguage{english}

Reference:  \cref{fig:ref}

\begin{PanelledFigure}[7.0625in][../FigureExternalization/Figure_iii.png]%
\includegraphics[width=3cm]{example-image-a.jpg}\\%
\caption[NO FIGURE LEGEND EXPECTED]{%
\label{fig:ref}%
Little figure summary here that provides extra details:
\begin{enumerate*}[label=(\roman*)]
\item first example;
\item another example;
and \item last example.
\end{enumerate*}
}%
\end{PanelledFigure}%
\end{document}

Tags :