4

In this MWE, I made two commands to highlight parts of the text as a reviewer comment, while the comments are colored uniquely to indicate the author whose comment is typeset.

If I want to make two listoftodos, each has the comments entries of one author, how can it be done?

\documentclass{article}
\usepackage{hyperref,lipsum}

\usepackage[textwidth=2.5cm,colorinlistoftodos]{todonotes}
\setlength{\marginparwidth}{2.5cm}

\newcommand\stR[2]{% 1st reviewer comment
    \todo[%
    author=1st Reviewer,noline,caption={1st Reviewer #1 Comment},color=blue!20%
    ]%
    {#1 Comment}{\color{blue}{\bfseries#2}}}

\newcommand\ndR[2]{% 2nd reviewer comment
    \todo[%
    author=2nd Reviewer,noline,caption={2nd Reviewer #1 Comment},color=red!50!white%
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}

\begin{document}
\listoftodos[Reviewers Comments]
\section{Section}
Text \stR{2nd}{2nd comment of the 1st reviewer} another text\vspace{\baselineskip}
\lipsum[1]\vspace{\baselineskip}
Some text \ndR{1st}{1st comment of the 2nd reviewer} continue text
\end{document}

enter image description here

Diaa
  • 9,599
  • I have a homebrewed version here: http://tex.stackexchange.com/questions/140310/multiple-lists-of-to-do-notes/168160#168160. Unfortunately for you, no other answer using todonotes arose from that question. – Steven B. Segletes Sep 15 '16 at 17:40
  • @StevenB.Segletes Thanks for your input. I would be grateful if you could adjust your code to make an output close to that of todonotes package. – Diaa Sep 15 '16 at 17:48
  • 1
    Unfortunately, that would take more work than I am willing to invest at the moment. Perhaps someone else will have a suitable idea. Best wishes. – Steven B. Segletes Sep 15 '16 at 17:50
  • @StevenB.Segletes your consideration is appreciated :) – Diaa Sep 15 '16 at 17:50

1 Answers1

5

A bit hackish but imho it should work. Be aware that it assumes that you use hyperref.

\documentclass{article}
\usepackage{hyperref}
\usepackage{lipsum}

\usepackage[textwidth=2.5cm]{todonotes}
\setlength{\marginparwidth}{2.5cm}

\usepackage{etoolbox}

\makeatletter
\newcommand\@todonotes@owner{default}
\define@key{todonotes}%
    {owner}{\def\@todonotes@owner{#1}}

\newtoggle{ownerdefault}
\newtoggle{ownerB}


\newcommand\stR[2]{% 1st reviewer comment
    \todo[%
    owner=default,
    author=1st Reviewer,noline,caption={1st Reviewer #1 Comment},color=blue!20%
    ]%
    {#1 Comment}{\color{blue}{\bfseries#2}}}

\newcommand\ndR[2]{% 2nd reviewer comment
    \todo[%
    owner=B,
    author=2nd Reviewer,noline,caption={2nd Reviewer #1 Comment},color=red!50!white%
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}



\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
     \addtocontents{tdo}
      {%
       \protect\iftoggle{owner\@todonotes@owner}
         {%
          \protect\contentsline {todo}
            {\protect\fcolorbox{\@todonotes@currentbordercolor}%
                {\@todonotes@currentbackgroundcolor}%
                {\protect\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption
            }{\thepage}{\@currentHref}%
          }{}%
       }%
    \else%
      \addtocontents{tdo}
      {%
       \protect\iftoggle{owner\@todonotes@owner}
         {%
          \protect\contentsline {todo}
            {\@todonotes@caption
            }{\thepage}{\@currentHref}%
          }{}%
       }%
    \fi}%

\makeatother
\begin{document}
\toggletrue{ownerdefault}
\section*{Reviewers 1 Comments}
\InputIfFileExists{\jobname.tdo}{}

\toggletrue{ownerB}
\togglefalse{ownerdefault}
\section*{Reviewers 2 Comments}
\InputIfFileExists{\jobname.tdo}{}

\togglefalse{ownerB}
\makeatletter \@starttoc{tdo}\makeatother % to trigger the creation of the list

\section{Section}
Text \stR{2nd}{2nd comment of the 1st reviewer} another text\vspace{\baselineskip}
\lipsum[1]\vspace{\baselineskip}
Some text \ndR{1st}{1st comment of the 2nd reviewer} continue text
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • This answer restored my faith in LaTeX :). I would like to ask for something overkill if you don't mind. Can I make the entries in each list sorted according to the comment number not to its appearance? For example, if the 2nd comment is in page 1, while the 1st comment in page 2, how can I make listoftodos print the entry of the 1st comment before that of 2nd comment? I know it is overkill, but it would be much appreciated if you could consider this. – Diaa Sep 15 '16 at 19:29
  • Additionally, how can I get the same output if I removed the option colorinlistoftodos?, because I found it a bit annoying to have the same color for each entry in the same list. – Diaa Sep 15 '16 at 19:38
  • Regarding the option: You will have to replace the \addcontentsline{tdo}{todo}{\@todonotes@caption} with similar code then before the \else. I didn't understand your first question, make a new question with an example, but don't expect an answer today. – Ulrike Fischer Sep 15 '16 at 19:53
  • I am so sorry, but I don't understand what you mean by similar code. – Diaa Sep 15 '16 at 19:58
  • I think I figured out how it works without using colorinlistoftodos option. All what I needed to do is to revamp the junk piece of code to be \renewcommand{\@todonotes@addElementToListOfTodos}{% \addtocontents{tdo} {% \protect\iftoggle{owner\@todonotes@owner} {% \protect\contentsline {todo} {\@todonotes@caption}{\thepage}{\@currentHref}% }{}% }% }% – Diaa Sep 15 '16 at 20:16
  • yes that's the idea. I just added the code to the branch. It should now work with and without the option, – Ulrike Fischer Sep 15 '16 at 20:23
  • I am happy you didn't give up on me :) Many thanks. I think I will ask a new question on how to sort the entries regardless their appearances someday later :) – Diaa Sep 15 '16 at 20:25
  • If you don't mind, I would like to understand how to address some issues: 1- how to make the page(s) containing listoftodos without numbers, so the article title page always starts at page 1? 2- if I don't have any comments/entries, how can I make the listoftodos page(s) not generated at all? 3- Is there a short way to switch on/off the creation of listoftodos without revamping the whole code? Your consideration is highly appreciated. – Diaa Sep 17 '16 at 13:34
  • I am sorry, but after testing again the code in some way, I found that normal \todo notes are automatically assigned to the toggle ownerB, which makes them be listed in its list of todos. Is there any way to make the normal command \todo create another normal list of todos without appending its entries to other toggles'? – Diaa Feb 21 '17 at 22:08