[Tex/LaTex] Tracking changes

changes

I'm writing a thesis using latex. My supervisor asked me to make few changes so, after checking this site, I found several solutions to track them, and finally decided to use the changes package.

I sent him my document with more than 100 changes. He approved almost all them, and then he suggested several new ones…. and asked me to send a new document with ONLY the new changes.

I know that using changes package I can use 'final' option to disable markup of changes, but my latex code still has all the \added{} \replaced{}{} and \deleted{}, so my question is:

Is there any easy way to hide changes from revision 1, and show new ones I'll add now?

EDIT: As suggested, I'm adding an example that shows what I've, and another one of what I'm looking for.

This is what my first revised text may look like:

\documentclass{article}

\usepackage{changes}
% Example of what first revision may be

\begin{document}

This is \added{new} text.

This is \deleted{unnecessary}text.

This is \replaced{nice}{bad} text. 

\end{document}

And this is what my second revised text I want to look like (of course, I don't want to manually remove the \added, \deleted, \replaced commands, just want the changes package to ignore them)

\documentclass{article}

\usepackage{changes}
% Example of what second revision should look like

\begin{document}

This is new text.

This is text.

This is nice text. 

\added{This should be seen as a change in revision 2 of document}

\end{document}

So, if you compile both documents, you'll see what I want to achieve, but, obviously, without having to manually remove the \added, \deleted, \replaced commands.

I'm using Miktex+Texmaker (windows port), and it defaults to pdflatex to compile.

Thanks in advance

Best Answer

Replace each instance of \added with \xadded in your source file. Define \xadded appropriately. Do the same for the other two change commands. You can do that with awk (as below) or with search and replace in your favorite editor.

version1.tex:

\documentclass{article}

\usepackage{changes}
% Example of what first revision may be

\newcommand{\xadded}[1]{#1}
\newcommand{\xdeleted}[1]{}
\newcommand{\xreplaced}[2]{#1}

\begin{document}

This is \added{new} text. This is more \added{new text with
\emph{embedded} \TeX{} on more than one line.}

This is \deleted{unnecessary}text.

This is \replaced{nice}{bad} text. 

\end{document}

version2.tex, after replacement:

\documentclass{article}

\usepackage{changes}
% Example of what first revision may be

\newcommand{\xadded}[1]{#1}
\newcommand{\xdeleted}[1]{}
\newcommand{\xreplaced}[2]{#1}

\begin{document}

This is \xadded{new} text. This is more \xadded{new text with
\emph{embedded} \TeX{} on more than one line.}

This is \xdeleted{unnecessary}text.

This is \xreplaced{nice}{bad} text. 

\end{document}

The script I used:

#!/usr/bin/awk
# Rename a few TeX macros
#
{
    gsub(/\\added/,"\\xadded",$0);
    gsub(/\\deleted/,"\\xdeleted",$0);
    gsub(/\\replaced/,"\\xreplaced",$0);
    print
}

Leaving my original awkward partial solution for a little while.

Here's the start of awk program to expand the three macros.

#!/usr/bin/awk
# Expand a few TeX macros
#

# delete the macro name
# leaving the parentheses doesn't hurt
/\\added/ { 
    sub(/\\added/,"",$0) 
}

# delete the macro name and its argument
/\\deleted/ { 
    sub(/\\deleted.*\}/,"",$0) 
}

# should delete the macro name and its SECOND argument
/\\replaced/ { 
    sub(/\\replaced/,"",$0)
}
{print}

Calling the OP's input file expandsome.tex, the command

 $ awk -f expand.awk < expandsome.tex > expanded.tex

produces

documentclass{article}

\usepackage{changes}
% Example of what first revision may be

\begin{document}

This is {new} text.

This is text.

This is {nice}{bad} text. 

\end{document}

I haven't yet figured out the regular expression syntax for deleting the second argument to \replace. I have no time now. If someone wants to contribute then I won't have to find the time tomorrow or the day after ...

This is not a robust solution. If a change spreads over more than one line it will fail. It will also fail for multiple similar changes on any single line.