5

I'm trying to create a \tbd (To Be Done) macro to add a todonote on a chapter/section/subsection/etc easily with the following properties.

  • to have a useful list of todos with a simple macro call: the todolist entry should represent the place of the todo inside the structure of the document (in the chapter named "C" it should have "TBD: C", in section "S" inside "C" it should have "TBD: C/S")
  • to avoid redundancy: I don't want to type the section title as a caption parameter each and every time. What if I want to change the title?
  • to display TBD in the note only (this seems to be more elegant)
  • preferred: keep the name of the command as \section (and others) (with the use of an optional argument maybe?)
  • preferred (but seems to be unlikely): without messing with the definition of section and friends
  • preferred (but seems to be really messy): with the todonote "pointing" at the title

Note: I've considered the possibility to put \tbd inside the section command (\section{title\tbd}) for the todonote to point at the right place, but this seems to be more pain than gain. Especially if I want to use the title...

Something like this (the blue bordered things are on different pages):

enter image description here

Is there a macro/package for this or does any of you have a similar implementation?

Example is shown using a half (or less) solution. Can I list the current stack of chapter/section/etc somehow?

\documentclass{book}

\usepackage{todonotes}

\newcommand\treeloc{dummy} % this should be replaced

\newcommand\tbd{\todo[caption={TBD: \treeloc}]{TBD}}

\begin{document}

\chapter{C-1}

\section{S-1}\tbd

\section{S-2}

\chapter{C-2}\tbd

\section{S-1}

\section{S-2}

\subsection{SS-1}\tbd

\section{S-3}

\listoftodos

\end{document}

And \treeloc should be changed for the todolist to have these instead of dummies:

  • C-1/S-1
  • C-2
  • C-2/S-2/SS-1

I'm going to work on this, but I thought this was a nice question.

References (I'm considering to use):

3

[THIS IS NOT WHAT YOU WANT, IS IT?]

This does it by parsing \thesubsection, and printing something out if the respective units are not equal to 0. The relevant routines are \getss and \gets.

\documentclass{book}
\usepackage{todonotes}
\usepackage{etoolbox}
\makeatletter
\def\getss#1.#2|{\expandafter\gets#1|\ifstrequal{#2}{0}{}{/SS-#2}}
\def\gets#1.#2|{C-#1\ifstrequal{#2}{0}{}{/S-#2}}
\newcommand\treeloc{\expandafter\getss\thesubsection|}
\makeatother
\newcommand\tbd{\todo[caption={TBD: \treeloc}]{TBD}}

\begin{document}

\chapter{C-1}

\section{S-1}\tbd

\section{S-2}

\chapter{C-2}\tbd

\section{S-1}

\section{S-2}

\subsection{SS-1}\tbd

\section{S-3}

\listoftodos

\end{document}

enter image description here

  • Update: I've tested this poorly. I wanted titles in the treeloc text instead of C-0 and C-1 independently from titles. I will submit my edited version as an answer soon. – masu Nov 8 '13 at 9:42
2

Here's my solution which fits my specification better:

enter image description here

\documentclass[openany,14pt]{book}

\usepackage[a5paper,margin=2cm,bindingoffset=0cm,marginparwidth=1.6cm,marginparsep=0.2cm]{geometry} % for demo only

\usepackage[textwidth=1.6cm]{todonotes}
\usepackage{xpatch}

\def\resetnamelevel#1{%
    \ifnum#1<1\let\thischaptername\relax\fi
    \ifnum#1<2\let\thissectionname\relax\fi
    \ifnum#1<3\let\thissubsectionname\relax\fi
    \ifnum#1<4\let\thissubsubsectionname\relax\fi
}\resetnamelevel{0}

\def\chaptername#1{\resetnamelevel{0}\def\thischaptername{#1}}
\def\sectionname#1{\resetnamelevel{1}\def\thissectionname{#1}}
\def\subsectionname#1{\resetnamelevel{2}\def\thissubsectionname{#1}}
\def\subsubsectionname#1{\resetnamelevel{3}\def\thissubsubsectionname{#1}}

\let\Chaptermark\chaptermark
\let\Sectionmark\sectionmark
\let\Subsectionmark\subsectionmark
\let\Subsubsectionmark\subsubsectionmark
\def\chaptermark#1{\chaptername{#1}\Chaptermark{#1}}
\def\sectionmark#1{\sectionname{#1}\Sectionmark{#1}}
\def\subsectionmark#1{\subsectionname{#1}\Subsectionmark{#1}}
\def\subsubsectionmark#1{\subsubsectionname{#1}\Subsubsectionmark{#1}}

\makeatletter
\newcommand\treeloc{%
    \ifx\thischaptername\relax%
        ??\@latex@warning{\textbackslash treeloc called outside of structure}
    \else
        \thischaptername%
        \ifx\thissectionname\relax%
        \else
            \ /\ \thissectionname%
            \ifx\thissubsectionname\relax%
            \else
                \ /\ \thissubsectionname%
                \ifx\thissubsubsectionname\relax%
                \else
                    \ /\ \thissubsubsectionname%
                \fi
            \fi
        \fi
    \fi
    }
\makeatother

\newcommand\tbd{%
    \todo[caption={TBD: \expandafter\treeloc}]{TBD}
}

\begin{document}

TREELOC: \treeloc

\chapter{Chapter one}\tbd
TREELOC: \treeloc

\section{Section one}\tbd
TREELOC: \treeloc

\subsection{Subsection one}\tbd
TREELOC: \treeloc

\subsubsection{Subsubsection one}\tbd
TREELOC: \treeloc

\subsection{Subsection two}\tbd
TREELOC: \treeloc

%\chapter*{Not indexed chapter}\tbd
%TREELOC: \treeloc

%\chapter*{Unset chapter}\resetnamelevel{0}\tbd
%TREELOC: \treeloc

\chapter*{Manually named chapter}\chaptername{Manually named chapter}\tbd
TREELOC: \treeloc

\section*{Manually named section}\sectionname{Manually named section}\tbd
TREELOC: \treeloc

\listoftodos

\end{document}

If there's no chapter name set, then a warning is raised and ?? is displayed.

enter image description here

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.