1

enter image description here I'm using the code below to get a todolist of all the comments I have in my document. The problem is the list displays the last section of the document, but it hasn't any comments. Only sections with comments should be displayed. Any Idea how to solve this??

\documentclass{article}

\usepackage{todonotes,tocloft,xpatch,hyperref}

% This is based on classicthesis chapter definition
\let\oldsec=\section
\renewcommand*{\section}{\secdef{\Sec}{\SecS}}
\newcommand\SecS[1]{\oldsec*{#1}}%
\newcommand\Sec[2][]{\oldsec[\texorpdfstring{#1}{#1}]{#2}}%

% http://tex.stackexchange.com/a/61267/11984
\makeatletter
\xapptocmd{\Sec}{\addtocontents{tdo}{\protect\todoline{\thesection}{#1}{}}}{}{}
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[3]{%
  \@ifnextchar\todoline
    {}
    {\contentsline{section}{\numberline{#1}#2}{#3}{}{}}%
}
\let\l@todo\l@subsection
\newcommand{\Endoftdo}{}

\AtEndDocument{\addtocontents{tdo}{\string\Endoftdo}}
\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{My third Section}

\section{My fourth Section}
\end{document}

1 Answer 1

2

The \xapptocmd{\Sec}{\addtocontents{...}}{}{} will add a Toc entry each time if a \section is used, regardless, whether a todo note is there or not.

In my opinion, it should be removed!

If I find some time, I'll provide another solution for the \todoline stuff.

\documentclass{article}

\usepackage{todonotes,tocloft,xpatch,hyperref}

% This is based on classicthesis chapter definition
\let\oldsec=\section
\renewcommand*{\section}{\secdef{\Sec}{\SecS}}
\newcommand\SecS[1]{\oldsec*{#1}}%
\newcommand\Sec[2][]{\oldsec[\texorpdfstring{#1}{#1}]{#2}}%

\newcounter{istodo}[section]

% http://tex.stackexchange.com/a/61267/11984
\makeatletter
%\xapptocmd{\Sec}{\addtocontents{tdo}{\protect\todoline{\thesection}{#1}{}}}{}{}
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
  \newcommand{\@todoline}[3]{%
    \@ifnextchar\todoline{}
    {\contentsline{section}{\numberline{#1}#2}{#3}{}{}}%
}
\let\l@todo\l@subsection
\newcommand{\Endoftdo}{}

\AtEndDocument{\addtocontents{tdo}{\string\Endoftdo}}
\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{My third Section}

\section{My fourth Section}
\end{document}

enter image description here

2
  • But it doesn't display all sections!! Just the ones with a comment in, and also the last section. If I insert sections between they are not included as shown.
    – Simon
    Sep 13, 2015 at 16:34
  • @Simon: I'll have a look later on
    – user31729
    Sep 13, 2015 at 16:36

You must log in to answer this question.

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