13

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}
\usepackage[colorlinks=true,linktocpage=true]{hyperref}

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

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

1 Answer 1

11
+100

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

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

enter image description here


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

\usepackage{xpatch}
\xapptocmd{\Chap}{\addtocontents{tdo}{\protect\todoline{\thechapter}}}{}{}
\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}{}
\AtEndDocument{\addtocontents{tdo}{\string\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}
\hypersetup{colorlinks=true,linktocpage=true}

\usepackage{xpatch}
\xapptocmd{\Chap}{\addtocontents{tdo}{\protect\todoline{\thechapter}}}{}{}
\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}{}
\AtEndDocument{\addtocontents{tdo}{\string\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} 

enter image description here


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}
\xapptocmd{\Chap}{\addtocontents{tdo}{\protect\todoline{\thechapter}{\spacedlowsmallcaps{#1}}{\thepage}}}{}{}
\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}{}
\AtEndDocument{\addtocontents{tdo}{\string\Endoftdo}}

It may be possible to make the chapter page number into a link. Be happy with this version. :)

enter image description here

2
  • Very happy with this solution, thank you :-)
    – Jörg
    Jun 27, 2012 at 12:43
  • 4
    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, 2013 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .