Home

Photo of Jan Pöschko

I am a student of Mathematical Computer Science, programmer, photographer, traveller, geek.

My mother tongues are German and Python, but I also speak and write C++, JavaScript, Ruby, Mathematica, and many others, including some English and Swedish. Learn more about my projects and me on this site.

Recent Posts

Highlighting changes in LaTeX

I want to shortly point out how convenient it is in LaTeX to highlight changes you made to a document, let’s say for a journal resubmission. That is, you want to show your readers which parts you have added or deleted. In my opinion, coloring additions green, deletions red, and additionally marking edits with bars in the page margin is a good way of doing that.

That can be achieved pretty easily with two packages in LaTeX: xcolor and changebar.

\usepackage{xcolor}
\usepackage{changebar}

Using these, we can define the following commands to mark up additions and deletions:

\newcommand{\removed}[1]{\cbstart\removedfragile{#1}\cbend{}}
\newcommand{\removedfragile}[1]{{\color{red}{#1}}{}}
\newcommand{\added}[1]{\cbstart\addedfragile{#1}\cbend{}}
\newcommand{\addedfragile}[1]{{\color{green!50!black}{#1}}{}}
\newcommand{\changed}[2]{\added{#1}\removed{#2}}

At least from my experience, change bars don’t work in “fragile” environments such as float captions, that’s why there are versions of the commands that only color the edit. With this, we could already do

This \changed{new replacement}{text} is replaced.

to produce the above image. However, what if we want to see the final version only, without the change markup? Let’s define a new if

\newif\ifdiff
\difffalse

and then conditionally define our markup functions:

\ifdiff
  % the above definitions of removed* and added*
\else
  \newcommand{\removed}[1]{} % non-markup version
  \newcommand{\removedfragile}[1]{}
  \newcommand{\added}[1]{#1}
  \newcommand{\addedfragile}[1]{#1}
\fi

Now we can select whether we want to display the edits by setting diff to true or false. You and your reviewers will like it.

You can download the full source code of a sample page, the corresponding output with differences shown and without markup.

  1. Homepage updated Leave a reply
  2. The last month Leave a reply
  3. Campus impressions Leave a reply
  4. L.A. and San Diego Leave a reply
  5. Extreme Geeky Tidying Up: Sorting image colors with Python and Hilbert curves 2 Replies
  6. To the North 1 Reply
  7. To the South Leave a reply
  8. Rock and Roll Leave a reply
  9. Death and reincarnation of some bitten fruit 1 Reply