如何从章节尾注和目录中删除多余的章节标签

如何从章节尾注和目录中删除多余的章节标签

以下代码在每章末尾生成章节尾注,并将“注释”分别重命名为“第一章尾注”和“第二章尾注”:

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

生成目录:

在此处输入图片描述

两个 Endnote 页面如下:

在此处输入图片描述

在此处输入图片描述

在尾注部分和目录中,尾注标题后面出现的“第一章”和“第二章”标题是多余的,我想删除它们。

如果重要的话,我会用 编译代码lualatex

问题:如何删除尾注部分以及目录中不需要的“第一章”和“第二章”标签,而只保留我通过命令和手动插入到目录中的两个\addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}}标签\addcontentsline{toc}{chapter}{\textbf{Chapter I. Endnotes.}}

谢谢。

答案1

尝试一下这个代码。

\theendnotes以新页面作为章节开始,因此不需要\newpage之前的内容。

仅列出四项ToC:两章和相应的endnotes

第一章有三处尾注,编号为 1 至 3;第二章有六处尾注,编号为 1 至 6。

A

bC

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

相关内容