# tex4ebook generates incorrect hyperlink references

I am sorry that I am unable to extract a minimal working example.

I downloaded the source code from arxiv, commented out \usepackage{times,fullpage} and \usepackage{xr-hyper} in the preamble:

\usepackage[all]{xy}
%\usepackage{times,fullpage}

% For cross-file-references
%\usepackage{xr-hyper}

\usepackage{hyperref}


and compiled with the configure file

\Preamble{xhtml,pic-align}

\Configure{Picture}{.svg}
\DeclareRobustCommand{$}{\begin{equation*}} \DeclareRobustCommand{$}{\end{equation*}}

\RequirePackage{etoolbox}
\def\patchaccent#1{%
\csletcs{orig#1}{#1}
\expandafter\def\csname #1\endcsname##1{\Picture+{}\csname orig#1\endcsname{##1}\EndPicture}
}
\patchaccent{acute}
\patchaccent{bar}
\patchaccent{breve}
\patchaccent{check}
\patchaccent{ddot}
\patchaccent{dot}
\patchaccent{grave}
\patchaccent{tilde}
\patchaccent{vec}
\patchaccent{widehat}
\patchaccent{widetilde}

\begin{document}
\EndPreamble


and the mk4 file

if mode == "draft" then
Make:htlatex {}
else
Make:htlatex {}
-- Make:biber {}
Make:htlatex {}
Make:htlatex {}
end

Make:tex4ht{}
Make:t4ht{}


I found that the generated epub file has many incorrect hyperlinks of references. For example, the generated code of label of Lemma 2.4:

<a id="x3-3002r3"></a>
<span class="cmbx-10">Lemma 2.4.</span>


while in the reference code of Lemma 2.4 in Remark 2.5 is

The following fact was used in the proof of Lemma <a href="#x3-3002r4">2.4<!--tex4ht:ref: lemma-cech --></a>:


The reference ID is incorrect (and in fact, there is no #x3-3002r4 according to the generated .aux file). It's weird that some of the references are correct, while others are wrong.

I look forward to a fix of this.

======

# Update

I produced a minimal working example:

\documentclass{amsart}

\usepackage{hyperref}

\theoremstyle{plain}
\newtheorem{thm}[subsection]{Theorem}

\begin{document}

\section{First section}

\subsection{A}

\begin{thm}
\label{thm:nul}
nul
\end{thm}

\begin{thm}
\label{thm:this}
This is a theorem
\end{thm}

Look at Theorem \ref{thm:nul}.

Look at Theorem \ref{thm:this}.

\end{document}


compiled with tex4ebook without any extra arguments.

Note that the environment thm uses the counter of subsection. See the wikibook for such a usage.

• I can see that this happens, but it seems to be completely random. When I copy parts of this document to a new one, with the same preamble, links works. – michal.h21 Apr 5 '19 at 12:46
• @michal.h21 It seems that there is some confliction between counting/labeling system. I found that all lemmas are referred by Lemma <a href="#x3-****r?">*.? where two question marks indicates the same number, while the label of lemma looks like #x3-****r, where the number after r is not necessarily the number of the lemma. – Yai0Phah Apr 6 '19 at 12:53
• @michal.h21 I understood what's happening. I produced an MWE and will update the answer soon. It is very probable a typo of the template that author uses, but since pdflatex will give us the right hyperlink, it is still reasonable to see whether we can do something. – Yai0Phah Apr 6 '19 at 13:55