As a scholar who often submits manuscripts to journals or conferences, it is not uncommon when the editor requests to submit a pdf which highlights the difference from the previous version to current one. This usually happens when a minor revision is requested.
If using Microsoft Word, the highlighted version is easy to produce as MS Word comes with a diff
option. However, in circumstances where LaTeX is used, producing a diff
version is not as straightforward as with MS Word.
LaTeX has its unique philosophy and elegance, as previously introduced in interaction between Visio and LaTeX. To highlight changes between an old version and a new version of a LaTeX document, we can use the latexdiff
tool, which is specifically designed for this purpose. latexdiff
is a Perl script, so having Perl installed is an essential prerequisite. Most Unix-like systems, including Linux and macOS, come with Perl pre-installed. To check if Perl is properly installed, simply
1perl -v
Do not worry if Perl is not installed; you can easily download the binary or source code from Perl’s website. On Ubuntu or Debian, you can install latexdiff
via apt.
1sudo apt install latexdiff
For Oracle Linux or RHEL, you can check the RPM package at rpm find.
Then, we can prepare our LaTeX documents. It is advisable to ensure we have both the old and the new versions of the LaTeX document. Let’s assume they are named old.tex
and new.tex
. If the project is simple and contains only one source file, then the following command should work fine to highlight the differences:
1latexdiff old.tex new.tex > diff.tex
However, when submitting a manuscript to a journal, chances are that other source files, including figures and bibliographies, are also requested. At this point, we need to specify several parameters to make latexdiff
work effectively. For example, if we want to highlight the differences in the references section as well, we first need to apply latexdiff
to both bbl
files.
1latexdiff old.bbl new.bbl > diff.bbl
If you are working with Overleaf, the bbl
file can be accessed through Logs and Output Files > Other Logs and Files. Furthermore, to present the differences between various versions, particularly regarding minipages
and figures, the following command can serve as a good template:
1latexdiff -t CFONT -c "PICTUREENV=(?:picture|minipage|DIFnomarkup)[\w\d*@]*" --graphics-markup=2 old.tex new.tex > diff.tex
Below is a detailed description of these parameters.
-t CFONT
specifies the type of markup used for highlighting differences. The CFONT style uses a combination of color and font changes to indicate differences. It is one of several predefined styles in latexdiff that can be used to visually distinguish between old and new text. This style is particularly useful for making changes stand out clearly.
-c "PICTUREENV=(?:picture|minipage|DIFnomarkup)[\w\d*@]*"
is a configuration command that defines how latexdiff handles certain environments. The setting PICTUREENV customizes the treatment of environments typically containing graphics or formatted text. The regular expression (?:picture|minipage|DIFnomarkup)[\w\d*@]* tells latexdiff to apply specific rules or ignore differences within the picture, minipage, and any environment names matching DIFnomarkup followed by any combination of alphanumeric characters, asterisks, or at symbols. This can help prevent the markup from interfering with complex environments where differences might not be meaningful or could disrupt the layout.
--graphics-markup=2
controls how changes in graphic files are marked. A setting of 2 means that graphical files which differ between the old and new versions will be included side by side in the output document. This is useful for visually comparing changes in included graphics.
To further customize the options, it is advisable to checkout the official documentation for more information.
Keep an eye on the Latex section of this blog for more interesting latex techniques!
Comments