# “Trackchanges”: respecting the equation environment

I am using trackchanges for monitoring changes in a LaTeX document.

I have a problem when compiling a trackchange tag with a equation environment embedded into it. Here is a .tex file which compiles

\documentclass[A4]{article}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{trackchanges}
\begin{document}

\section{dog}
There is a tree\remove[alexm]{but I remove a cat}. My hair is
\change[alexm]{green}{red}.

\end{document}


This file compiles fine and a .pdf is produced as it should be. But now with an equation being shown:

\documentclass[A4]{article}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{trackchanges}
\begin{document}
\section{dog}
There is a tree\remove[alexm]{but I remove a cat}. My hair is
\change[alexm]{green}{red}.

Now with an equation it fails, but why?
$$1+1=2$$
and some more text.}

\end{document}


This gives fatal compiling errors. Is there a way to keep it from failing, any protective tags? It doesn't matter if it doesn't display properly, as long as it compiles, since it is for draft purposes anyways, but it would be a bonus.

-
What are the errors it gives? It would help if you could post a minimal file that can be compiled to give the errors you are experiencing. –  Aaron Apr 15 '11 at 0:24

I believe the best solution here is to use \protect, so:

\add[alexm]{some text
\protect $$1+1=2$$
and some more text.}


may meet your needs. I've used \protect for things like the itemize environment as well.

-
Thanks for pointing this out. I could swear I tried it before posting my answer, but obviously I didn't. –  Alan Munn May 14 '11 at 0:05
thanks a ton!! Could you give any intuition about this solution as well? It would be an appretiated addition :) –  Vass May 14 '11 at 14:19
@Vass I would refer to this post regarding fragile/robust commands. –  Matt Kolb May 16 '11 at 13:37

The trackchanges package defines its \add command (roughly) to set the colour of its argument and pass it to the \ul command of the soul package for underlining. You simply can't pass any environment to the \ul command. (So it's not just equations that won't work; no environment will work.) The only way around this, as far as I can see is to never put environments inside the \add command, but instead use \add commands around the added environments.

Edit: (Solution due to Matt Kolb) It seems that just protecting environments within the \add command actually works:

\documentclass[]{article}
\usepackage{trackchanges}
\usepackage{amsmath, amsthm, amssymb}
\begin{document}
\section{dog}
There is a tree\remove[alexm]{but I remove a cat}. My hair is
\change[alexm]{green}{red}.

Now with an equation it fails, but why?

\protect$$1+1=2$$

@Vass See What is the difference between Fragile and Robust commands? for what \protect does. –  Alan Munn May 14 '11 at 14:58