With change tracking on, an edit does not replace text. Both versions stay in the file,
and marks record who did what and when, until the changes are accepted or rejected. So a
document can hold text its reader never sees on screen. Turning tracking on is the
w:trackRevisions setting in word/settings.xml.
Inserted and deleted text
<w:p>
<w:r><w:t xml:space="preserve">The </w:t></w:r>
<w:ins w:id="1" w:author="Ada Example" w:date="2024-05-17T13:45:00Z">
<w:r><w:t>new</w:t></w:r>
</w:ins>
<w:del w:id="2" w:author="Ada Example" w:date="2024-05-17T13:45:00Z">
<w:r><w:delText>old</w:delText></w:r>
</w:del>
<w:r><w:t xml:space="preserve"> text</w:t></w:r>
</w:p>
| Attribute | Meaning |
|---|---|
w:id | A number, unique among the document’s annotations. |
w:author | Who made the change. |
w:date | When, as an ISO 8601 date and time. It may be left out. |
Moved text
A moved passage appears in both places. w:moveFrom marks the old place and
w:moveTo the new. The ends are marked by
w:moveFromRangeStart and w:moveFromRangeEnd, with the same pair
for moveTo, sharing a w:name.
Other tracked changes
| Where | Element | Records |
|---|---|---|
w:pPr/w:rPr | w:ins, w:del | The paragraph mark itself was inserted or deleted, so two paragraphs would join on accepting. |
w:rPr | w:rPrChange | The run’s previous formatting. |
w:pPr | w:pPrChange | The paragraph’s previous formatting. |
w:sectPr | w:sectPrChange | The section’s previous properties. |
w:tblPr, w:trPr, w:tcPr, w:tblGrid | w:tblPrChange, w:trPrChange, w:tcPrChange, w:tblGridChange | Previous table formatting. |
w:trPr | w:ins, w:del | A whole row inserted or deleted. |
w:tcPr | w:cellIns, w:cellDel, w:cellMerge | A cell inserted, deleted or merged. |
A formatting change holds the old properties. The new ones are the element’s siblings: the element records only what they replaced.
Tracked changes in detail
Compared with ECMA-376 Part 1 §17.13.5.1–17.13.5.37, the transitional schema
(CT_TrackChange, CT_RunTrackChange, CT_MoveBookmark
and the …Change types in wml.xsd) and MS-OI29500
§2.1.317–2.1.353.
| Element | Type, children and attributes |
|---|---|
w:ins, w:del, w:moveFrom, w:moveTo in a paragraph | CT_RunTrackChange: run content and math elements, any number, in any order. Attributes w:id and w:author are required, w:date is optional. |
w:ins, w:del, w:moveFrom, w:moveTo in w:pPr/w:rPr | CT_TrackChange, empty, the same three attributes. They mark the paragraph mark. Their order is w:ins, w:del, w:moveFrom, w:moveTo, then the run formatting, then w:rPrChange. |
w:ins, w:del in w:trPr | CT_TrackChange, empty: a whole row. |
w:cellIns, w:cellDel, w:cellMerge in w:tcPr | CT_TrackChange; w:cellMerge also has w:vMerge and w:vMergeOrig (ST_AnnotationVMerge). |
w:moveFromRangeStart, w:moveToRangeStart | CT_MoveBookmark: required w:id, w:name, w:author and w:date; optional w:colFirst, w:colLast and w:displacedByCustomXml. The name joins the source and the destination. The matching w:moveFromRangeEnd and w:moveToRangeEnd carry only w:id (and w:displacedByCustomXml). |
w:pPrChange, w:rPrChange, w:sectPrChange, w:tblPrChange, w:tblPrExChange, w:trPrChange, w:tcPrChange | The three CT_TrackChange attributes, then exactly one child holding the previous properties (w:pPr, w:rPr, w:sectPr (optional here), w:tblPr, w:tblPrEx, w:trPr, w:tcPr). The previous w:pPr has no w:rPr, w:sectPr or w:pPrChange of its own. |
w:tblGridChange | Only w:id; there is no author or date. One w:tblGrid child with the previous columns. |
The custom XML pairs (w:customXmlInsRangeStart, …End, and the same for
Del, MoveFrom and MoveTo) are range markers that carry the
tracked-change attributes and wrap custom XML or a structured document tag.
What a reader must treat as an error or a limit
From the prose of §17.13.5.4–17.13.5.37 (Part 1, read in full for this page):
- Rows and cells.
w:insorw:delinw:trPr(§17.13.5.12, 17.13.5.17) affects only the row itself. It says nothing about the cells or their content, which carry their own revision marks.w:cellInsandw:cellDeltreat the parent cell as inserted or deleted while the revisions were recorded; theirw:idis required, so a file without it is non-conformant. Forw:cellMerge,w:vMergeis the state after the revision andw:vMergeOrigthe state the revision removed (defaultrest). If neither is present the revision can be ignored. - Paragraph marks.
w:delinw:pPr/w:rPr(§17.13.5.15) joins the paragraph to the next one, but does not mark its content as deleted.w:insthere (§17.13.5.20) is described with the same joining words in Part 1; Word reads it as an inserted mark (see below). - Numbering.
w:insinsidew:numPr(§17.13.5.19) says the numbering was added as a tracked change, on each paragraph that received it. - Custom XML ranges. A
customXmlDelRangeStartwithout an end of the same id, an end without a start, a duplicate id, or a pair that encloses no custom XML makes the document non-conformant (§17.13.5.4, 17.13.5.5; the Ins, MoveFrom and MoveTo markers follow the same pattern). - Moves.
w:moveFromandw:moveTo, as run content or as a paragraph mark, must sit inside a move source or destination container whose partner exists (§17.13.5.21, 22, 25, 26). A container start without an end, a duplicate start id, a container without a partner of the other kind, or two containers around the same text are all non-conformant (§17.13.5.24, 27, 28). The sharedw:namepairs the source with the destination. - Property changes.
w:pPrChange,w:rPrChange(paragraph mark),w:sectPrChange,w:tblPrChange,w:tblPrExChange,w:tcPrChangeandw:trPrChangeeach hold the complete set of properties before the revision; the attributes say when they became the former set.w:tblGridChangeholds the former grid.
Divergence from spec
- Author. The prose says that a missing
w:authormeans no author; the schema requires it, and Word follows the schema (MS-OI29500 §2.1.334 b). - Id. Word does not allow
-1as an id (§2.1.317 a). - Nesting. The standard allows
w:ins,w:del,w:moveFromandw:moveToinside one another. Word does not support nested insertions, deletions orw:moveFrom, and does not allow aw:moveToinside another (§2.1.330 a, §2.1.334 a, §2.1.338 a, §2.1.341 a). - Paragraph mark. For
w:insinw:pPr/w:rPrthe standard’s text says the mark is deleted; Word uses it to say that the mark is inserted (§2.1.336 a). - Move of a whole paragraph. Word ignores
w:moveFromandw:moveToinw:pPr/w:rPr(§2.1.337 a, §2.1.342 a). - Moves in maths. Word treats
w:moveFromandw:moveToin math objects as deletions and insertions (§2.1.338 b, §2.1.341 b). In an inserted or deleted math control character Word acceptsw:rPr, not the previous-run form, and does not require thew:rPr(§2.1.329 a, §2.1.332 a, b). - Move ranges. A
w:moveToRangeStartorw:moveToRangeEndinside a move source container is ignored, and Word always writes them in a destination container (§2.1.326 b, c). With severalw:moveToRangeEndof the same id, the first in document order ends the destination (§2.1.343 a). A file with too many move ranges does not open: at most 32,751 when theuiCompat97to2003setting (named so in MS-OI29500; it is not in the Part 1 schema) is set, otherwise 2,147,483,647 (§2.1.340 a). - Overlapping custom XML ranges. The standard allows pairs of
customXml…RangeStartand…Endto overlap; Word does not (§2.1.321 b, §2.1.323 c, §2.1.325 b, §2.1.327 b). Word uses these elements for structured document tags as well as custom XML (§2.1.320 a and the lines that follow it). Word’s results are unpredictable when a move starts inside, ends inside or contains anm:oMathPara(§2.1.325 c, §2.1.327 c). - Section changes. The standard says
w:sectPrChangeholds a complete set of the previous properties; Word reads them relative to the current set (§2.1.348 a). - Row property changes. The standard allows
w:trPrChangein table styles; Word does not (§2.1.353 a). - Revisions in comments. Word does not support any of these elements inside comment text (§2.1.313 b).
- Libraries. python-docx has no classes for revisions: its body iterators skip paragraphs and tables that are nested in a
w:insor another wrapper (pydocx-oxml-table.pylines 486–493,pydocx-oxml-sectpr.pylines 45 and 266), andw:trackRevisionsappears only in the settings child order (pydocx-oxml-settings.pyline 51). LibreOffice readsw:trackRevisionsas its “record changes” option, and handlesw:moveFromandw:moveToas redlines (lo-SettingsTable.cxxlines 309–311, 700;lo-DomainMapper.cxxlines 5458–5465). - docx4j (version 17.3.7,
docx4j-revisions-TrackedChange.javaanddocx4j-revisions-Resolver.java, packageorg.docx4j.model.revisions). The library lists tracked changes the way Word’s Review tab does, not one per element: touching insertions, deletions or formatting changes by one author are one change whatever their dates, and a move is one change from either half (TrackedChange.javalines 49–57). It has twenty-two kinds (lines 69–122, among them three that group mixed insertions, deletions or formatting): run insertion and deletion, move, an inserted or deleted paragraph mark (w:pPr/w:rPr/w:insorw:del, the reading the standard’s text gets wrong, see above), run, paragraph-mark and paragraph property changes, row insertion and deletion (w:trPr/w:insandw:del), an inserted field (Word writesw:insaround the begin and instruction and around the end), an inserted or deleted content control or custom XML element (w:customXmlInsRangeStartandw:customXmlDelRangeStart), an inserted or deleted equation structure (w:insorw:delinm:ctrlPr), the table property records as one change per table (w:tblPrChange,w:tblGridChange,w:trPrChange,w:tcPrChange,w:tblPrExChange),w:sectPrChange, andw:cellInsandw:cellDel, which Word no longer writes but reads. Accepting or rejecting followsResolver.java: an insertion or a move destination is kept when accepted and removed when rejected, a deletion or move source the other way round (lines 134–144); an inserted paragraph mark that is rejected joins the paragraph with the next (lines 146–153); accepting a property change drops thew:*PrChangeelement and rejecting it restores the stored former properties (lines 155–184); an accepted row insertion keeps the row and a rejected one removes it, and a table left without rows is removed (lines 193–207); a rejected inserted field goes whole, separator and result included (lines 211–227); an inserted cell stays when accepted and a deleted one goes (lines 121–130). These whole-object rules for fields and content controls are Word’s behaviour where, in the class comment’s words, its saves differ from a plain per-element reading (lines 71–76); the standard does not state them. - Apache POI (
poi-XWPFParagraph.java119–169,poi-XWPFRun.java1667–1683,poi-XWPFDocument.java1533–1543). There are no revision classes; onlyisTrackRevisionsandsetTrackRevisionson the document, forwarded to the settings part. When a paragraph builds its run list it tests for the XMLBeans typeCTRunTrackChange, which wml.xsd (lines 3403–3406) gives to all four ofw:ins,w:del,w:moveFromandw:moveToin a paragraph; so all four are treated alike: their directw:rchildren become runs of the paragraph, and only nestedw:insare searched again (getInsArray, line 158). A run insidew:delis therefore part of the paragraph text:w:delTextis aCT_Text(wml.xsd line 1748) andXWPFRun._getTextappends everyCTTextexceptw:instrTextandw:delInstrText(line 1674). Author, date, id and the property changes (w:rPrChangeand the others) are not exposed, andw:moveFromtext appears as if it were still present; a plain-text extraction by POI thus returns the text of accepted and rejected content together, where the reading in this page’s “Reading tracked changes” section skips deleted and moved-from text. Aw:insorw:delinside aw:hyperlinkis not reached: that branch reads only thew:rchildren (lines 129–135), while aw:smartTagis searched again as a whole (lines 162–166).
The page viewer takes the text of every w:ins, w:moveTo, w:del and w:moveFrom (w:t or w:delText, at most 120 characters), draws inserted and moved-to text underlined in green and deleted and moved-from text struck through in red, and adds a balloon with the author and the date (pages.js lines 753–762, 808–809, 506–508). The page balloons do not show formatting, row or cell revisions. The text and Revisions views (body.js, word.js) list, with author and date, the revisions of paragraph, run and paragraph-mark properties (w:pPrChange, w:rPrChange, 17.13.5.29-31), of the table, grid, row, cell and table-exception properties (w:tblPrChange, w:tblGridChange, w:trPrChange, w:tcPrChange, w:tblPrExChange, 17.13.5.33-37), of the section properties (w:sectPrChange, 17.13.5.32), inserted and deleted rows and cells (w:ins, w:del in w:trPr; w:cellIns, w:cellDel, w:cellMerge, 17.13.5.1-3) and moved paragraph marks; each formatting change names the properties the former set held (the child element, which per the spec holds the complete set before the revision) but the viewer never applies or reverts a change. The move range marks (w:moveFromRangeStart and the others, 17.13.5.23-28) and the custom XML range marks (17.13.5.4-11) are not listed.
Reading tracked changes
To get the text as if all changes were accepted, read the content of w:ins
and w:moveTo, and skip w:del and w:moveFrom. To get it
as if they were rejected, do the reverse. The explorer shows inserted text as plain text,
deleted text struck through, and lists every change with its author and date.