# babel causing cref mistakes to labels when compiled with htlatex

Update:

I'd be very interested to know what babel does to that enables the advanced hungarian accents to be loaded. The comments below indicate that it should really have no affect. Given the experience and brilliance of those responding their probably right. That being said, it is doing something as it definitely gives me a scaleable character when I use it. Since babel on it's own is interfering with cleveref I'd like to extract whatever part it's providing that character (recognizing that it's probably not changing encoding or anything) and just use that snippet.

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}


Update:

It looks like cleveref doesn't yet support Hungarian and this argument is actually the part that is causing problems.

So the problem is now less about cref, and more about how to insert complex characters such as those found in Hungarian, when compiling with htlatex. When I compile the following, I get two blurry png images inserted that needs to be worked around.

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

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

\usepackage{xparse,xpatch,letltxmacro}

\RequirePackage{ifxetex,ifluatex}
\newif\ifunicode
\ifxetex\unicodetrue\fi
\ifluatex\unicodetrue\fi

\ifdefined\HCode
\usepackage{textgreek}
\usepackage{textcomp} % needed for degree sign or something with tex4ht
%\usepackage[british,UKenglish,USenglish,english,american,hungarian]{babel}

%\selectlanguage{english}
% No defaults to set yet

\usepackage{alternative4ht}

\altusepackage[T1]{fontspec}
\usepackage[utf8]{inputenc}

\altusepackage{polyglossia}

\else
% These packages won't work in html, so only include if using the pdf generation.

\ifxetex
\usepackage{textgreek}
\usepackage{polyglossia} % loads fontspec (font selection with XeLaTeX and LuaLaTeX - load open type fonts)
\setmainlanguage{english}

\setmainfont[
Ligatures=TeX,
SmallCapsFont={TeX Gyre Termes},
SmallCapsFeatures={Letters=SmallCaps},
]{Times New Roman}

%\setmainfont[Mapping=tex-text]{TeX Gyre Termes}
%\setmainfont[
%Extension=.otf,
%UprightFont= *-regular,
%BoldFont=*-bold,
%ItalicFont=*-italic,
%BoldItalicFont=*-bolditalic,
%]{texgyreheros}

\defaultfontfeatures{Ligatures={TeX}}
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
% This will likely need improvements to fonts and languages still
\fi
\fi

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

Text with a complex accent \H{o} or \H{u}
\end{document}

• Why are you loading enumerate and enumitem? What is the command to compile this document with htlatex? In my point of view you're abusing the PanelledFigure macro as an environment, which isn't really – user31729 Jan 14 '18 at 1:00
• Also \usepackage[english]{cleveref} seems to be a better way – user31729 Jan 14 '18 at 1:06
• I no longer remember why enumerate is being loaded, but I load enumitem because I need to customize the label's appearance and I found efficient solutions to customize my list aesthetics with enumitem. Before updating my question with the compile info, as the compile script I wrote is very complex, but usable by, the MWE, I will do a quick a quick MWE test of common/simple htlatex compile sequences to verify this is simply reproducible. If you tried this with your own preferred htlatex sequence and observed the failed picture import with example-image-a.jpg that is what I see to. – EngBIRD Jan 14 '18 at 1:07
• @ChristianHupfer The babel is used because I was unable to find a way, short of using it, to get a few Hungarian accents (in my bibliography) to display without appearing as a horrible png image of the accented character. – EngBIRD Jan 14 '18 at 1:08
• @EngBIRD: babel is not interfering with cleveref -- no one has written the relevant \crefname etc. settings for Hungarian and various other languages so far. By default cleveref uses English, it has support for German, Dutch, French, Spanish, Italian, Russian, Ukrainian, Norsk, Danish, Esperanto (!), Swedish and Brazilian. – user31729 Jan 14 '18 at 10:06