Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
@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 3 '13 at 8: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 3 '13 at 8:32
    
Also see meta.tex.stackexchange.com/questions/3238/… –  cgnieder Aug 3 '13 at 8:33
add comment

1 Answer

up vote 2 down vote accepted

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}
share|improve this answer
    
For those that don't know about \@secondoftwo like me: 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 3 '13 at 8: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 3 '13 at 8:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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