1

The following code produces chapter endnotes at the end the end of each chapter and rename "Notes" as "Chapter I. Endnotes" and "Chapter II Endnotes," respectively:

\documentclass[openany]{book}
\usepackage{endnotes}
\usepackage{chngcntr}
\counterwithin*{endnote}{chapter}  % Reset endnote numbering everyv%new chapter

\let\latexchapter\chapter
\makeatletter  %changes the catcode of @ to 11
\renewcommand\enoteheading{
  \setcounter{secnumdepth}{-2}
  \latexchapter*{\notesname\markboth{NOTES}{}}
  \mbox{}\par\vskip-\baselineskip
  \let\@afterindentfalse\@afterindenttrue
}
\makeatother %changes the catcode of @ back to 12

\usepackage{xparse}

\RenewDocumentCommand {\chapter}{som}{%
\IfBooleanTF{#1}
  {\latexchapter*{#3}%
   \setcounter{endnote}{0}%
   \addtoendnotes{%
     \noexpand\enotedivision{\noexpand\subsection}
       {\unexpanded{#3}}}%
  }
  {\IfNoValueTF{#2}
     {\latexchapter{#3}}
     {\latexchapter[#2]{#3}}%
   \addtoendnotes{%
     \noexpand\enotedivision{\noexpand\subsection}
       {\chaptername\ \thechapter. \unexpanded{#3}}}%
  }%
}
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter

\begin{document}
\LARGE

\renewcommand\contentsname{Table of Contents.}
\tableofcontents

\chapter*{Chapter I}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
Some words.\endnote{an endnote.} Some words.\endnote{an endnote.} Some words.\endnote{an endnote.}

\newpage
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}}
\renewcommand{\notesname}{Chapter I. Endnotes} 
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes

\chapter*{Chapter II}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter II.}}
Some words.\endnote{An endnote.} Some words.\endnote{An endnote.} Some words.\endnote{An endnote.} Some words.\endnote{An endnote.} Some words.\endnote{An endnote.}

\newpage
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter II. Endnotes.}}
\renewcommand{\notesname}{Chapter II. Endnotes}
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}

which produces the TOC:

enter image description here

And the two Endnote pages are:

enter image description here

and

enter image description here

The "Chapter I" and "Chapter II" headings which appear after the Endnotes titles in both the Endnotes sections and in the TOC are redundant and I would like to remove them.

If it matters, I compile the code with lualatex.

QUESTION: How may I remove the unwanted "Chapter I" and "Chapter II" labels in the Endnotes sections, as well as in the TOC, keeping only the two which I have manually inserted into the TOC by the commands \addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}} and \addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}}?

Thank you.

1 Answer 1

1

Try this code.

\theendnotes starts a new page as a chapter, so there's no need for a\newpage before.

Only four items are listed in the ToC: the two chapters and the corresponding endnotes.

There are three endnotes in Chapter I, numbered 1 to 3; and six endnotes in chapter II numbered 1 to 6.

a

b c

\documentclass[openany]{book}

\usepackage{endnotes}
\usepackage{chngcntr}
\usepackage{etoolbox} % added<<<<<<<*    

\let\latexchapter\chapter
\makeatletter  %changes the catcode of @ to 11
\renewcommand\enoteheading{
    \setcounter{secnumdepth}{-2}
    \latexchapter*{\notesname\markboth{NOTES}{}}
    \mbox{}\par\vskip-\baselineskip
    \let\@afterindentfalse\@afterindenttrue
}
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\pretocmd{\@makeschapterhead}{\setcounter{endnote}{0}}{}{} % reset counter
\makeatother    

\begin{document}
    \LARGE
    
    \renewcommand\contentsname{Table of Contents.}
    \tableofcontents
    
    \chapter*{Chapter I}
    \addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
    Some words.\endnote{an endnote.} Some words.\endnote{an endnote.} Some words.\endnote{an endnote.}
    
    \renewcommand{\notesname}{Chapter I. Endnotes} 
    \addtoendnotes{\unexpanded{\enotedivision{}{}}}
    \theendnotes
    \addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}}
    
    \chapter*{Chapter II}
    \addcontentsline{toc}{chapter}{\textbf{Chapter II.}}
    Some words.\endnote{an endnote.} Some words.\endnote{an endnote.} Some words.\endnote{an endnote.}  Some words.\endnote{an endnote.} Some words.\endnote{an endnote.} Some words.\endnote{an endnote.}
    
    \renewcommand{\notesname}{Chapter II. Endnotes} 
    \addtoendnotes{\unexpanded{\enotedivision{}{}}}
    \theendnotes
    \addcontentsline{toc}{chapter}{\textbf{Chapter II. Endnotes.}}
    
\end{document}
5
  • Many thanks for posting this answer; however, the algorithm does restart the counting at 1. with the beginning of a new chapter.
    – DDS
    Commented Feb 26, 2022 at 20:26
  • @mlchristians Yes but that was the output in the code you posted. If you want consecutive numbering remove \pretocmd{\@makeschapterhead}{\setcounter{endnote}{0}}{}{} % reset counter Commented Feb 26, 2022 at 20:29
  • I apologize; in my first comment, for some reason "does restart" got typed instead of "does not restart". I want the endnotes for chapter II to begin with 1. In the MWE, Chapter II has five such endnotes numbered 1-5. In your answer, which has three endnotes for chapter II, I would like them if possible, instead of being numbered 4-6, to be numbered 1-3. Again, sorry for the confusion.
    – DDS
    Commented Feb 26, 2022 at 20:48
  • @mlchristians Try the code now. I added more footnotes in chapter II and a figure. Commented Feb 26, 2022 at 21:04
  • Many thanks once again for a very helpful answer.
    – DDS
    Commented Feb 26, 2022 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .