1

I added a counter to the todonotes packages \todo so I could display the total number of todos I have left. However I also enjoy working with the package option disabled. Therefore I would like to wrap the part where I typeset the counter in a conditional that is only executed when the packageoption disable is NOT given. However I do not know how I can access this package option.

MWE:

\documentclass{report}
\usepackage{letltxmacro}                        %properly rename protected macros
\usepackage{totcount}                           %counter totals before last increment
\usepackage{xcolor}                             %for the red text (will be loaded by todonotes but for completness)
\usepackage{todonotes}
\usepackage{hyperref}                           %make links in listoftodos clickable

\newtotcounter{todocounter}
\LetLtxMacro{\oldTodo}{\todo} %avoid endless recursion be redefining \todo as \todo+x
\renewcommand{\todo}[2][]{\stepcounter{todocounter}\oldTodo[#1]{#2}}

\begin{document}
\LARGE{\textcolor{red}{\total{todocounter} todos left}} %if wrap this line
\todo{1}

later
\todo{some more}
\listoftodos
\end{document}
ted
  • 3,377
  • @cgnieder: you "awnsered" quite often by leaving a key comment, this always makes me think if you just want me to close/remove the question due to beeing to localized or similar. But since you bothered to give a nice detailed awnser I wonder why you do this. (I hope this does not sound offensive, if it should, it is not meant that way) – ted Aug 03 '13 at 08:28
  • I sometimes do that when I'm not sure if my answer is the best way or when the question lacks an MWE or if I don't have the time to compose a full answer or ... it doesn't mean much :) – cgnieder Aug 03 '13 at 08:32
  • Also see http://meta.tex.stackexchange.com/questions/3238/why-do-people-answer-in-comments – cgnieder Aug 03 '13 at 08:33

1 Answers1

2

The disable option sets \@todonotes@disabledtrue, i.e., a conditional that can be tested with

\if@todonotes@disabled
  ...
\else
  ...
\fi

The code below wraps this in a command \iftodonotes{<true>}{<false>} which is more convenient to use as it doesn't contain @ as a letter.

BTW: \LARGE does not take an argument but is a font property switch. Instead of \LARGE{...} you should write {\LARGE ...} (i.e., place the call in a group) otherwise following text will also be \LARGE until you set another size again.

\documentclass{report}
\usepackage{letltxmacro}
\usepackage{totcount}
\usepackage{xcolor}
\usepackage[disable]{todonotes}
\usepackage{hyperref}

\newtotcounter{todocounter}
\LetLtxMacro{\oldTodo}{\todo}
\makeatletter
% this defines \iftodonotes{<true>}{<false>}
\newcommand*\iftodonotes{%
  \if@todonotes@disabled
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
\makeatother
\renewcommand{\todo}[2][]{\stepcounter{todocounter}\oldTodo[#1]{#2}}

\begin{document}
\iftodonotes
  {{\LARGE\textcolor{red}{\total{todocounter} todos left}}}
  {}

\todo{1} foo

later \todo{some more}

\listoftodos

\end{document}
cgnieder
  • 66,645
  • For those that don't know about \@secondoftwo like me: http://tex.stackexchange.com/q/21262/19326. If I need that if only once would there be any reason against simply using the part inside the newcommand definition directly? – ted Aug 03 '13 at 08:25
  • You can of course use \if@todonotes@disabled directly (you'd have to make @ at letter before you use it and should make it other again afterwards). However, I think it's much cleaner to define a new command with a LaTeX syntax. And who knows: maybe you find out later that there are more places where you want to use it. – cgnieder Aug 03 '13 at 08:30