# Endnote Cwyw DOCX

> Create or convert a Word manuscript so citations and the bibliography are genuine EndNote Cite While You Write fields linked to a native .enl library. Use for DOCX manuscripts that contain static numbered or author-year citations, when references must remain editable by changing the EndNote output style, or when validating ADDIN EN.CITE, ADDIN EN.REFLIST, Traveling Library records, and EndNote database linkage.

- Skill: `pkulhc/endnote-cwyw-docx` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add pkulhc/endnote-cwyw-docx`
- Raw SKILL.md: https://api.skillmd.com/api/skills/pkulhc/endnote-cwyw-docx/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- Author: pkulhc (https://skillmd.com/u/pkulhc)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/pkulhc/endnote-cwyw-docx

---


# EndNote CWYW for Word

Create a native EndNote library, convert static citations into dynamic CWYW fields, and verify that Word can reformat them through EndNote styles.

## Non-negotiable rules

- Use `officecli` for every DOCX read, edit, render, and validation operation.
- Do not use Word COM automation, `python-docx`, LibreOffice, or direct ZIP/OOXML writes.
- Use EndNote itself to create/import/save the `.enl` library. An EndNote library consists of both `name.enl` and `name.Data/`.
- Back up the DOCX before mutation. Put working files in the workspace `Codex_temp/` directory.
- Treat reference numbers as library record numbers, not merely displayed bibliography numbers.
- Abort on ambiguous paragraph matches, missing records, malformed fields, or a non-empty target that already contains EndNote fields.

## Workflow

### 1. Inventory and back up

1. Confirm the target DOCX, desired `.enl` path, reference source, citation markers, and bibliography boundaries.
2. Run:

```powershell
officecli view manuscript.docx text
officecli view manuscript.docx issues
```

3. Identify each citation paragraph by `paraId` from the text view or by a unique text fragment.
4. Keep the source manuscript unchanged until the citation map and reference-record mapping are complete.

### 2. Create the native EndNote library

1. Open EndNote and create a new library at the requested `.enl` path.
2. Import the RIS or EndNote XML source. For RIS, select `Reference Manager (RIS)` as the import option.
3. Prefer importing into an empty library in final reference order. Confirm the imported count and save.
4. Export or retain an EndNote XML file whose `<rec-number>` values match the native library record numbers.
5. Never move or deliver the `.enl` file without its same-named `.Data` folder.

Use EndNote UI control only for the library operations. Use the bundled scripts for database-ID extraction and DOCX field insertion.

### 3. Prepare the citation map

Read [citation-map.md](references/citation-map.md) and create a JSON file in `Codex_temp/`. Each item must identify one visible marker and the corresponding EndNote record number(s). Use `paragraphId` when available; otherwise use a unique `paragraphContains` value.

The bibliography configuration must identify the exact heading, the next section heading, and the pattern matching the existing static reference paragraphs.

### 4. Insert dynamic fields atomically

Run:

```powershell
$skill = Join-Path $env:USERPROFILE '.codex\skills\endnote-cwyw-docx'
& "$skill\scripts\insert_endnote_fields.ps1" `
  -DocxPath '.\manuscript.docx' `
  -EndNoteXmlPath '.\Codex_temp\references.xml' `
  -CitationMapPath '.\Codex_temp\citation-map.json' `
  -EndNoteLibraryPath '.\Codex_temp\Ref\library.enl'
```

The script:

- reads the DOCX through `officecli raw`;
- extracts the library database ID from `library.Data\sdb\sdb.eni`;
- embeds full Traveling Library records in `ADDIN EN.CITE` instructions;
- wraps the cached reference list in one `ADDIN EN.REFLIST` field;
- applies all mutations through one atomic `officecli batch`;
- preserves the visible citation and bibliography text;
- rolls back automatically if any batch operation fails.

Pass `-DatabaseId` only when automatic extraction is impossible. Pass `-BackupPath` to control the backup destination.

### 5. Validate before handoff

Run:

```powershell
& "$skill\scripts\validate_endnote_fields.ps1" `
  -DocxPath '.\manuscript.docx' `
  -ExpectedCitationFields 14 `
  -ExpectedUniqueRecords 15

officecli view '.\manuscript.docx' issues
officecli view '.\manuscript.docx' html --out '.\Codex_temp\endnote-preview.html'
```

Require all of the following:

- expected `ADDIN EN.CITE` count;
- exactly one `ADDIN EN.REFLIST`;
- balanced field begin/separate/end counts;
- all expected record numbers present in Traveling Library XML;
- one consistent EndNote `db-id`;
- no temporary `{Author, Year #Record}` citations;
- no generated `dNpN:space` XML namespace prefixes;
- zero `officecli` structural issues;
- unchanged visible citation markers and bibliography entries.

Finally, instruct the user to open the library, select another style in Word's EndNote tab, and choose **Update Citations and Bibliography**. This is the user-visible confirmation that the fields are editable CWYW objects.

## Failure handling

- If `sdb.eni` is locked, use the bundled extractor; it opens the file with read/write sharing.
- If database-ID extraction returns zero or multiple candidates, stop and inspect the library rather than guessing.
- If a marker is split across multiple Word runs, normalize that marker with `officecli` or choose a narrower paragraph edit before retrying.
- If the DOCX already contains `EN.CITE` or `EN.REFLIST`, validate or update it; do not wrap it a second time.
- If EndNote record numbers differ from bibliography numbering, rebuild the citation map from the actual library records.
- If Word displays cached text correctly but EndNote cannot update it, check the `db-id`, `<RecNum>`, Traveling Library record payload, and `.Data` folder first.

