# Todonotes: group list-of-todos by chapter

I use the todonotes package extensively to mark and comment my projects. So, for a large project, I have dozens of todo-notes and the list of todos, which I insert at the beginning of a document, get's very cluttered.

I'm looking for a way to group the list of todos by chapter, so essentially something like:

List of Todos

Chapter 1

Chapter 1 note ... 2
Chapter 1, section 1 note ... 2
Chapter 1, section 2 note ... 3

Chapter 2

Chapter 2, section 1 note ... 4
Chapter 2, section 2 note ... 4


The following MWE gives a starting point for modification:

\documentclass{scrreprt}

\usepackage{todonotes}
% \usepackage{classicthesis}
\usepackage{tocloft}
\usepackage{lipsum}

\begin{document}

\listoftodos

\chapter{My first chapter}
\lipsum[1]
\todo{Chapter 1 note}

\section{A first section}

\lipsum[1]

\todo{Chapter 1, section 1 note}

\section{Another section}

\lipsum[1]

\todo{Chapter 1, section 2 note}

\chapter{My second chapter}

\section{A first section}

\lipsum[1]

\todo{Chapter 2, section 1 note}

\section{Another section}

\lipsum[1]

\todo{Chapter 2, section 2 note}

\end{document}


This post tries something similar, but just adds the section next to the page number, which would not remove the clutter I have.

I'm using the classicthesis template which uses titlesec for tableofcontents appearance, in case it matters. A second point would be to remove the "dots" in the list of todos. I believe todonotes formats the appearance with this command:

\newcommand{\l@todo}
{\@dottedtocline{1}{0em}{2.3em}}


but I don't know how to modify it to remove the dots and show page numbers at the end of each TOC entry.

-
any idea how this could be achieved when not using the classicthesis package? – user16725 Jul 18 '12 at 15:35
@latex_user I think you should create a follow-up question for other document classes. – Jörg Jul 18 '12 at 19:56

This is specific for classicthesis. Add the following code to the preamble

\usepackage{xpatch}
\xapptocmd{\Chap}{%
\vskip\bigskipamount\noindent\textbf{Chapter \thechapter}\par\nobreak\vskip\medskipamount}}{}{}


If you really need a more complicated approach, printing the line only if there are notes, then here it is:

\usepackage{xpatch}
\makeatletter
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[1]{%
\@ifnextchar\todoline
{}
{\vskip\bigskipamount\noindent\textbf{Chapter #1}\par\nobreak\vskip\medskipamount}}
\makeatother
\newcommand{\Endoftdo}{}


But why doing something so complicated when the Todo List is only for working copies?

Here is a complete example, where the todo notes in the Todo List are typeset in the same way as sections in the table of contents:

\documentclass{scrreprt}

\usepackage{classicthesis}
\usepackage{todonotes}
\usepackage{tocloft}
\usepackage{lipsum}

\usepackage{xpatch}
\makeatletter
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[1]{%
\@ifnextchar\todoline
{}
{\vskip\bigskipamount\noindent\spacedlowsmallcaps{Chapter #1}\par\nobreak\vskip\medskipamount}}
\let\l@todo\l@section
\makeatother
\newcommand{\Endoftdo}{}

\begin{document}
\tableofcontents
\listoftodos

\chapter{My first chapter}
\lipsum[1]
\todo{Chapter 1 note}

\section{A first section}

\lipsum[1]

\todo{Chapter 1, section 1 note}

\section{Another section}

\lipsum[1]

\todo{Chapter 1, section 2 note}

\chapter{My second chapter}

\section{A first section}

\lipsum[1]

\todo{Chapter 2, section 1 note}

\section{Another section}

\lipsum[1]

\todo{Chapter 2, section 2 note}

\end{document}


In case you want the chapter title in the Todo List, a slightly different approach should be used. Change the code from \usepackage{xpatch} up to the \AtEndDocument line with the following

\usepackage{regexpatch}
\makeatletter
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[3]{%
\@ifnextchar\todoline
{}
{\contentsline{chapter}{\numberline{#1}#2}{#3}{}{}}%
}
\let\l@todo\l@section
\makeatother
\newcommand{\Endoftdo}{}

In my case I needed to change \Hy@org@chapter, and not \Chap because I'm using hyperref (and no classicthesis). Maybe others will need this as well. – Pieter Feb 14 '13 at 20:30