1

From an MWE like this:

\documentclass{report}

\usepackage[backref,totoc=chapter,counter-format=Roman,split=chapter]{enotez}
\setenotez{split-title={\chaptername\ <ref>}}

\begin{document}

\chapter{Introduction}
Some text with an endnote.\endnote{Once upon a time\dots}

\printendnotes
\end{document}

I get the following:

enter image description here

Is there a way to get the chapter name also? Ie: Chapter 1 -- Introduction. I found this answer, but it only works within the current chapter or section... The enotez manual has also not been of much help...

Thank you in advance.

wmnorth
  • 657

1 Answers1

4

Here is a non-obvious solution which relies on nameref and redefines \chapter in order to automatically place a label after it which can then be used. Please note that this only works if all your endnotes are in numbered chapters…

\documentclass{report}

\usepackage{enotez}
\setenotez{
  backref,
  totoc=chapter,
  counter-format=Roman,
  split=chapter,
  split-title={\chaptername\ <ref> -- <title>}
}

\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}

\usepackage{nameref}% automatically loaded if you use hyperref

\usepackage{letltxmacro}

\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {% starred chapter, no label then
      \origchapter*{#3}%
    }
    {% else add a label
      \IfNoValueTF{#2}
        {\origchapter{#3}}
        {\origchapter[#2]{#3}}%
      \expanded{\noexpand\label{ch:\arabic{chapter}}}%
    }%
}

\begin{document}

\chapter{Introduction}
Some text with an endnote.\endnote{Once upon a time\dots}

\chapter{Second Chapter}
Some text with an endnote.\endnote{Twice upon a time\dots}

\chapter{And another one}
Some text with an endnote.\endnote{Another endnote\dots}

\printendnotes

\end{document}

enter image description here

cgnieder
  • 66,645
  • This was almost it, but it added needless "Chapter" to the Notes chapter (as well as the toc). The solution was to redefine chapter like this (requires etoolbox; snatched from here):

    \makeatletter \apptocmd{\@chapter}{% \expanded{\noexpand\label{ch:\arabic{chapter}}}% }{}{} \makeatother

    – wmnorth Oct 14 '19 at 01:11
  • The suggestion in my previous comment works only for numbered chapters, but to me, this is not a problem. – wmnorth Oct 14 '19 at 01:21
  • @wmnorth see edited answer – cgnieder Oct 14 '19 at 16:00
  • Even though I prefer my alternative -- rather than redefining \chapter -- I have accepted your answer, as it does what I had asked for. Still... is there a reason to prefer redefining \chapter rather than patching (appending) to its definition? Or is it just a matter of taste? – wmnorth Oct 15 '19 at 23:56
  • @wmnorthit it isn't that important. I like it better if I don't have to rely about how things are implemented… :) – cgnieder Oct 16 '19 at 16:01