## Friday, September 14, 2007

### Todo notes in Latex

An updated version of the code below can be found at http://midtiby.blogspot.com/2008/05/updated-todonotes-package.html.

This is a description of how to place todo notes in your latex document, and how to collect the content of these in a structure like a table of contents (eg. a list of things todo)

A year and a half ago, when I wrote my bachelor report, I had a need to mark needed changes in the margin of a latex document. I wanted to place a note in the margin with a command like
  \todo{Something that has to be done}

The solution was to use the marginpar command, in the definition below
  \newcommand{\todo}[1]{\marginpar{#1}}

Later this approach was improved by generating a list of these todo items. The behavior of \todo was now to print something in the margin and add an item in the todolist.
  \newcommand{\todo}[1]{    \addcontentsline{tdo}{todo}{\protect{#1}}    \marginpar{#1}}

Additionally I defined a command to generate the list of todos.

Now the list of todo's could be inserted by using the command
  \listoftodos

For some time ago, I began reading about the portable graphics format (PGF) and wanted to tinker a bit with it. PGF is a great tool for generating graphics for latex documents (you can find a lot of examples at www.fauskes.net/pgftikzexamples/.) Especially the possibility of overlaying your existing text with graphics were interesting.

One of the results is this improved todo note code for latex.
  \newcommand{\todo}[1]{  % Add to todo list  \addcontentsline{tdo}{todo}{\protect{#1}}  %  \begin{tikzpicture}[remember picture, baseline=-0.75ex]      \node [coordinate] (inText) {};  \end{tikzpicture}  %  % Make the margin par  \marginpar{      \begin{tikzpicture}[remember picture]          \definecolor{orange}{rgb}{1,0.5,0}             \draw node[draw=black, fill=orange, text width = 3cm] (inNote)                   {#1};      \end{tikzpicture}  }  %  \begin{tikzpicture}[remember picture, overlay]      \draw[draw = orange, thick]          ([yshift=-0.2cm] inText)              -| ([xshift=-0.2cm] inNote.west)              -| (inNote.west);  \end{tikzpicture}  %  }

Currently there are a minor glitch of the code, at the location of the \todo command latex inserts a large amount of space, which I would like to avoid.

I use this piece of code myself, but if any of you would like to use it you should be welcome. Comments or ideas for improving the code are of cause welcome

Henrik