| name | mathtype-word-assistant |
| description | Create, inspect, export, and incrementally edit Microsoft Word DOCX documents containing real MathType OLE equations that open in MathType on double-click. Use for Word or DOCX tasks involving MathType, TeX/LaTeX conversion, inline or display equations, native left/right equation numbering, native equation references, or inserting, replacing, deleting, and renaming formulas. Trigger on requests mentioning MathType, Word formulas, DOCX equations, inline formulas, numbered formulas, equation references, or Chinese terms such as 公式、行内公式、左编号、右编号、公式引用、新增公式、修改公式、删除公式. Requires Windows, desktop Microsoft Word, and MathType 7 for full automation; do not treat WPS Writer as an execution host. |
MathType Word Assistant
Use the bundled deterministic PowerShell entry point. Resolve every path relative to the directory containing this SKILL.md; do not assume where the user installed the skill. Prefer the fast path below and load references/operations.md only for advanced or unclear edit payloads.
Fast path
Set <skill-root> to this skill directory and run commands with:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" <command> <arguments>
Do not run a routine environment preflight before normal work. The installer already performs the baseline check. mtword.ps1 starts and reuses its hidden Word service automatically; do not start word_service.ps1 manually.
Keep document source, edit payloads, and returned manifests in memory. Do not create helper .txt, .md, changes.json, or *.mathtype.json files.
Create
Compose the complete document source in memory. Mark formulas as:
- Inline:
$...$
- Display:
\[...\]
- Right-numbered:
[[MT-RIGHT]]\[...\]
- Left-numbered:
[[MT-LEFT]]\[...\]
Pipe the UTF-8 source to:
$source | powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" create -SourceStdin -OutputPath "paper.docx" -Json
If the requested output .docx already exists but is 0 bytes, treat it as a user-created placeholder and overwrite it with create -SourceStdin -OutputPath <that same path>. Do not inspect or inventory a 0-byte placeholder when the user is asking to write or generate a new document.
If the current PowerShell session may not emit UTF-8 to native commands, set $OutputEncoding to UTF-8 before piping. Return the exact output path and state that formulas are real MathType OLE objects that open in MathType on double-click.
Edit
Use managed working copies by default. The original remains unchanged; after edits the folder contains the original, paper_当前版.docx, and, from the second real edit onward, paper_上一版.docx.
If the target .docx is 0 bytes and the user asks to write, generate, fill, or create content in it, switch to the Create flow and use that path as -OutputPath. If the user asks to modify existing content in a 0-byte file, explain that there is no existing document content to inspect or edit and ask for a non-empty valid .docx.
- Inspect first. If the user supplies the original filename,
inspect automatically prefers its current working copy:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" inspect -InputPath "paper.docx" -Json
- If there is no embedded manifest, run inventory once. Inventory initialization is not a real edit and must not create
上一版:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" inventory -InputPath "paper.docx" -Json
- Build one JSON payload for all changes in the user's message, then pipe it to edit:
$operationsJson | powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" edit -InputPath "paper.docx" -OperationsStdin -Json
Batch related insert, replace, delete, reference, and rename operations into the same run. All insert and replace formulas in one payload are converted together with one MathType Toggle TeX call.
Common edit payloads
Use these schemas directly for routine edits. Read references/operations.md only when you need advanced location choices, deletion with references, reference deletion, ID renaming, or extra examples.
Wrap multiple changes as:
{ "operations": [] }
Replace formula while preserving layout:
{ "operation": "replace", "id": "eq_0001", "tex": "E=mc^2" }
Insert formula. Valid layouts are inline, display, right-numbered, and left-numbered:
{
"operation": "insert",
"id": "eq_loss",
"tex": "\\mathcal{L}=\\frac{1}{n}\\sum_i(y_i-\\hat{y}_i)^2",
"layout": "right-numbered",
"location": { "type": "formula", "id": "eq_0001", "position": "after" }
}
Delete formula:
{ "operation": "delete", "id": "eq_0003" }
Reference a native left- or right-numbered formula:
{
"operation": "reference",
"id": "ref_loss",
"target_id": "eq_loss",
"location": { "type": "document_end" },
"prefix": "See equation ",
"suffix": "."
}
Common locations are:
{ "type": "document_start" }
{ "type": "document_end" }
{ "type": "formula", "id": "eq_0001", "position": "before" }
{ "type": "formula", "id": "eq_0001", "position": "after" }
Export source
The embedded manifest identifies formulas but does not contain their TeX source. Export only when the user explicitly asks for exact TeX source or a TeX source copy:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<skill-root>\scripts\mtword.ps1" export -InputPath "paper.docx"
Never edit the original during export.
Guardrails
- Require Windows, desktop Microsoft Word, MathType 7 OLE registration, the MathType Word add-in, and enabled MathType macros for mutating operations.
- Use
-RestartWorkingCopy only when the user explicitly wants to discard managed edit history and restart from the original.
- Use
-DirectOutput -OutputPath ... only when the user requests a separately named deliverable.
- Keep built-in verification enabled. Use
-SkipVerification only when the user explicitly asks.
- If the service cannot start before a request is sent, the wrapper falls back to direct Word mode. After a request has been sent, never repeat it automatically.
- After a Word, MathType OLE, add-in, or macro-related failure, let
mtword.ps1 run the deep check and relay its Reason: and Next action: lines instead of raw PowerShell stack details.
- Preserve the last successful current copy; the engine commits a managed working copy only after Word, MathType, and structural verification succeed.
- On ambiguous formula selection, inspect the manifest and surrounding document content before asking the user.
- Native references can target only left- or right-numbered MathType formulas. Deletion of a referenced formula is rejected unless the operation explicitly sets
delete_references to true.
- Do not claim WPS-only automation support. Generated DOCX files may be opened in WPS, but this tool controls
Word.Application.