Posted on

Highlighting changes in LaTeX

In order for the package to work, do the following:

  • create a trackchanges.sty file containing the code at the bottom of this post
  • add \usepackage{trackchanges} to the preamble of your article
  • adjust your text using one of the following commands:
    • \removed{the text you want to remove} will result in red strike through text
    • \added{new text}will result in green new text
    • \changed{new text}{old text}will combine the two above, new text will have the added markup, old text the removed markup

    When building your .tex document twice, change bars will also be added in the margin of the document.


The snippet of code:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{trackchanges}[2013/02/20 tvandenbrande style for track changes in the elsevier template]
\RequirePackage{changebar}
\RequirePackage{xcolor}
\RequirePackage{ulem}

\newif\ifdiff
\difftrue % activate this line to show the changes
%\difffalse %activate this line to apply changes

\ifdiff
\newcommand{\removed}[1]{\cbstart\removedfragile{#1}\cbend{}}
\newcommand{\removedfragile}[1]{{\sout{\color{red}{#1}}}{}}
\newcommand{\added}[1]{\cbstart\addedfragile{#1}\cbend{}}
\newcommand{\addedfragile}[1]{{\color{green!50!black}{#1}}{}}
\else
\newcommand{\removed}[1]{} % non-markup version
\newcommand{\added}[1]{#1}
\newcommand{\addedfragile}[1]{#1}
\fi
\newcommand{\changed}[2]{\added{#1}\removed{#2}}

\endinput

Comment ( 1 )

  1. ReplyThijs Van den Brande (@thijsvdb)
    mijn paper is ondertussen online beschikbaar, voor zij die niet zo van regen houden is er ook een stukje LaTeX code: http://t.co/5C9QFkGQja

React!