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

share|improve this question
    
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
add comment

1 Answer

up vote 5 down vote accepted
+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

share|improve this answer
    
Very nice and clean solution. One drawback is that also adds the Chapters to the list that have no todos. And do you have a solution to remove that dots and put pagenumbers next to the text? –  Jörg Jun 26 '12 at 16:09
    
Generally I agree that it is too much fuzz for an internal working copy, but occasionally documents with todo-marks go out to clients, hence the presentation should be nice and consistent with the overall layout of the document. –  Jörg Jun 27 '12 at 8:41
    
Hence, if you know a solution to remove the dots and show pagenumbers after the entry (like in classicthesis tocs), I will be a happy bunny :). And congratulations to 100k! –  Jörg Jun 27 '12 at 8:58
    
Very happy with this solution, thank you :-) –  Jörg Jun 27 '12 at 12:43
    
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
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.