LaTeX todonotes for printing

The LaTeX package <code>todonotes</code> is nice for added todo-notes to documents. The problem is the default settings (orange colored background) will waste printer ressources if you print intermediate versions of the document.

I have found a nice way around it by using the “Optional Content Group” feature of PDFs. The following command generates two todos on top of each other, one with the orange background which will not be printed, and another with white background for printing.

It is quite a dirty hack, but it works well for me. The only problem I found so far is that it will not work in captions.

\usepackage{ocg-p}
\usepackage[linecolor=black]{todonotes}
\newif\ifPrintTODO
\PrintTODOtrue % comment this line to omit todos
\ifPrintTODO
    \makeatletter
    \newcommand{\printInWhiteTODO}[2][inline]{
        ~\newline
        \newsavebox\todoboxa
        \savebox\todoboxa{\begin{ocg}[printocg=never]{ToDo screen}{todo4screen}{1}
        \todo[#1,inline]{#2}
        \end{ocg}}
        \newsavebox\todoboxb
        \savebox\todoboxb{\begin{ocg}[printocg=always]{ToDo print}{todo4print}{0}
        \todo[#1,bordercolor=\@todonotes@currentlinecolor, backgroundcolor=white, inline, nolist]{#2}
        \end{ocg}}
        \noindent\usebox\todoboxb\llap{\usebox\todoboxa}
        \global\let\todoboxa\relax
        \global\let\todoboxb\relax
    }
    \makeatother
\else
    \newcommand{\printInWhiteTODO}[2][]{}
\fi

\newcommand{\TODO}[2][]{\printInWhiteTODO[#1]{#2}}
\newcommand{\TODOY}[1]{\printInWhiteTODO[color=yellow]{#1}}

Update: Added the possibility to pass additional arguments. Also the border color in print will match the background color on screen.