zotdocx
English | 中文
zotdocx repairs Zotero citation fields inside a .docx. It edits the file only: it does not touch the Zotero library, and it does not re-typeset the document.
It is built for numeric citation styles, where a citation is a number that has to stay in step with the tables, figures and notes around it — GB/T 7714, IEEE, Nature, Vancouver. Author–date styles such as APA or Harvard have no number to reorder, so renumber and lift do not apply to them.
Quick start
pip install zotdocx
zotdocx demo
demo writes demo.docx into the current directory — a synthetic document with two citation fields and a few known defects — then prints a read-only report and a dry run of renumber:
demo.docx
部件 7 个;document.xml 0.00 MB
样式 未记录
域 3 = 引注 2 + 书目 1 + 其他 0
跨段落:引注 0 · 书目 0
位置:正文 2
条目 2 个
编号 显示 1–2;同条目多编号 0;单条目编号不符 2;多条目编号不符 0
纯文本 正文 1 · 表格 1 · 表注图注 1 · 图题表题 1
Then point it at your own file:
zotdocx status 论文.docx # read-only report; exit code 1 if something is off
zotdocx renumber 论文.docx # dry run, prints what would change
zotdocx renumber 论文.docx --apply
Console labels are Chinese in this release. Numbers, exit codes and --json output are the parts meant for scripts.
What it fixes
- Citation fields split across paragraphs, with the field end in the next paragraph
- Numbers stored in a field that disagree with the numbers shown on the page
- Numbering that does not follow the order of first citation
- Plain-text citations in the body (
[3],[12,13]) that are not live fields - Citation fields pointing to items removed from the library (broken links)
- Zotero's "Cannot delete range" error when refreshing
Commands
| Command | What it does |
|---|---|
demo |
Write a synthetic sample document and check it |
status |
Report field structure, item count, numbering consistency, plain-text citations |
heal |
Repair cross-paragraph citation fields; align stored and displayed numbers |
renumber |
Renumber by first citation and sync plain-text numbers in tables, captions and notes |
lift |
Turn plain-text citations in the body into live fields |
repair |
Relink broken citations by item key or title |
patch |
Inspect or reapply the Zotero omni.ja patch |
Install
pip install zotdocx
Python 3.9 or later; the only dependency is lxml. From a checkout, pip install ..
repair, and the broken-link part of status, need zotero.sqlite. It is looked up in this order: --zotero-db, the ZOTERO_DB environment variable, then ~/Zotero/zotero.sqlite. If none is found, the document-side checks still run and the broken-link check is skipped.
Usage
Write commands are dry runs until --apply is given:
zotdocx heal manuscript.docx # print what would change
zotdocx heal manuscript.docx --apply # write, original backed up as *.bak_<timestamp>
zotdocx lift manuscript.docx --apply --out new.docx
Exit code is 1 when status finds a problem, 0 otherwise, and 2 for usage or file errors.
Scope
- Only
word/document.xmlis replaced; every other part of the package is preserved byte for byte. - Numbers in table cells, captions and notes stay plain text;
renumbersyncs the digits and never turns them into fields. - Caption, note and bibliography headings are recognised in both Chinese (图 / 表 / 注 / 参考文献) and English (Table / Figure / Note / References).
- The Zotero database is opened read-only, from a temporary copy.
- No wording changes, no layout, no conversion to a final plain-text manuscript.
Limitations
- Numeric CSL styles only. Author–date styles have no numbers to reorder.
- Verified on Windows with Word only.
- Citations split across several runs are reported, not lifted.
repairmatches by item key or exact title; anything else is reported, never guessed.patchrequires a patchedintegration.jssupplied by the user. See docs/integration-patch.md.
Tests
python tests/run_all.py
Tests run against synthetic documents built in the test process, in Chinese and English. No real manuscript or library content is included. The same suite runs on GitHub Actions for Python 3.9, 3.11 and 3.13.
Advanced: Zotero integration patch
If Zotero reports Cannot delete range and citation fields keep breaking, the cause is on the Zotero side, not in the document. docs/integration-patch.md describes a small snippet for integration.js and the three steps to apply it with zotdocx patch. It is optional, it modifies Zotero rather than the document, and a Zotero update overwrites it.
License
MIT, see LICENSE.
Metadata
Release files for zotdocx 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zotdocx-0.2.0.tar.gz | 33.7 kB | Without provenance | Details for zotdocx-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zotdocx-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zotdocx-0.2.0-py3-none-any.whl |
Total release size: 64.4 kB
Release files / zotdocx-0.2.0.tar.gz
| Download URL | zotdocx-0.2.0.tar.gz |
|---|---|
| Size | 33.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab04b9dbf139d8282b349c90a90b49e9573c0e2499bd96071baf5a21695527ab
|
|
BLAKE2b-256 checksum How to use checksums |
e80e558dda5bc94654bc9c9181e8f00d472a56557220a4db4d65d268fc00f341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / zotdocx-0.2.0-py3-none-any.whl
| Download URL | zotdocx-0.2.0-py3-none-any.whl |
|---|---|
| Size | 30.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2b818aab3c6935be4c1d2bce8f48a163405304bc799f0e37e827e5c0ac4de68
|
|
BLAKE2b-256 checksum How to use checksums |
b09ce2b9fe22b52c1ee479d954b2546d1a3944525d716b52f43b5a79a626f3fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for zotdocx 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.