A lightweight Python utility for applying native Microsoft Word Track Changes and comments to .docx files with minimal OOXML modifications.
This project is designed for revision-heavy workflows such as paper editing, supervisor feedback, collaborative manuscript polishing, and tracked DOCX generation.
- Preserve Word-native review markup instead of plain text diffs
- Apply tracked changes directly to
.docxfiles - Keep changes as small as possible by modifying only the necessary OOXML parts
- Support comments, inline replacements, paragraph operations, and header/footer text replacement
- Work on body paragraphs and table cell paragraphs
- Replace an entire paragraph with tracked deletion + insertion
- Replace inline text with tracked changes
- Replace only the nth inline match
- Delete a paragraph with revision marks
- Insert a new paragraph after an anchor paragraph
- Add Word comments to matching text
- Replace text in headers and footers
- Emit replacement logs for easier verification
- Main body paragraphs
- Table cell paragraphs
- Header/footer paragraphs
scripts/track_changes.py— main CLI toolSKILL.md— detailed usage guide and examples
- Python 3.10+
lxml
Install dependency:
pip install lxmlpython3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace-inline "old phrase" "new phrase"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace "Old paragraph" "New paragraph"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace-inline "better prediction accuracy" "higher prediction accuracy"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace-inline-nth "dynamic response" "vibration response" 2python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--delete "Paragraph to remove"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--insert-after "Anchor paragraph" "Inserted paragraph"python3 scripts/track_changes.py input.docx output.docx \
--author "Reviewer" \
--comment "finite element" "Please add the software version here" \
--comment "dynamic response" "Consider citing a recent reference"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace-hf "Company Name" "New Company" \
--replace-hf "2023" "2024"python3 scripts/track_changes.py input.docx output.docx \
--author "Yachiyo" \
--replace "Old paragraph A" "New paragraph A" \
--replace-inline "old phrase" "new phrase" \
--replace-inline-nth "dynamic response" "vibration response" 2 \
--comment "finite element" "Please add a reference" \
--replace-hf "Old Institution" "New Institution" \
--delete "Old paragraph B" \
--insert-after "Paragraph C" "Inserted paragraph D"The script follows a minimal-intrusion OOXML strategy:
- unpack the
.docx - modify the required XML parts
- write Word-compatible tracked insertions/deletions/comments
- repackage the document
The goal is to preserve the original Word shell as much as possible while still producing native review markup visible in Microsoft Word.
- Academic paper revision with visible track changes
- Supervisor/student collaborative editing
- Reviewer-style comment injection into DOCX manuscripts
- Batch-like manuscript cleanup with controlled tracked edits
- Preparing revision-friendly files for coauthors
--replaceand--deleterequire exact paragraph matches- Inline replacement supports both single-run and cross-run matching, but complex formatting may still be imperfect
- If target text crosses fragile structures such as some field-code boundaries, the script may skip replacement to avoid corrupting the document
- Text boxes, footnotes, and endnotes are not yet supported
- For complex mixed-style runs, formatting is preserved on a best-effort basis, usually using the first relevant run style
This repository intentionally excludes:
- sample
.docxfiles - local test artifacts
- local publishing metadata
- personal document metadata from example files
That keeps the public repository cleaner and safer to share.
- Support text boxes, footnotes, and endnotes
- Better style preservation for complex cross-run replacements
- Native automation for accepting/rejecting revisions
- Cleaner packaging as a reusable Python tool or pip package
For more detailed examples and Chinese usage notes, see:
SKILL.md
MIT