Compare Revisions of LaTeX Documents

How to compare two LaTeX documents: source diffs, word-level diffs and compiled change-marked PDFs, what each changes, which suits your revision, and how to keep the output usable.

When a LaTeX manuscript goes through several rounds of edits, you usually need to see what changed between two versions. You might be checking a co-author's revisions, answering reviewers, or confirming that a rewrite did not alter a result. Several methods exist, and they show you different things. This guide explains what each one does to your text, how to choose between them for paragraph-level revisions, and what to check before you rely on or share the output.

What comparing LaTeX documents actually changes

Comparing two .tex files does not modify either file. The methods differ in what they produce and where the differences become visible.

  • Source-level diff: the two .tex files are compared as plain text, and you get a report of inserted and deleted lines. You see raw LaTeX, including commands, comments and math, exactly as stored.
  • Word-level source diff: this is the same comparison, but changes are reported per word instead of per line. It is easier to read when only a few words in a long paragraph changed.
  • Change-marked compiled document: a tool generates a new third .tex file in which deletions and additions are wrapped in markup commands. You compile that file to get a PDF where changes appear as styled text. The stored characters in this third file differ from both originals because it contains the inserted markup.
  • Visual comparison of compiled PDFs: the rendered outputs are compared, not the source. This shows how the reader-facing document changed, but it gives no direct link back to the LaTeX that caused each change.

Separate how a difference is displayed from what is stored. Colored highlighting in a terminal or editor is presentation only. The underlying text is unchanged, and the color may disappear, or turn into stray escape codes, when the output is copied or saved. Text markers such as brackets around deleted words, or LaTeX commands in a generated diff file, are real characters. They survive copying and stay in the file until you remove them.

Which approach suits your revision

The table compares the four approaches on the same criteria. It is a general guide, not the result of a benchmark.

Approach | What you see | What is stored or produced | Editable afterward? | Best for
Line-based source diff | Whole changed lines in raw LaTeX | A text report; originals untouched | Report is plain text; edit the originals, not the report | Code-like content, preamble and macro changes, version-control review
Word-level source diff | Changed words within lines, in raw LaTeX | A text report with change markers or display-only color | Same as above | Prose edits inside long paragraphs
Change-marked compiled PDF | Formatted document with additions and deletions styled | A generated .tex file with inserted markup, plus its PDF | The generated .tex is a review artifact, not a working copy | Co-authors, editors and reviewers who read PDFs, not source
Visual PDF comparison | Differences in the rendered pages | A comparison view or report of the PDFs | No; it does not map back to source | Checking layout, figure placement and final-output regressions

Source diffs: precise, but you read raw LaTeX

A standard line-based diff, such as the one built into most version-control systems, shows every change, including edits to comments, labels and macros that never appear in the PDF. That precision matters when you need to audit exactly what was edited. The downside for prose is that LaTeX users often keep a whole paragraph on a single line. One changed word then marks the entire paragraph as replaced, and you have to find the edit yourself.

Word-level comparison handles this. Git, for example, documents a word-diff mode that also works on two files outside a repository. The plain variant marks deletions and insertions with bracket markers instead of relying on color alone:

git diff --no-index --word-diff=plain old.tex new.tex

Illustrative example, not output captured from a test run. Given an old line and a revised line:

Old: The method converges in most cases \cite{smith}.
New: The method converges quickly in all tested cases \cite{smith,lee}.

Word-diff style output:
The method converges {+quickly+} in [-most-]{+all tested+} cases [-\cite{smith}.-]{+\cite{smith,lee}.+}

In this example the citation is reported as one changed token. Words are split on whitespace by default, so a LaTeX command and its argument count as a single word. That is usually fine, but small edits inside commands or math can show up as larger replacements than they really are.

Change-marked PDFs: readable for reviewers, but a generated artifact

latexdiff, a tool distributed with common TeX distributions, takes two .tex files and writes a third file with additions and deletions marked by inserted LaTeX commands. You compile that file like any other document. Its documentation describes options to choose the markup style, to merge files pulled in with \input or \include before comparing (--flatten), and to control how changes inside math are shown. A companion script, latexdiff-vc, compares revisions stored in version control. The exact options vary by version, so check the manual installed on your system.

latexdiff old.tex new.tex > diff.tex
pdflatex diff.tex

Illustrative example of the kind of markup inserted into the generated file, using the same sentence as above. The exact command names and spacing depend on the version and options:

The method converges \DIFaddbegin \DIFadd{quickly }\DIFaddend in \DIFdelbegin \DIFdel{most }\DIFdelend \DIFaddbegin \DIFadd{all tested }\DIFaddend cases

This approach suits reviewers who will never open the source. Its tradeoff follows from the fact that it inserts characters: the generated file is neither the old nor the new version. Do not edit it and treat it as your manuscript, because removing the markup by hand is error-prone. Make your changes in the new source and regenerate the diff.

Visual PDF comparison: checks the output, not the edit

Comparing two compiled PDFs answers a different question: did the published result change? It can reveal shifted figures, changed numbering or altered bibliography formatting caused by a package update rather than a text edit. It cannot tell you which source line caused a difference. Reflowed text can also make a one-word change appear across many lines. Use it as a final check alongside a source or change-marked diff, not as a replacement for one.

Choosing by situation

  • You are reviewing your own or a collaborator's edits in source: use a word-level source diff.
  • You need to audit every change, including comments, macros and preamble: use a line-based source diff.
  • You are sending tracked changes to a journal, editor or co-author who reads PDFs: use a change-marked compiled PDF.
  • You want to confirm the final layout did not shift unexpectedly: add a visual PDF comparison.

Getting cleaner diffs for paragraph revisions

How you write the source affects every comparison method, because LaTeX ignores single line breaks within a paragraph. Putting each sentence, or each clause, on its own line makes line-based diffs show edits at sentence level and reduces noise in every other method. The most common cause of an unreadable diff is reflowing: an editor that rewraps a paragraph to a fixed width changes the line breaks throughout it, so a one-word edit appears as a rewrite of the whole paragraph. Turn off automatic hard wrapping, or keep pure formatting changes in a separate revision from content changes so each diff shows one kind of change.

Will the comparison output remain readable and usable?

Copying and sharing

Color highlighting in a terminal is display formatting. When you paste it into an email or document, the color is usually lost, which leaves additions and deletions indistinguishable. If the output was redirected to a file with color forced on, it may contain escape-code characters instead. To share a source diff as text, use a mode with textual markers, such as the plain word-diff markers shown above, or a unified diff file. To share a change-marked document, send the compiled PDF and keep the generated .tex file as a reproducible artifact.

Compilation and compatibility

A generated change-marked file has to compile, and inserted markup can conflict with complex constructs such as heavily customized macros, some table and math environments, or packages that redefine text commands. If compilation fails or a change looks wrong, try the tool's options for math and for excluding specific commands or environments, flatten multi-file projects before comparing, and compare against a plain source diff to confirm what really changed. Always keep the original files. The comparison is only a view of them.

Accessibility

Markup that relies on color alone excludes readers who cannot tell the colors apart. Prefer styles that pair color with a second cue, such as underlining for additions and strike-through for deletions, or textual markers in source diffs. Check how your chosen style actually renders rather than assuming. This guide has not tested how screen readers present strike-through or underline in change-marked PDFs. If a reader uses assistive technology, a text-based diff with explicit markers is the safer choice until you have confirmed that their tools announce the styling.

Sensitive manuscripts and online tools

Browser-based diff services require uploading or pasting your text to an external server. For unpublished research, confidential reviews or anything under embargo, compare locally with tools installed on your own machine. If you do use an online service, read its data-handling terms first, and assume anything you submit may be retained.

Limits of this guide

The command examples and outputs above are illustrative and were not captured from a test run. Exact markup, option names and behavior depend on the tool versions installed. No measurements of speed, accuracy or rendering across viewers were available for this guide. Before you rely on a method for submission or review, run it on a short sample of your own document and check the result in the destination where it will be read.