3

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

  • I have a homebrewed version here: tex.stackexchange.com/questions/140310/…. 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
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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.