Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to list the endnotes chapter-by-chapter at the end of a book class Latex document. I borrowed this code from

How to reset endnotes counter at parts and chapters

\documentclass[12pt]{book}

\usepackage{endnotes,chngcntr}

\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\latexchapter\chapter

\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}

\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 will appear at the end, under the heading "Yet Another Amazing
Story", with the counter reset to 1, since this is the first endnote of this chapter.}

\addtoendnotes{\unexpanded{\enotedivision{}{}}}

\theendnotes

\end{document}

It's working great for me, EXCEPT that in the endnotes I get just the Chapter titles, but NO CHAPTER NUMBERS. How to I edit this to include Chapter numbers?

Example: right now I get this:

Notes

"Amazing Story"

(list of notes for that chapter)

I want this:

Notes

"Chapter 1. Amazing Story"

(list of notes for that chapter)

share|improve this question
    
A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Guido Nov 30 '12 at 7:18
    
@Guido: thanks! –  Latex user Nov 30 '12 at 17:26
add comment

1 Answer

Just change the redefinition of \chapter as follows

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

Here's, anyway, the complete example

\documentclass[12pt]{book}

\usepackage{endnotes,chngcntr}

\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\latexchapter\chapter

\RenewDocumentCommand{\chapter}{som}{%
  \IfBooleanTF{#1}
    {\latexchapter*{#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}

\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 will appear at the end, under the heading "Yet Another Amazing
Story", with the counter reset to 1, since this is the first endnote of this chapter.}

\addtoendnotes{\unexpanded{\enotedivision{}{}}}

\theendnotes

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.