5

I'm trying to setup my article with notes such that:

  • Notes are not shown at the bottom of the page
  • Notes are shown at the end of the article (no need to show them after each section or so)
  • I can refer multiple times to the same note

This is typical code:

Some text\footnote{\label{l1}First footnote}

bla bla\footnote{other footnote} bla bla blaaaa, bla bla\cref{l1}

The \cref should create a superscript number that is the same as the number created for the first \footnote.

For the first two points, I was using the endnotes package, like this:

\usepackage{endnotes}
\let\footnote=\endnote
...
\theendnotes

And for the last point, I use cleveref, like this:

\usepackage{cleveref}
\crefformat{footnote}{#2\footnotemark[#1]#3}

However, while it does work separately, it doesn't work together, I'm getting these warnings:

LaTeX Warning: cref reference format for label type `' undefined on input line ...

And instead of displaying the right number, \cref puts '??'.

Whether I load cleveref before endnotes or the other way around (cleveref suggests I should load it later, as endnotes doesn't specifically support cleveref) doesn't matter.

Is there any way I can make them work together, or is there an other way to achieve my goal?

Keelan
  • 5,425

1 Answers1

6

With endnotes the label is set without using a counter, because this happens only when the endnotes file is read in.

As a workaround we can step a fake counter before setting the label and aliasing this counter to footnote, so that cleveref will do the correct annotation in the .aux file.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{endnotes}
\usepackage{cleveref}
\crefformat{footnote}{#2\footnotemark[#1]#3}
\crefalias{fakeendnote}{footnote}
\let\footnote\endnote
\newcounter{fakeendnote}

\makeatletter
\patchcmd{\theendnotes}
 {\@ResetGT\edef}
 {\@ResetGT\refstepcounter{fakeendnote}\edef}
 {}{}
\makeatother

\begin{document}

Some text\footnote{First footnote\label{l1}}

bla bla\footnote{other footnote} bla bla blaaaa, bla bla\cref{l1}

\theendnotes

\end{document}

Note that the value of fakeendnote is never used, because endnotes redefines \@currentlabel using the footnote number stored in advance.

enter image description here

With enotez instead of endnotes the problem is similar: no counter is stepped, so cleveref can't make its proper annotation.

\documentclass{article}

\usepackage{enotez}
\usepackage{cleveref}
\crefformat{footnote}{#2\footnotemark[#1]#3}
\renewcommand\footnote{\refstepcounter{footnote}\endnote}

\begin{document}

Some text\footnote{First footnote}\label{l1}

bla bla\footnote{other footnote} bla bla blaaaa, bla bla\cref{l1}

\printendnotes

\end{document}

Note that \label should go outside the footnote text with enotez.

egreg
  • 1,121,712
  • Works like a charm, thank you very much. I will wait with accepting it for a bit of course, to see if others have something to say. But, thanks a lot! – Keelan Oct 25 '14 at 19:39