# Error using hyperref and tex4ebook

\documentclass[ebook,12pt,oneside,openany]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xurl}

\usepackage[hyperindex=true]{hyperref}
\hypersetup{
urlcolor     = blue, %Colour for external hyperlinks
citecolor   = red %Colour of citations
}
\title{Test}
\author{Author}
\date{}

\begin{document}

\maketitle
\frontmatter
\tableofcontents \newpage
\mainmatter
\pagenumbering{arabic}

\chapter{New Chapter}
I am citing a book \footnote{sample footnote}.

\backmatter
\end{document}


I get following error message.

! LaTeX Error: No counter 'Hfootnote' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...


My .mk4 file is as follows:

Make:htlatex {}
Make:htlatex {}

• Your code can not be tested as we don't have the input files. Show a real minimal example. – Ulrike Fischer Sep 5 at 13:33
• Added a simplified code. There is some issue with HFootnote. – Jyotiranjan Beuria Sep 5 at 14:13
• Does the problem actually have anything to do with biblatex or can you reproduce the same error without biblatex? (If the latter is the case, please simplify your MWE further.) – moewe Sep 5 at 15:09
• The error exists independent of biblatex. As soon as I add \usepackage[hyperindex=true]{hyperref}, it gives error. – Jyotiranjan Beuria Sep 5 at 15:13
• If the question has otherwise nothing to do with biblatex I recommend you remove the code for the bibliography (and the biblatex tag) to streamline the question and provide only the code necessary to reproduce the issue and nothing more. – moewe Sep 5 at 15:17

There is a clash between Memoir, Hyperref and tex4ht in a definition of footnotes. The simplest fix is to define the Hfootnote counter in tex4ht. This can be done in a custom configuration file. Save the following code as mycfg.cfg:

\Preamble{xhtml}
\makeatletter
\ifHy@hyperfootnotes
\newcounter{Hfootnote}
\fi
}{}
\makeatother
\begin{document}
\EndPreamble


Request the config file using

tex4ebook -c mycfg.cfg filename.tex


The compilation should run without errors.

• Thanks! this works. However, when a bibliography entry is clicked, it comes back to the first page of the chapter instead of bibliography page. – Jyotiranjan Beuria Sep 6 at 11:59
• @JyotiranjanBeuria I think this is another issue. or did it work before this fix? – michal.h21 Sep 6 at 12:25
• Yes, it worked before this trick. Now with this .cfg file, I am not able to reach an appropriate bibliography page. – Jyotiranjan Beuria Sep 6 at 12:29