LinuxCommandLibrary

latexdiff

Compare and highlight differences between LaTeX files

TLDR

Determine changes between different versions of a LaTeX file (the resulting LaTeX file can be compiled to show differences underlined)

$ latexdiff [old.tex] [new.tex] > [diff.tex]
copy

Determine changes between different versions of a LaTeX file by highlighting differences in boldface
$ latexdiff --type=BOLD [old.tex] [new.tex] > [diff.tex]
copy

Determine changes between different versions of a LaTeX file, and display minor changes in equations with both added and deleted graphics
$ latexdiff --math-markup=fine --graphics-markup=both [old.tex] [new.tex] > [diff.tex]
copy

SYNOPSIS

latexdiff [OPTIONS] <old.tex> <new.tex> [> <diff.tex>]

Compares <old.tex> with <new.tex> and outputs the marked-up differences to standard output or a specified file.

PARAMETERS

-h, --help
    Displays a help message and exits.

--style=<style>
    Specifies the markup style. Common styles include CFONT (color and font changes, default), CTRADITIONAL (strikethrough and underline), and CSCRIPT (uses margin notes).

--type=<type>
    Sets the document type, e.g., ARTICLE, REPORT, BOOK. This affects how certain commands or environments are handled.

--flatten
    Recursively includes and expands all included LaTeX files (e.g., via \input or \include) from the original documents before diffing.

--config=<key>=<value>
    Overrides a configuration variable. For example, --config="COLOR{added}=blue" changes the color for added text.

--ignore-comments
    Instructs latexdiff to ignore any changes that occur solely within LaTeX comments.

--ignore-changes=<category>
    Ignores certain categories of changes, such as Preamble, Whitespace, Comments, Floats. Can be specified multiple times.

--exclude-text-markup=<regexp>
    Prevents text markup for content matching a regular expression (e.g., for specific environments or commands like \label).

--math-markup=<method>
    Defines how mathematical content is marked up. Options include COMMENTS, COLOR, NONE, or STRIKE.

--graphics-markup=<method>
    Controls how graphic files (e.g., included via \includegraphics) are handled. Options include INLINE, FIGURES, COMMENTS, NONE.

DESCRIPTION

latexdiff is a powerful Perl script designed to compare two LaTeX documents and produce a new LaTeX file where the differences are visually marked. This tool is invaluable for collaborative writing, tracking revisions, or managing document versions. It intelligently parses LaTeX syntax, identifying changes in text, commands, and environments, and then applies configurable markup styles. The output .tex file typically uses color, strikethrough, or underlining to highlight additions and deletions. latexdiff handles complex document structures, including included files, equations, and figures, making it an indispensable utility for anyone working with LaTeX documents.

CAVEATS

While powerful, latexdiff might be slow for extremely large documents or those with very complex macro definitions. It relies on perl and a standard diff utility (like diff) being available on the system. The output is a new LaTeX file, which must be compiled (e.g., using pdflatex) to render the visual differences in a PDF or DVI viewer.

COMPILATION OF OUTPUT

The result of running latexdiff is a new LaTeX file (e.g., diff.tex). This file contains specific LaTeX packages and commands (e.g., soul, xcolor, changes) to apply the visual markup. To see the highlighted differences, this output file must be compiled using a LaTeX compiler (e.g., pdflatex diff.tex) to generate a viewable PDF document.

MARKUP STYLES OVERVIEW

latexdiff offers several markup styles to suit different preferences. The CFONT style (the default) uses color and font changes (e.g., italic for added text, strike-through for deleted text). The CTRADITIONAL style mimics traditional proofreading marks, using strikethrough for deleted text and underlining for added text. Other styles like CSCRIPT can insert margin notes for changes, providing a flexible way to visualize document revisions.

HISTORY

latexdiff was originally developed by J. R. Ryder and first released in 2004. It quickly gained traction as a crucial tool for LaTeX users due to its robust handling of LaTeX syntax compared to generic text diff tools. The project has seen continuous development and maintenance, evolving into the de-facto standard for comparing and highlighting changes in LaTeX documents.

SEE ALSO

diff(1), latexdiff-vc(1), latexrevise(1)

Copied to clipboard