# Making hyperlinks working with cleveref and htlatex/TeX4HT

Following Are htlatex (TeX4HT) and cleveref compatible? I am able to create cross-references with cleveref package with htlatex.

Still, these cross-references are not hyperlinked, while those created with usual \ref{} are.

Here is my test file

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % may use latin1 instead of utf8
\usepackage{cleveref}

\begin{document}
\section{testsection}
\label{testlabel}

Go to \cref{testlabel}

Go to \ref{testlabel}

\end{document}

and here is my output

Is there a way out?

• – MadyYuvi Feb 18 at 10:11
• @MadyYuvi you suggested exactly the same post that I linked in the description and that does not answer the problem! As I said, I do have "go to section 1" in my output, but the problem here is that it is not hyperlinked: this is the problem! – DarioMangoni Feb 19 at 11:16
• Oops...sorry, I didn't notice that.... – MadyYuvi Feb 20 at 4:45

Try the following version of cleveref.4ht:

% cleveref.4ht (2018-06-08-16:51), generated from tex4ht-4ht.tex
% Copyright 2018 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2018-06-08-16:51}

\def\refstepcounter@noarg#1{%
\cref@old@refstepcounter{#1}%
\cref@constructprefix{#1}{\cref@result}%
\@ifundefined{cref@#1@alias}%
{\def\@tempa{#1}}%
{\def\@tempa{\csname cref@#1@alias\endcsname}}%
\protected@xdef\cref@currentlabel{%
[\@tempa][\arabic{#1}][\cref@result]%
\csname p@#1\endcsname\csname the#1\endcsname}
}%
\def\refstepcounter@optarg[#1]#2{%
\cref@old@refstepcounter{#2}%
\cref@constructprefix{#2}{\cref@result}%
\@ifundefined{cref@#1@alias}%
{\def\@tempa{#1}}%
{\def\@tempa{\csname cref@#1@alias\endcsname}}%
\protected@edef\cref@currentlabel{%
[\@tempa][\arabic{#2}][\cref@result]%
\csname p@#2\endcsname\csname the#2\endcsname}}%

\ifdefined\@firstoffive\else%
\def\@firstoffive#1#2#3#4#5{#1}
\fi
\def\:tempa#1#2{\bgroup%
\expandafter\expandafter\expandafter\@firstoffive\csname r@#2\endcsname{}{}{}{}{}%
\o:@@@setcref:{#1}{#2}%
}%

\HLet\@@@setcref=\:tempa
\Hinput{cleveref}
\endinput

It patches the \@@@setcref command, which is used for the printing of the references. The patch executes the current reference, in order to get the link. Because of the reference structure used by tex4ht when the Hyperref package is loaded is a bit complicated, we need to use some tricks like the \@firstofone command etc. It works with and without Hyperref though.

The solution supports even multiple references in one \cref command, as shown in a modified example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % may use latin1 instead of utf8
\usepackage[]{hyperref}
\usepackage{cleveref}

\begin{document}
\section{testsection}
\label{testlabel}

Go to \cref{testlabel,secondsectioon}
\section{second}
\label{secondsectioon}

Go to \ref{testlabel}

\end{document}

This is the result:

There are two different links used in \cref, as is visible from the HTML code:

id="x1-10001"></a>testsection</h3>
<!--l. 11--><p class="noindent" >Go to <a
href="#x1-10001">sections 1</a><a
href="#x1-20002"> and 2</a>
</p>