# todonotes and tikzexternalize

In my document I use todonotes and TikZ/pgfplots. After activating the externalization in TikZ I realized that todonotes are all exported as well (because they are based on TikZ).

This behaviour is inconvenient, it would be much better for me to tell tikz-external to ignore all \todo.

I know I can generally disable the externalization with \tikzset{external/export=false} and turn it on only for selected plots, but the inverse would be more convenient.

• At the start of the document say \tikzexternaldisable, and then wrap the normal figures in \tikzexternalenable {your tikz code} \tikzexternaldisable. I haven't tested it, but that should be possible, no? Or wrap the todo macros in a personal macro using the reverse. I don't use todonotes, so I can't say how that would look. – Psirus Jan 27 '12 at 11:59
• @Psirus: I'm not experienced in TikZ, but wrapping the todo macro sounds better because you only have to do it once in the preamble and can easily change it later. – doncherry Jan 27 '12 at 12:08
• I agree. Now that I read it again, my first suggestion is already covered in the question... – Psirus Jan 27 '12 at 12:13
• Would \newcommand{\xtodo}[1]{{\tikzexternaldisable\todo{#1}}} or similar not do the trick? – Martin Scharrer Jan 27 '12 at 12:25
• The documentation of the package now mentions the same solutions suggested here, namely \newcommand{\ruggedtodo}[2][]{\tikzexternaldisable\todo[#1]{#2}\tikzexternalenable} – papabravo Feb 15 '13 at 10:10

I had this very problem a while ago, just for the \todo command (I never use \missingfigure). Here's how I fixed it (place this in your preamble, somewhere after todonotes and tikz/pgfplots is called):

\makeatletter
\renewcommand{\todo}[2][]{\tikzexternaldisable\@todo[#1]{#2}\tikzexternalenable}
\makeatother


Now, \todo will be ignored by the externalization process.

Hence, for the \missingfigure command you need

\makeatletter
\renewcommand{\missingfigure}[2][]{\tikzexternaldisable\@missingfigure[#1]{#2}\tikzexternalenable}
\makeatother

• Your redefinition of the \missingfigure command does not work, as there is no \@missingfigure in the package. I am not sure though how to do it differently; trying to use \let\oldmissingfigure\missingfigure causes LaTeX to complain about TeX capacity being exceeded. – mSSM Jul 18 '12 at 15:05
• the replacement of \todo works fine, however for \missingfigure the solution provided by @rook (tex.stackexchange.com/a/115095/4419) works fine – kromuchi Sep 16 '15 at 11:48

For me neither of the proposed solutions worked. Maybe it is platform-dependent, taking into consideration the significant number of up-votes in favor of the accepted answer.

However, mSSM's approach with \let was close. The reason for it not to work properly with \missingfigure is that the latter consumes an optional argument. The simple \let fails to copy all required information to a new macro. According to this piece, one should use the letltxmacro package. Eventually, my working version is:

\usepackage{letltxmacro}

\LetLtxMacro{\oldmissingfigure}{\missingfigure}
\renewcommand{\missingfigure}[2][]{\tikzexternaldisable\oldmissingfigure[{#1}]{#2}\tikzexternalenable}

\LetLtxMacro{\oldtodo}{\todo}
\renewcommand{\todo}[2][]{\tikzexternaldisable\oldtodo[#1]{#2}\tikzexternalenable}


I have played around with \missingfigure, but a simple \renewcommand{\missingfigure}... will not work, as given in the answer by @Frits.

The only solution I found was defining a new command:

\newcommand{\extmissingfigure}[2][]{\tikzexternaldisable\missingfigure[#1]{#2}\tikzexternalenable}


Working with \let, i.e.:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{todonotes}

\tikzexternalize

\let\oldmissingfigure\missingfigure
\renewcommand{\missingfigure}[2][]{\tikzexternaldisable\oldmissingfigure[#1]{#2}\tikzexternalenable}

\begin{document}

\missingfigure{Ah!}

\end{document}


unfortunately raises an error:

! TeX capacity exceeded, sorry [input stack size=5000].
l.18 \missingfigure{Ah!}

• Finally, I managed to overcome the issues you encountered. You may want to have a look at my answer. – rook May 19 '13 at 15:30

I found another workaround which just modifies the original implementation of the todo command. Just modify

\newcommand{\todo}[1]{%
%
\begin{tikzpicture}[remember picture, baseline=-0.75ex]%
\node [coordinate] (inText) {};
\end{tikzpicture}%
%
% Make the margin par
\marginnote{%
\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}%
%
}%


by inserting \tikzexternaldisable before and \tikzexternalenable after the tikzpicture envoronment:

\newcommand{\todo}[1]{%
\tikzexternaldisable
%
\begin{tikzpicture}[remember picture, baseline=-0.75ex]%
\node [coordinate] (inText) {};
\end{tikzpicture}%
%
% Make the margin par
\marginnote{%
\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}%
\tikzexternalenable
%
}%