Compare Text and Document Versions for Differences and Moved Passages

How text diffs work, why moved passages often appear as a deletion plus an insertion, and how to choose a comparison method you can trust.

Comparing two versions of a document seems simple: show what changed. In practice, a comparison tool has to decide what counts as one unit of text, which differences matter, and whether a block that moved is a move or a deletion followed by an insertion. Those decisions determine whether the result is useful for proofreading, contract review, code review or editorial sign-off. This guide explains what a diff actually reports, how the main comparison approaches differ, and what to check before you rely on the output.

What a Text Diff Actually Changes and Reports

A diff does not change either document. It reads an original and a revised version and produces a third artifact: a description of the edits that would turn one into the other. That description is usually an edit script made of kept, deleted and inserted units. Depending on the method, a unit is a line, a word or a single character.

Most diffs compare stored characters, not appearance. This distinction matters whenever text has been transformed. If a passage was visually mirrored or flipped with display styling such as CSS, the stored characters are unchanged, so a character-based diff reports no difference even though the page looks different. If the character order was actually reversed, every affected character is in a new position, and the diff reports a large change. If letters were swapped for look-alike Unicode symbols, such as styled bold or script letters used by font generators, those are different code points, so the diff flags them as changed even when the text looks nearly identical.

Several invisible differences behave the same way. A non-breaking space and a regular space look alike but are different characters. An accented letter can be stored as a single precomposed character or as a base letter plus a combining accent; unless the tool normalizes text before comparing, those versions may register as different. Zero-width characters and bidirectional control characters, which affect how right-to-left and left-to-right text is displayed, can also produce differences that are not visible on screen. When a diff highlights a line that looks unchanged, hidden characters like these are a likely cause.

Why Moved Passages Are Hard to Detect

Classic line-based diff algorithms look for the longest sequence of lines the two versions share in the same order, then report everything else as deleted or inserted. A paragraph that moved from the top of a document to the bottom breaks that shared order, so it is typically reported twice: once as removed from its old position and once as added in its new one. Nothing in the basic output tells you the two are the same text.

Move detection is an additional step. A move-aware comparison looks for deleted and inserted blocks that match, or nearly match, and labels them as a moved passage. Even then, moves can be ambiguous: if two adjacent paragraphs swap places, either one can be described as the one that moved. Different tools may resolve that ambiguity differently, and a passage that was both moved and edited may fall below a tool's similarity threshold and revert to a plain deletion and insertion.

An illustrative example

The following example uses one matched pair of inputs. The outputs are illustrative of how each method typically presents results; they were not produced by a specific tested tool.

Original version:
Introduction
Scope of the policy
Data retention rules
Contact the team

Revised version:
Introduction
Data retention rules
Scope of the policy
Contact the review team

A line-based diff in unified style might report the result like this, with a minus sign for removed lines, a plus sign for added lines and a leading space for unchanged lines:

 Introduction
-Scope of the policy
 Data retention rules
-Contact the team
+Scope of the policy
+Contact the review team

Read literally, that output says two lines were deleted and two were added. A reviewer has to notice that "Scope of the policy" appears on both sides and that the last line gained a single word. A word-level comparison of the final line would narrow the change to one insertion:

Contact the [+review+] team

A move-aware comparison of the same input would ideally report two edits: "Scope of the policy" moved below "Data retention rules", and "review" was inserted into the final line. Note the ambiguity described above: a tool could equally report that "Data retention rules" moved up instead.

Which Comparison Approach Suits Your Task

The right method depends on what kind of text you are comparing and what a reviewer needs to confirm. The table below compares the common approaches on the same criteria.

Approach | What it compares | Strength | Tradeoff | Best suited to
Line-based diff | Whole lines as units | Compact, predictable output; standard format that other tools can read | A one-word edit marks the entire line changed; moved blocks appear as deletion plus insertion; re-wrapped paragraphs look heavily changed | Source code, configuration files, data with one record per line
Word-level diff | Words and the spaces between them | Pinpoints small wording edits in prose | Can become cluttered when sentences are rewritten; punctuation and spacing handling varies by tool | Articles, policies, contracts and other edited prose
Character-level diff | Individual characters | Catches typos, swapped letters, invisible or look-alike characters | Very noisy for substantial rewrites | Proofreading, identifiers, checking for hidden or substituted characters
Move-aware comparison | Matched blocks across positions, plus edits within them | Shows reorganized passages as moves instead of separate deletions and insertions | Moves can be ambiguous; moved-and-edited passages may not be recognized; behavior differs between tools | Restructured reports, reordered sections, long documents after editorial reorganization
Formatted document comparison | Text plus formatting and structure in rich documents | Can surface changes to styles, tables and layout that plain-text diffs miss | Results depend on the file format and the application; output is often tied to that application | Word-processor files where formatting changes matter

For most prose revisions, a word-level comparison with move detection gives the clearest picture. For code and structured data, a line-based diff remains the practical default because its format is widely understood. When you suspect copied text contains substituted or hidden characters, a character-level pass is the most reliable way to find them.

Comparing documents rather than plain text

When you compare word-processor files or PDFs, the comparison usually works on text extracted from the file, and extraction is where many false differences start. PDF extraction can reorder columns, split words at line-end hyphens and insert line breaks where the layout wrapped. Re-flowing a paragraph changes every line break, which makes a line-based diff report the whole paragraph as changed. Plain-text comparison also ignores formatting, so a change from regular to bold text, or a modified heading style, will not appear at all.

  • Compare files in the same format where possible, such as two exported plain-text files or two versions in the same word-processor format.
  • If you must compare extracted text, choose an option that ignores whitespace or line-break differences when the tool provides one, and confirm that setting is actually applied.
  • Use a formatted comparison when styling, tables or layout carry meaning, such as in contracts with defined terms in bold.
  • Spot-check a few reported changes against the source documents before treating the full result as accurate.

Will the Comparison Output Remain Readable and Usable

A comparison result is only useful if it survives the place you send it. Highlighting shown in a browser or application is presentation, not text. When you copy a highlighted diff and paste it into an email, chat or plain-text document, the colors and strike-through styling are commonly lost, and deleted and inserted words can end up merged into one unreadable line. If the result needs to travel, prefer an output that encodes changes in the text itself, such as plus and minus line markers or explicit bracketed insertions and deletions, and check the destination after pasting.

Accessibility depends on how changes are signaled. Red and green highlighting alone is difficult for readers with some forms of color vision deficiency, and visual styling is not necessarily conveyed by assistive technology such as screen readers. Output that also uses symbols, labels or text markers for additions, deletions and moves is more dependable for these readers. Whether a particular tool's highlighting is announced by a given screen reader cannot be assumed; it needs to be tested with that combination.

Unicode handling affects both directions of a comparison. Text containing styled look-alike characters, reversed character order or bidirectional control characters may display differently across applications, and those characters may be preserved, stripped or altered during copy and paste. If a comparison will be used to verify that two documents match, convert both to plain text from the same source and, where the tool supports it, normalize them the same way before comparing.

Sensitive documents and online comparison services

Pasting text into an online comparison service sends it to that service's servers. For contracts, personal data, unreleased material or anything under a confidentiality obligation, read the service's stated retention and processing policy before uploading, and consider a comparison tool that runs locally on your own device instead. Removing names, account numbers and other identifying details before comparing reduces exposure when an online service is the only option.

Gaps to Check Before Relying on a Tool

No tested results for specific comparison tools were available for this guide, so it does not state which applications or websites offer move detection, word-level comparison, whitespace options or Unicode normalization. Those features vary by tool and version. Before adopting one, run a small test like the example above: include a moved paragraph, a one-word edit, a re-wrapped line and a non-breaking space, then confirm that the output reports each change the way you expect.