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'm using the todonotes package to add notes in my documents. The \listoftodos command adds a ToC for todos.

Instead of the page numbers in this ToC, I would like to display another value, for example \thesection. The todonotes package manipulates a ToC named .tdo, so I'm guessing I can do that with tocloft but so far I've failed to achieve it.

Here is a MWE:

\documentclass{scrbook}

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

\begin{document}

\chapter{My first chapter}

\section{A first section}

\lipsum

\todo{This is a note}

\section{Another section}

\lipsum

\todo{This is another note}


\listoftodos


\end{document}

The two notes have page numbers 2 and 3 respectively. I would like them to show 1.1 and 1.2 (section numbers) instead. How can I do that?

share|improve this question
    
please provide a MWE. –  Marco Daniel May 23 '11 at 7:03
    
OK, added a MWE. –  ℝaphink May 23 '11 at 7:12
add comment

2 Answers

Update!!!

The following solution sets the correct width of \@pnumwidth

\documentclass{scrbook}

\usepackage{todonotes}
\usepackage{tocloft}
\usepackage{lipsum}
\usepackage{showframe}
\makeatletter
\def\myaddcontentsline#1#2#3{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at p. \thepage}}}
\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
        \myaddcontentsline{tdo}{todo}{{%
            \colorbox{\@todonotes@currentbackgroundcolor}%
                {\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption}}%
    \else%
        \myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}%
    \fi}%
\newcommand*\mylistoftodos{%
  \begingroup
       \setbox\@tempboxa\hbox{see 9.9 at p. 99}%
       \renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
       \renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
       \listoftodos%
  \endgroup
}
\makeatother

\begin{document}
\chapter{My first chapter}
\section{A first section}
\lipsum
\todo{This is a note}
\section{Another section}
\lipsum
\todo{This is another note}

\mylistoftodos
\end{document}

The result is:

enter image description here

share|improve this answer
    
@Marco: the \protect in lines 6 and 11 do nothing, since they only protect an open brace. I think that a bug report should be filed to the package's author. –  egreg May 23 '11 at 7:55
    
@Egreg: You are right. I only copied the peace of code :-) . Do you send the bug greport. –  Marco Daniel May 23 '11 at 8:20
    
It doesn't work for me : ! LaTeX Error: \@todonotes@addElementToListOfTodos undefined. –  ℝaphink May 24 '11 at 6:31
    
Which version of TL do you have? Maybe you only need an update. –  Marco Daniel May 24 '11 at 7:32
1  
To make it compatible with hyperref it should be \addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at p. \thepage}{}}} (extra pair of curly braces at the end), @midtiby: you may want to update the example in the todonotes manual. –  Jörg Jun 22 '12 at 10:54
show 7 more comments
up vote 0 down vote accepted

Since it is the only ToC in my document, I have found that redifining \addcontentsline works fine and is quite straightforward:

 \renewcommand{\addcontentsline}[3]{%
   \addtocontents{#1}{\protect\contentsline{#2}{#3}{\tododate}{section*.\thesection}}
 }

The only side effect I've seen is that it ruins the bookmarks in the PDF. That is OK for my draft (which is why I use todonotes), but not for my final document, so my solution so far is to make a package that wraps up todonotes and passes it the disable option:

\ProvidesPackage{review}
\let\review@disable\@empty
\let\review@dateinlist\@empty
\DeclareOption{disable}{\def\review@disable{true}}
\DeclareOption{dateinlist}{\def\review@dateinlist{true}}
\ProcessOptions


% Put dates instead of page numbers in listoftodos
\newcommand{\tododate}{%
  \thesection~\chaphead
}

\ifx\review@disable \@empty
  \usepackage[french,colorinlistoftodos,textsize=small]{todonotes}
  \ifx\review@dateinlist \@empty
  \else
    \renewcommand{\addcontentsline}[3]{%
      \addtocontents{#1}{\protect\contentsline{#2}{#3}{\tododate}{section*.\thesection}}
    }
  \fi
\else
  \usepackage[french,colorinlistoftodos,textsize=small,disable]{todonotes}
\fi

This way, I can call my package in different ways:

\usepackage{review} % normal style
\usepackage[dateinlist}{review} % date instead of page numbers
\usepackage[disable]{review} % disable todonotes and do not mess up bookmarks
share|improve this answer
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.