WordIndexer is an open-source Python tool that inserts native Microsoft Word XE (Index Entry) fields into .docx manuscripts. It helps authors, researchers, educators, publishers, and technical writers create professional indexes from configurable JSON dictionaries.
Version: 0.5.0 — Hierarchical Entries and Cross-References
The current release has been tested against:
- A sample Word document.
- A torture-test document containing complex formatting and document structures.
- A real PowerShell manuscript.
- Reads Microsoft Word
.docxdocuments. - Loads JSON dictionaries with terms, aliases, and canonical index names.
- Finds every occurrence of enabled terms.
- Indexes aliases under one canonical term using
index_as. - Supports parent entries, subentries,
See, andSee alsoreferences. - Resolves overlapping matches by preferring the most specific match.
- Preserves visible text and run formatting.
- Inserts Word-compatible XE fields.
- Appends a real Word
INDEXfield automatically. - Adds an
Indexheading before the generated index field. - Excludes front matter using an explicit TOC boundary or first-chapter fallback.
- Optionally searches table-cell paragraphs with
--include-tables. - Produces dry-run coverage reports and JSON reports.
- Saves a new indexed document without modifying the source document.
- Provides a command-line interface.
Version 0.5.0 searches normal body paragraphs and headings. Table-cell indexing is available with --include-tables. It does not yet index text inside:
- Headers and footers.
- Footnotes and endnotes.
- Text boxes and other embedded Word stories.
The current scope is intentionally limited so that the core engine remains predictable and testable.
WordIndexer requires Python 3.12 or newer.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txtUse python -m pytest, rather than a possibly unrelated global pytest, so tests run with the active virtual environment.
python book_indexer.py inspect input/sample.docxpython book_indexer.py analyze input/sample.docx dictionaries/technology/powershell.jsonpython book_indexer.py index input/sample.docx dictionaries/technology/powershell.json output/sample_indexed.docxThe command automatically adds XE fields, an Index heading, and a Word INDEX field. Open the output in Word and press Ctrl+A, then F9.
Use --include-tables to include table-cell paragraphs:
python book_indexer.py index input/sample.docx dictionaries/technology/powershell.json output/sample_with_tables.docx --include-tablesUse --no-index-field when only XE fields are required.
{
"metadata": {
"name": "PowerShell Dictionary",
"version": "1.0",
"author": "WordIndexer"
},
"entries": [
{
"term": "Get-ChildItem",
"aliases": ["gci", "dir", "ls"],
"index_as": "Get-ChildItem",
"parent": "PowerShell",
"subentry": "Cmdlets",
"category": "Cmdlet",
"enabled": true
},
{
"term": "pwsh",
"index_as": "pwsh",
"see": "PowerShell",
"enabled": true
},
{
"term": "PowerShell",
"index_as": "PowerShell",
"see_also": ["Windows PowerShell", "PowerShell Core"],
"enabled": true
}
]
}A parent and subentry create a hierarchy such as PowerShell:Cmdlets:Get-ChildItem. A see entry redirects readers to a preferred entry. A see_also entry adds a related-topic reference while preserving the entry's normal page references.
python -m pytest -qThe project follows a staged workflow: write a focused test, implement one capability, run the full suite, validate a generated DOCX in Word, and commit only after the result is confirmed.
WordIndexer is released under the MIT License. See LICENSE.