Open JeanOlivier opened 5 years ago
Sorry for the late reply, I totally forgot about this issue and found it again thanks for the reminder from another issue.
The problem is, that there are no pages in HTML files (in Epub there can be page numbers, but these are different than page numbers used by Backref). So Backref inserts links that go back to non-existent destination in HTML.
We can patch Backref to insert link destinations at each \cite
command, and link to these destinations from the bibliography. Here is the backref.4ht
file which does that:
% patch command that inserts backlink destinations
\pend:defI\Hy@backout{%
% prevent duplicate backlink on the same page
\ifcsname bk##1\thepage\endcsname\else%
% insert link to the page
\html:addr\Link-{}{X\last:haddr}\EndLink%
% save link to the .xref file
\Tag{)Q##1\thepage}{X\last:haddr}%
% we need to save the link destination in .xref file
% too, otherwise \Link command would issue warning
\Tag{)QX\last:haddr}{\FileNumber}%
\fi
% declare this backlink destination as used, so we don't
% declare another one with the same name
\expandafter\def\csname bk##1\thepage\endcsname{}%
}
% redefine macro that puts out backlinks
\def\:tempa#1#2#3{%
% test if we saved link to the current bibitem and page
\ifTag{)Q\current:back:desc#1}{%
\Link{\LikeRef{)Q\current:back:desc#1}}{}#1\EndLink%
}%
{#1}% print just page number if there is no saved link
}%
\HLet\backrefxxx\:tempa
% save current bibkey for use in \backrefxxx
\pend:defI\BR@backref{\def\current:back:desc{##1}}
Tested with BibTeX only as it's what I use with my custom bst files.
Consider the following minimal example:
File
document.tex
:File
document.bib
:Compiling in PDF with
generates a backref in the [1] entry of the bibliography pointing to where the entry was cited.
Compiling in epub with
yields the backref with a page number (surprisingly) but the hyperlinks points to an invalid target, namely "#page.1". For large documents those will appear as "pages" that seem related to the pdf pages. I'd suggest changing it for section numbers (even if hyperpageref is used) or a simple increasing counter for ebooks.
The paragraph with the citation is the following:
This can be fixed manually by adding
<a id="#page.1">
next to the 1 in [1] indocument.html
and modifying the href in the bibliography to<a href="document.html#page.1">1</a>