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}}{}{}
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}
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. :)
Here's a possible solution; only information for sections with \todo
notes will be written to the List of Todos:
\documentclass{scrartcl}
\usepackage{todonotes,xpatch,hyperref}
% initial definitions for storing the section info (name and number)
\def\thissectiontitle{}
\def\thissectionnumber{}
\newtoggle{noTodos}
\makeatletter
% redefinition of \@sect so \section glbally stores its name and number
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2>\c@secnumdepth
\let\@svsec\@empty
\else
\refstepcounter{#1}%
\protected@edef\@svsec{\@seccntformat{#1}\relax}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa>\z@
\begingroup
#6{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #8\@@par}%
\endgroup
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\else
\@xsect
\def\@svsechd{%
#6{\hskip #3\relax
\@svsec #8}%
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi
\@xsect{#5}%
\ifnum#2=1\relax
\global\def\thissectiontitle{#8}
\global\def\thissectionnumber{\thesection}
\fi%
}
\pretocmd{\section}{\global\toggletrue{noTodos}}{}{}
% the \todo command does the job: the first time it is used after a \section command,
% it writes the information of the section to the list of todos
\AtBeginDocument{%
\xpretocmd{\todo}{%
\iftoggle{noTodos}{
\addtocontents{tdo}{\protect\contentsline {section}%
{\protect\numberline{\thissectionnumber}{\thissectiontitle}}{}{} }
\global\togglefalse{noTodos}
}{}
}{}{}%
}
\makeatother
\begin{document}
\listoftodos
\tableofcontents
\section{My first Section}\todo{Section 1 note}
\subsection{A first Subsection}
\subsubsection{A first subsubsection}\todo{Section 1, section 1, subsection note}
\subsection{Another subsection}\todo{Section 1, section 1, subsection note 2}
\section{My second Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\section{A section without notes}
\subsection{A subsection without notes}
\subsubsection{A subsubsection without notes}
\section{My fourth Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\end{document}
Remarks and explanations
This is basically an adaptation of my answer
to Include chapters in List of Figures with titletoc?
The \todo
command does the job and decide if the section info will be written to the List of Todos; whenever the \todo
command is used in the document, it will examine a boolean flag; if the boolean is false, then it adds the section information to the List of Todos and sets the boolean to true; otherwise, it does not add any information.
The \section
command was also modified to reset the boolean.
\@sect
was modified to globally store the information about the corresponding title and number for the section; this information will then be used when writing to the List of Todos.
Version using titlesec
In the comments it has been mentioned that the titlesec
package is being used (which might produce undesired results with KOMA classes; see Incompatibilities between KOMA-Script and titlesec). In this case, using the explicit
option the code simplifies considerable, since now there's no need to hook into \@sect
to retrieve the name and number for sections:
\documentclass{scrartcl}
\usepackage{todonotes,xpatch,hyperref}
\usepackage[explicit]{titlesec}
% initial definitions for storing the section info (name and number)
\def\thissectiontitle{}
\def\thissectionnumber{}
\newtoggle{noTodos}
\titleformat{\section}
{\normalfont\Large\bfseries\sffamily}
{\thesection}
{0.5em}
{\gdef\thissectiontitle{#1}\gdef\thissectionnumber{\thesection}#1}
\pretocmd{\section}{\global\toggletrue{noTodos}}{}{}
% the \todo command does the job: the first time it is used after a \section command,
% it writes the information of the section to the list of todos
\AtBeginDocument{%
\xpretocmd{\todo}{%
\iftoggle{noTodos}{
\addtocontents{tdo}{\protect\contentsline{section}%
{\protect\numberline{\thissectionnumber}{\thissectiontitle}}{}{} }
\global\togglefalse{noTodos}
}{}
}{}{}%
}
\begin{document}
\listoftodos
\tableofcontents
\section{My first Section}\todo{Section 1 note}
\subsection{A first Subsection}
\subsubsection{A first subsubsection}\todo{Section 1, section 1, subsection note}
\subsection{Another subsection}\todo{Section 1, section 1, subsection note 2}
\section{My second Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\section{A section without notes}
\subsection{A subsection without notes}
\subsubsection{A subsubsection without notes}
\section{My fourth Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\end{document}
Best Answer
The
llncs
class setsso the
todo
items, which are declared as level 1 don't appear:will show the items.