Here's an automatic version:
\documentclass{book}
\usepackage{endnotes,chngcntr}
\usepackage[perpage,symbol*]{footmisc}
\counterwithin*{endnote}{part} % Reset endnote numbering every new part
\counterwithin*{endnote}{chapter} % Reset endnote numbering every new chapter
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\chapter*{\notesname}
\addtocontents{toc}{\protect\addvspace{10pt}} % adjust to suit
\addcontentsline{toc}{chapter}{\notesname}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother
\usepackage{xparse}
\let\latexpart\part
\let\latexchapter\chapter
\RenewDocumentCommand{\part}{som}{%
\IfBooleanTF{#1}
{\latexpart*{#3}}
{\IfNoValueTF{#2}
{\latexpart{#3}}
{\latexpart[#2]{#3}}%
\addtoendnotes{\unexpanded{\section{#3}}}
}
}
\RenewDocumentCommand{\chapter}{som}{%
\IfBooleanTF{#1}
{\latexchapter*{#3}}
{\IfNoValueTF{#2}
{\latexchapter{#3}}
{\latexchapter[#2]{#3}}%
\addtoendnotes{\unexpanded{\subsection{#3}}}
}
}
\begin{document}
Some text,\endnote{This endnote will naturally be numbered 1, as the first endnote in the document.}
not in any structural part of the document.
\part{Part One}
Some\footnote{This is the first footnote, symbolised by a star.}
text,\footnote{Second footnote, a pair of stars.}
not\endnote{This endnote will naturally be numbered 1, as the first endnote in the document.}
part\footnote{Third footnote, a solitary dagger.}
of any chapter.
\chapter{Chapter 1}
This\footnote{A footnote, should be a single star (symbol \#1), not a pair of daggers (\#4)
because of reset footnote numbering at new page.}
is chapter one.\endnote{This endnote should be numbered 1, since it's the first of a chapter.}
\part{Part Two}
Text.\endnote{This should also be numbered 1, since it's the first in its part.}
\theendnotes
\end{document}
First of all I've said \usepackage[perpage,symbol*]{footmisc}
to get footnotes numbered per page. Consult the documentation for how to change the order of symbols. I also changed a bit the \enoteheading
command.
The substantial part is the redefinition of \part
and \chapter
to write their titles in the endnotes file. The original meaning is saved and xparse
is used to easily redefine them.
Here's a slightly different version that avoids printing a chapter (subsection) header in the endnotes if there's no endnote in it. Part (section) headers are always printed.
\documentclass{book}
\usepackage{endnotes,chngcntr}
\usepackage[perpage,symbol*]{footmisc}
\counterwithin*{endnote}{part} % Reset endnote numbering every new part
\counterwithin*{endnote}{chapter} % Reset endnote numbering every new chapter
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\chapter*{\notesname}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother
\usepackage{xparse}
\let\latexpart\part
\let\latexchapter\chapter
\RenewDocumentCommand{\part}{som}{%
\IfBooleanTF{#1}
{\latexpart*{#3}}
{\IfNoValueTF{#2}
{\latexpart{#3}}
{\latexpart[#2]{#3}}%
\addtoendnotes{\unexpanded{\enotedivision{\section}{#3}}\relax}
}
}
\RenewDocumentCommand{\chapter}{som}{%
\IfBooleanTF{#1}
{\latexchapter*{#3}}
{\IfNoValueTF{#2}
{\latexchapter{#3}}
{\latexchapter[#2]{#3}}%
\addtoendnotes{\unexpanded{\enotedivision{\subsection}{#3}}}
}
}
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter
\begin{document}
Some text,\endnote{This endnote will naturally be numbered 1, as the first endnote in the document.}
not in any structural part of the document.
\part{Part One}
Some\footnote{This is the first footnote, symbolised by a star.}
text,\footnote{Second footnote, a pair of stars.}
not\endnote{This endnote will naturally be numbered 1, as the first endnote in the document.}
part\footnote{Third footnote, a solitary dagger.}
of any chapter.
\chapter{Chapter 1}
This\footnote{A footnote, should be a single star (symbol \#1), not a pair of daggers (\#4)
because of reset footnote numbering at new page.}
is chapter one.\endnote{This endnote should be numbered 1, since it's the first of a chapter.}
\chapter{Chapter 2}
No endnotes
\part{Part Two}
Text.\endnote{This should also be numbered 1, since it's the first in its part.}
\chapter{Chapter 3}
No endnotes.
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}
This sort of works. It prints the footnote counter, but \nameref
still prints "A Section".
\documentclass{report}
\usepackage{nameref}
\usepackage{enotez}
\usepackage{hyperref}
%\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}
\label{test\theendnoteLabelCnt}
}
\newcommand{\myendnote}[3]{% #1=
% Here maybe something to auto generate the "autolabel" ???
{#1}\endnote{\stepcounter{endnoteLabelCnt}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter}
\section{A section}
\subsection{A subsection}
\autoLabelling
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{test\theendnoteLabelCnt}
% Warning: \autoLabelling command is called into the footnote here:
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{test\theendnoteLabelCnt}}\autoLabelling
\setcounter{endnoteLabelCnt}{0}
\printendnotes
\end{document}
If you intend to call \printendnotes
more than once, you will need two counters. All labels must have unique names, so you can't reuse the old numbers.
\documentclass{report}
\usepackage{nameref}
\usepackage{enotez}
\usepackage{hyperref}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcounter{endnoteLabelUsed}
\setcounter{endnoteLabelUsed}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}
% Modification here by adding "\thechapter"
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\label{\thechapter\theendnoteLabelCnt}
}
% Modification of the command in order to deal with call inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage{xparse}
\NewDocumentCommand{\myendnote}{m m m o}{%
% <code>
\IfNoValueTF{#4}{% code when no optional argument #4 is passed
{#1}\autoLabelling\endnote{\stepcounter{endnoteLabelUsed}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
{% code when the optional argument #4 is present
% Note that, on the next line, the \stepcounter is moved after the \ref and \nameref in order to link to the current section and after to the footnote numer
{#1}\autoLabelling\endnote{\emph{\S{}~\ref{#3} \nameref{#3}, \stepcounter{endnoteLabelUsed}footnote \ref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
% #4 : Optionnal argument if command passed inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\begin{document}
\chapter{First Chapter}
\section{A First section}
\subsection{A First subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\printendnotes
\chapter{Second Chapter}
\section{A second section}
\subsection{A second subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\printendnotes
\end{document}
Best Answer
Making the comment of daleif to an answer
@daleif: I've ended up reimplementing it differently in
memoir
, i.e. is no longer using the solution frompagenote
, but rather one inspired byendnotes
. This version then use a unique counter and labels to provide back references. Hmm, seem to have forgotten about forward references (via hyperref), will fix that in the next release (which is not the one I just released an hour ago)