Compare LaTeX Documents for Text Changes

How to compare two LaTeX documents: source diffs, word-level diffs, marked-up PDFs and rendered-text checks, plus how moved passages and markup noise appear.

Comparing two versions of a LaTeX document sounds simple, but what you see depends on whether you compare the source files or the typeset output. Each approach shows a different kind of change, handles rewrapped lines and moved passages differently, and produces output with different limits. This guide explains what a comparison actually reports, how the main approaches differ, and how to check that the result is usable for your purpose.

What a LaTeX comparison actually shows

A comparison does not transform your text. It does not reverse characters, mirror them, or substitute lookalike Unicode characters. It reads two inputs and reports where their stored characters differ. The question that matters is which characters are being compared.

In a .tex file, the stored characters include prose, commands, environments, comments and line breaks. A source comparison reports all of them. A change to a macro definition appears as one small edit even if it alters every page of the output, while a paragraph rewrapped to a new line width can look like a full rewrite even though no words changed.

In the typeset output, such as a PDF, the characters are what LaTeX produced after expanding macros, resolving references and applying hyphenation. Comparing text extracted from the output shows changes a reader would see, but it hides the source edits that caused them and can introduce artifacts from the extraction process.

Moved passages are a frequent source of confusion. Many comparison methods find a common subsequence of lines or words and report everything else as deleted or inserted. Under that model, a paragraph moved from one section to another usually appears as a deletion in one place and an insertion in another, not as a move. Some tools attempt to detect moves; check the documentation of any tool you use before relying on that.

Choosing a comparison approach

The approaches below are compared on the same criteria: what is compared, how changes appear, how moved text is shown, and whether the output can be edited or compiled. Features of specific tools change between versions, so confirm the details against current documentation.

Approach | What is compared | How changes appear | Moved passages | Output and editability
Line-based source diff | Lines of the .tex files | Whole changed lines marked as removed or added | Typically shown as a deletion plus an insertion | Plain text; easy to read in a terminal or code review, but rewrapped paragraphs create large, noisy changes
Word-level source diff | Words or tokens in the .tex files | Changed words highlighted within lines | Typically shown as a deletion plus an insertion | Plain text; less sensitive to rewrapping, still shows markup changes alongside prose
Markup-annotated diff | Source tokens, rewritten into a new .tex file with change markers | Additions and deletions styled in the compiled document | Usually shown as separate deletion and insertion | A new .tex file that must compile; suited to reviewers who read the PDF rather than source
Rendered-text comparison | Text extracted from two compiled outputs | Differences in what a reader sees | Depends on the comparison tool | Reflects final wording, but loses source context and can include extraction artifacts

Use a line-based or word-level source diff when you or your collaborators edit the source directly and want to see exactly what was typed. Use a markup-annotated diff when a co-author, editor or reviewer needs a readable marked-up PDF. Use a rendered-text comparison when the question is whether the final wording changed, regardless of how the source was restructured.

Common command-line starting points are shown below. They are illustrative invocations, not tested output from your files. The first is a standard unified line diff, the second uses Git's word-diff mode on two files outside a repository, and the third uses latexdiff, a markup-annotated diff tool distributed with common TeX installations. Options vary by version, so check each tool's help text.

diff -u old.tex new.tex

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

latexdiff old.tex new.tex > changes.tex

Illustrative example: a moved sentence

The matched input below shows how a line-based comparison typically reports a sentence moved from the end of a paragraph to the start. This is an illustrative example of the common-subsequence model, not observed output from a particular tool.

old.tex:
We measured the response under three loads.
Results are summarized in Table 2.
All tests used the same fixture.

new.tex:
All tests used the same fixture.
We measured the response under three loads.
Results are summarized in Table 2.

Typical line diff:
+All tests used the same fixture.
 We measured the response under three loads.
 Results are summarized in Table 2.
-All tests used the same fixture.

Nothing in the sentence changed, yet it appears twice: once added and once removed. When reviewing, look for identical text on both sides of the diff before treating it as a rewrite.

Reducing noise before you compare

  • Keep one sentence per line in the source. Rewrapping then affects only the sentence that changed, and moved sentences are easier to spot.
  • Compare the full document, not just the main file. If the project uses \input or \include, either compare each included file or merge them into one file first; some tools offer an option to do this automatically.
  • Decide whether comments matter. Comment-only edits show up in source diffs but not in the output.
  • Compare macro and preamble changes separately. A one-line change there can alter the output throughout the document.
  • Use the same compiler, packages and bibliography data for both versions when comparing rendered output, so differences reflect content rather than environment.

Will the comparison output be usable where you need it?

Plain-text diffs from source comparisons are ordinary text. They copy and paste cleanly into email, issue trackers and code review tools, and screen readers can read them, although the plus and minus markers need to be understood as change indicators. They are the most portable option.

A markup-annotated .tex file has to compile. Documents with complex tables, custom environments, heavy math or unusual packages can fail to compile once change markers are inserted, or can compile with markers in unexpected places. If that happens, tool options that restrict marking to prose, or a source diff, are alternatives. Check the compiled result before sending it to anyone.

Marked-up PDFs often distinguish additions and deletions by color. Color alone is not reliable for readers with color vision deficiencies or for grayscale printing, so prefer styles that also use underlining, strikeout or another non-color cue. Text copied out of such a PDF usually loses the markup, and deleted text may be copied along with inserted text, so do not treat copied passages as the new wording without checking.

Text extracted from compiled PDFs has its own limits. Hyphenated words may split, ligatures may extract as single characters, multi-column layouts and floats may come out in a different order, and math rarely extracts as meaningful text. Documents containing right-to-left scripts add another layer: the order of characters in the stored text can differ from the visual order on the page, and extraction may follow either. Treat apparent differences from extracted text as leads to verify against the source.

If you consider an online comparison service, remember that uploading files sends their content to someone else's system. Unpublished manuscripts, grant proposals and confidential reports deserve caution. Review the service's stated retention and privacy terms, or use a local tool that runs on your own machine.

Gaps to keep in mind

This guide describes general behavior of comparison methods rather than tested results from particular tools or versions. No specific measurements, compatibility tests or feature lists were available for it. Before relying on move detection, multi-file handling, compile success with your packages, or a service's data handling, confirm the behavior in that tool's current documentation or by running it on a copy of your own documents.