I have a document with Chapters and endnotes, and a table of contents (TOC). In order not to generate a number for the last chapter (Epilogue), I use \chapter*{Epilogue} in the code and then I put an extra line in the TOC by hand, using the command \addcontentsline{toc}. The problem is that as the result, the page number for the section "Notes" in the TOC appears to be wrong: it is equal to the page number of the Epilogue.

How to change this number (increase it by 2)?

Here is the code (most of it was borrowed from the answer to my earlier question Chapter numbers in endnotes):

\documentclass[12pt]{book}

\usepackage{endnotes,chngcntr}

\counterwithin*{endnote}{chapter}  % Reset endnote numbering every new chapter

\makeatletter
\setcounter{secnumdepth}{-2}
\chapter*{\notesname\markboth{NOTES}{}}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother

\usepackage{xparse}

\let\latexchapter\chapter

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

\begin{document}

\setcounter{tocdepth}{1}

\tableofcontents

\chapter*{Preface\markboth{PREFACE}{}}

This is the Prologue. There are no endnotes here.

\chapter{Amazing Story}
As I am describing this story, I make a note which should appear at
the end.\endnote{This the first endnote.} And then I make the second
note.\endnote{This is the second note.}

\chapter{Another Amazing Story}
In this chapter, there are no endnotes. So it should not appear in the
"Notes" at the end.

\chapter{Yet Another Amazing Story}
In this chapter, I have some notes again, which I want to go to the
end.\endnote{This note should appear at the end, under the heading
"Chapter 3. Yet Another Amazing Story", with the counter reset to 1,
since this is the first endnote of this chapter.}

\chapter*{Epilogue\markboth{EPILOGUE}{}}

This is the Epilogue. No endnotes here.

\theendnotes

\end{document}

-
Put \cleardoublepage before \addcontentsline{toc}{chapter}{Notes} (and also \phantomsection if you're using hyperref). –  egreg Mar 7 '13 at 0:34
@egreg: This works in my example. However, I am wondering whether there is a more general method that would allow me in this situation to assign in the TOC any given page number to the Notes (not necessarily increasing it by 1 or by 2). –  Latex user Mar 7 '13 at 0:46
\addtocontents{toc}{\protect\contentsline{chapter}{Notes}{42}} But this will break with hyperref. –  egreg Mar 7 '13 at 0:52
@egreg: What exactly will break with hyperref if I use this line? And also: what did you mean by "\phantomsection if you're using hyperref" above? –  Latex user Mar 7 '13 at 1:29
The annotation on the .toc file written by hyperref is different and depends on the anchor name chosen by it and is not readily predictable. However, why assigning an arbitrary page? The \cleardoublepage\phantomsection\addcontentsline path is safe if hyperref is used. –  egreg Mar 7 '13 at 10:23

Put \cleardoublepage before \addcontentsline{toc}{chapter}{Notes} (and also \phantomsection if you're using hyperref).

\cleardoublepage
%\phantomsection % if you're using hyperref, uncomment this line

\chapter*{Preface}
\markboth{PREFACE}{}


In order to assign a specific page number, it's best to say

\cleardoublepage
\setcounter{page}{42}
%\phantomsection % if you're using hyperref, uncomment this line