todonotes: ToDo リストに章のヘッダーを挿入する

todonotes: ToDo リストに章のヘッダーを挿入する

パッケージの場合todonotes、ToDo リスト内に章のヘッダーを挿入して、それぞれの章の下にグループ化する方法を知りたいです。

\documentclass{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[hidelinks,colorlinks=false]{hyperref}
\usepackage{todonotes,lipsum}


\begin{document}

    \listoftodos

    \chapter{1st Chapter}
    \lipsum[1]
    \todo[inline]{1st todo}

    \chapter{2nd Chapter}
    \lipsum[2]
    \todo[inline]{2nd todo}

\end{document}

答え1

ドキュメントの序文(つまり、 の前\begin{document})に以下を追加できます。

\makeatletter
\let\ori@chapter\@chapter
\def\@chapter[#1]#2{\ori@chapter[#1]{#2}%
  \if@mainmatter\addcontentsline{tdo}{chapter}{\protect\numberline{\thechapter}{#1}}%
  \else\addcontentsline{tdo}{chapter}{#1}%
  \fi}
\makeatother

ここに画像の説明を入力してください

関連情報