I'm trying to use cleveref to cross reference between documents and compile them with make4ht. The following example compiles with pdflatex but not with make4ht or htlatex.
main.tex
:
\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\section{First Section} \label{section}
\begin{equation} \label{equation}
\int f(x) dx
\end{equation}
\end{document}
ref.tex
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{cleveref}
\externaldocument[main-]{main}
\begin{document}
Equation \eqref{main-equation} in \cref{main-section}.
\end{document}
If I change the \cref
to \ref
(stop using cleveref) then make4ht still can't compile without giving an error
[ERROR] htlatex: ./ref.tex 10 Argument of \XR:rEfLiNK has an extra }.
If compiled using batchmode then the expected html is produced. If I try to compile with \cref
then I get a load more errors and the references don't work if batchmode is used. If I compile ref.tex
before main.tex
then there are no errors, but obviously then the cross referencing doesn't work.
There used to be an almost identical bug with make4ht xr-hyper and hyperref discussed here which has since been fixed.
Anyone know a work around for this? Also which project would it be good to report the bug to?
Best Answer
There are two problems. The first is that TeX4ht needs to load the
aux
file frommain.tex
. When it does this, it checks all the labels and modifies them so that they produce correct links to themain.html
file. However, Cleveref uses special labels with meta information about the reference type of the given label. These special labels use the suffix@cref
. We have to ignore them. This version of thexr-hyper.4ht
file does that:The important code is this:
It uses the LaTeX 3 regex to detect
@cref
labels, and declares the given reference accordingly.The other problem is in
cleveref.4ht
, because we need to support the special external file links introduced in the previous function. This version ofcleveref.4ht
should fix that:The important code is this:
We need to declare
\def\XRrEfLiNK[##1]##2##3
here.With these changes, you should be able to compile your example: