44

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.

6
  • 3
    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, 2012 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, 2012 at 12:08
  • I agree. Now that I read it again, my first suggestion is already covered in the question...
    – Psirus
    Jan 27, 2012 at 12:13
  • Would \newcommand{\xtodo}[1]{{\tikzexternaldisable\todo{#1}}} or similar not do the trick? Jan 27, 2012 at 12:25
  • 2
    The documentation of the package now mentions the same solutions suggested here, namely \newcommand{\ruggedtodo}[2][]{\tikzexternaldisable\todo[#1]{#2}\tikzexternalenable}
    – papabravo
    Feb 15, 2013 at 10:10

4 Answers 4

47

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
2
  • 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, 2012 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, 2015 at 11:48
14

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}
0

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].
<to be read again> 
\tikzexternal@orig@tikzfadingfrompicture 
l.18 \missingfigure{Ah!}
1
  • Finally, I managed to overcome the issues you encountered. You may want to have a look at my answer.
    – rook
    May 19, 2013 at 15:30
0

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

\newcommand{\todo}[1]{%
  % Add to todo list
  \addcontentsline{tdo}{todo}{\protect{#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
  % Add to todo list
  \addcontentsline{tdo}{todo}{\protect{#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}%
  \tikzexternalenable
  %
}%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .