2

Inspired by other answer I found here, I decided to use endnotes to have all my footnotes and the end of my ebook. The solution works and epubchecker does not complain. Unfortunately, uploading to Kindle Publishing fails. Here the steps I followed:

The latex file:

\documentclass{report}

\usepackage{endnotes}
\renewcommand{\footnote}{\endnote}

\begin{document}

This is a sentence with a footnote\footnote{This is the footnote}.

\theendnotes

\end{document}

A minimal configuration file:

\Preamble{xhtml,mathml}
\begin{document}

\EndPreamble

Compile with:

tex4ebook -c ebook/testconfig.cfg -f epub3 test.tex --tidy

This generates:

<!DOCTYPE html> 
<html xmlns:epub='http://www.idpf.org/2007/ops' xmlns='http://www.w3.org/1999/xhtml' lang='en-US'> 
<head>
   <title></title> 
<meta charset='UTF-8' /> 
<meta name='generator' content='TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)' /> 
<link type='text/css' href='test.css' rel='stylesheet' /> 
</head><body>
<p class='noindent'>This is a sentence with a footnote<!-- l. 8 --><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>  <msup><mrow></mrow><mrow><mstyle xmlns:xlink='http://www.w3.org/1999/xlink' xlink:type='simple' xlink:href='#ennote-1' class='label' id='enmark-1'><mn>1</mn></mstyle><!-- endlabel --></mrow></msup></math>.
   </p> 

   <h3 class='likesectionHead'><a id='x1-1000'></a>Notes</h3>
<p class='noindent'></p> 
<p class='indent'>   <a id='ennote-1' href='#enmark-1'><!-- l. 4 --><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'> <msup><mrow></mrow><mrow><mn>1</mn> </mrow> </msup> </math></a><span class='cmr-8'>This is the footnote</span>
   </p> 
      
</body> 
</html>

The problem is that the 1 superscript in the footnote link is using a math environment and this fails when uploading to Kindle. I can get rid off this issue not using mathml. However, I need to use math notations.

The following is the output without the mathml option:

<!DOCTYPE html> 
<html xmlns:epub='http://www.idpf.org/2007/ops' lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> 
<head>
   <title></title> 
<meta charset='UTF-8' /> 
<meta name='generator' content='TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)' /> 
<link href='test.css' type='text/css' rel='stylesheet' /> 
</head><body>
<p class='noindent'>This is a sentence with a footnote<sup><a href='#ennote-1' id='enmark-1'><span class='cmr-7'>1</span></a></sup>.
   </p> 

   <h3 class='likesectionHead'><a id='x1-1000'></a>Notes</h3>
<p class='noindent'></p> 
<p class='indent'>   <a href='#enmark-1' id='ennote-1'><sup><span class='cmr-6'>1</span></sup></a><span class='cmr-8'>This is the footnote</span>
   </p> 
      
</body> 
</html>

I do not really understand why the footnote label is in the math environment. I would appreciate any guidance on how to move forward.

1

1 Answer 1

2

The tex4ebook (or more generally the tex4ht) configuration file for the endnotes package specifies the endnote numbers in math mode. This used to be the case for the normal LaTeX definitions for endnote as well, and it is still listed in the comments of the package (line 170):

%   \makeenmark : A macro to generate the endnote marker from  \theenmark
%                  The default definition is \hbox{$^\theenmark$}.

The actual definition however has changed, and is currently as follows (line 268):

\def\@makeenmark{\hbox{\@textsuperscript{\normalfont\@theenmark}}}
\def\makeenmark{\@makeenmark}

However, tex4ht uses the following definition in endnotes.4ht:

\def\@makeenmark{%
   \gHAdvance\endnote:N by 1
   \hbox{$\sp{\a:makeenmark\@theenmark\b:makeenmark}$}}
\def\enoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
     \leavevmode\llap{\hbox{$\sp{\@theenmark}$}}}

with the first definition for the note number in the main text, and the second for the note number in the list of notes at the end. You can see the math delimiters and the superscript (\sp) in these definitions. This gets converted into the XHTML that is included in the question.

I don't know enough about tex4ht to figure out how to change the definitions from the .tex or .cfg file. Maybe tex4ht maintainer Michal Hoftich (user michal.h21 on the site here) can explain that. However, what you can do is to copy endnotes.4ht to the same folder as your .tex document, and change the code there. This is against best practise for modifying code (see below), but it may serve as a workaround for your use case.

The following endnotes.4ht produces text mode for the endnotes, in text superscript and at the end normal script. Note that the new definition is copied from the current source of endnotes.

\immediate\write-1{version 2009-05-21-09:32, update 2021-03-29}

   \HAssign\endnote:N=0
\def\endnoteN{\endnote:N}
\def\:tempc{\addtoendnotes
   {\def\string\endnoteN{\endnote:N}}\o:@endnotetext:}
\HLet\@endnotetext=\:tempc
\def\@makeenmark{%
   \gHAdvance\endnote:N by 1
   \hbox{\@textsuperscript{\normalfont\a:makeenmark\@theenmark\b:makeenmark}}}
\NewConfigure{makeenmark}{2}
\def\enoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
     \leavevmode\llap{\hbox{\@theenmark}}}
\def\:tempc{\bgroup
   \pend:def\enoteformat{\a:enoteformat}%
   \append:def\enoteformat{\b:enoteformat}%
   \a:theendnotes \o:theendnotes: \b:theendnotes \egroup}
\HLet\theendnotes=\:tempc
\NewConfigure{theendnotes}{2}
\NewConfigure{enoteformat}{2}

\Hinput{endnotes}
\endinput

XHTML:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en-US"> 
<head>
   <title></title> 
<meta charset="UTF-8" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<link rel="stylesheet" type="text/css" href="epubfootnote.css" /> 
</head><body 
>
<p class="noindent">This is a sentence with a footnote<sup class="textsuperscript"><a 
href="#ennote-1" id="enmark-1"><span 
class="cmr-9">1</span></a></sup>.
   </p> 

   <h3 class="likesectionHead"><a 
 id="x1-1000"></a>Notes</h3>
<p class="noindent"></p> 
<p class="indent">   <a 
href="#enmark-1" id="ennote-1"><span 
class="cmr-8">1</span></a><span 
class="cmr-8">This is a footnote</span>
   </p> 
      
</body> 
</html>

Viewing the .epub file with Okular (note: I expect it looks different on Kindle):

enter image description here

Note on code modification: if it is not possible to modify code in place (using redefinitions or patches in the .tex or .cfg files) then best practise is to modify the original file but save it with a new name. This makes sure that users are not confused by which version is actually loaded, and if you distribute your code then it will be obvious (because there will be an error) if you forget to include the files for the modified style/class/configuration etc. In this case that would mean that you should also modify and rename the endnote package, because the 4ht configuration that is loaded is based on the name of the LaTeX package (i.e., endnotes.4ht configures endnotes.sty), so if you want to use for example myendnotes.4ht then you need to rename the package to myendnotes.sty, change the name mentioned within the file, change your .tex source, and redistribute the package file as well if you share your code. This is rather cumbersome, therefore copying endnotes.4ht with the original name to your working directory may be preferred (until Michal tells you how this is intended to work).

2
  • 2
    your analysis is correct. the endnotes.4ht file was last modified in 2009 and uses math mode for endnote superscript. It simply used the code from original endnotes.sty and inserted special code used by TeX4ht for placement of HTML tags. I will update TeX4ht sources soon, but the change will be available only in TeX Live 2021. Until that becomes available, it is best to use a local copy of endnotes.4ht with corrected definitions.
    – michal.h21
    Mar 29, 2021 at 22:00
  • This is just to confirm that using a local copy of endnotes.4ht works. Thanks for the guidance.
    – Juan
    Mar 30, 2021 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.