1

Pretext: I am aware of packages such as todonotes, todo, and fixme, but this is more of a task for learning LaTeX programming. Therefore, the use of additional packages downloaded from CTAN is discouraged. Would also like to avoid using additional *.sty files.

How does one create a command in the main *.tex for a counted item to be later displayed in a listing? For example:

Text before\todo[optional caption]{my text here}. 
Some other text in the document\todo{another todo but without caption}.

The todo note will be coloured, prefixed, or otherwise marked in the inline text. Calling \listoftodos will then create a list of the \todos in the document and generate a (hyperlinked) list similar but separate to \tableofcontents, where the content in {} will be replaced by that in [] if and only if it is present, with the page number on the right. This list will only need a single level of depth.

Was looking through the source code for the todonotes package, but could not make much sense of it. From what I can tell, this task will require defining two new commands, storing the texts in a list of todos, handling optional arguments, and finally making a referenced list of todos using hyperref in a(nother) table of contents. The list will be written to the *.aux file.

Bonus:

  • Safety to be used within an equation or section header, safety to have formatting or an equation within the note

  • How can options be added? A simple show or hide option for the inline text (while still being displayed in the \listoftodos) would be nice.

  • Can this method be extended for other items? \myitem, \listofmyitems, \otheritems, \listofotheritems?

Addendum: is there any advanced guide online for programming (La)TeX? This will be helpful for any future ventures.

3
  • Welcome to TeX.SX! Would etoolbox and xparse be allowed, as a helper package?
    – user31729
    Commented Feb 22, 2015 at 8:51
  • @ChristianHupfer Unless absolutely necessary (or lack thereof produces bunch of overhead), please avoid. Getting into the heart of LaTeX seems like an interesting challenge.
    – dbwa
    Commented Feb 22, 2015 at 9:07
  • The request for [] as optional list-of-todos entry and for options is tricky. I suggest either a second [] (easy to get with xparse or an option for the toc entry)
    – user31729
    Commented Feb 22, 2015 at 9:37

1 Answer 1

1

A preliminary version, without option keys

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{etoolbox}%
\usepackage{blindtext}% Just as text filler
\usepackage{hyperref}
\makeatletter
\def\todolist{}

\newcounter{todolistcounter}

\newcommand{\ToDo}{%
  \@ifnextchar[{\todoopt}{\todonoopt}%
}%

\newcommand{\todonoopt}[1]{%
  \refstepcounter{todolistcounter}
  % \addcontentsline{todo}{section}{\thetodolistcounter~#1} % No contents line
  \listgadd{\todolist}{#1}%
   #1%
   %      \colorbox{green}{\thetodolistcounter~#1}
}

\newcommand{\todoopt}[2][]{%
  \refstepcounter{todolistcounter}
  \addcontentsline{todo}{section}{\thetodolistcounter~#1}
  \listgadd{\todolist}{#2}%
   #2%
   %      \colorbox{green}{\thetodolistcounter~#2}
}%



\newcommand{\listoftodos}{%
  \section{List of Todos}
  \@starttoc{todo}
  \clearpage
}%

% inline display (as a enumerate) list 
\newcommand{\InTextListOfToDos}{%
\begin{enumerate}%
  \renewcommand*{\do}[1]{%
  \item ##1%
  }
  \dolistloop{\todolist}%
\end{enumerate}%
}


\makeatother

\begin{document}
\listoftodos
\ToDo{first} \ToDo{We}

\blindtext[5] \ToDo[should not]{should} \blindtext[10]\ToDo{start from scratch}
\ToDo{\begin{equation}
    E = mc^2%
    \end{equation}%
}

\blindtext

\section{The ToDos}

\section{A heading with a ToDo \protect\ToDo{Something}}


\InTextListOfToDos


\end{document}
2
  • Storing whole math equation environments and handle them in to another command is not easy. I'll try to get a workaround
    – user31729
    Commented Feb 22, 2015 at 11:14
  • Haven't seen any other input, so this will do. Thanks for the starter on lists, counters, and conditions!
    – dbwa
    Commented Mar 2, 2015 at 4:19

You must log in to answer this question.

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