Convert manually typed formulas in Word documents (.doc, .docx, .wps) into editable Word equations while preserving layout through local Microsoft Word or Li...
--- name: word-latex-formula description: Convert manually typed formulas in Word documents (.doc, .docx, .wps) into editable Word equations while preserving layout through local Microsoft Word or LibreOffice conversion and direct OOXML edits. Use for academic manuscripts, staged formula review, local batch conversion, or optional AI-assisted formula classification. --- # Word Formula Conversion Use this skill when a user wants manually typed formula text in a Word document converted into editable Word equations while preserving the original document layout as much as possible. ## Resource Layout The runnable project is bundled at `resources/latex_convert_project/`. - Core CLI: `python3 -m latex_convert.cli` - Web UI starter: `python scripts/start_web.py` - Security notes: read `references/SECURITY_AND_PRIVACY.md` before enabling AI review or configuring any external model endpoint. - Operational details: read `references/USAGE.md` when a user asks for installation, web UI, or advanced parameters. ## Default Workflow 1. Keep the source document unchanged. 2. Work from `resources/latex_convert_project/` unless the user provides another checkout path. 3. For `.doc` or `.wps`, use `--engine auto` by default. macOS and Windows try Microsoft Word first; if Word automation fails, the code falls back to LibreOffice. Linux uses LibreOffice. 4. For important manuscripts, prefer the staged pipeline: `scan`, review or decide, then `apply`. 5. Leave bibliography protection enabled unless the user explicitly says formulas appear inside the bibliography section. 6. Modify only OOXML formula targets. Do not rebuild the document with high-level document libraries. 7. Verify output by checking the JSON report and confirming Word math nodes exist. ## Common Commands One-step local conversion: ```bash cd resources/latex_convert_project python3 -m latex_convert.cli convert input.docx -o output.docx --report report.json ``` Staged review: ```bash cd resources/latex_convert_project python3 -m latex_convert.cli scan input.docx --out candidates.json --review-doc candidates.docx python3 -m latex_convert.cli decide candidates.json -o decisions.json --provider rule python3 -m latex_convert.cli apply input.docx --decisions decisions.json -o output.docx --report apply_report.json ``` Optional AI-assisted decision: ```bash cd resources/latex_convert_project python3 -m latex_convert.cli decide candidates.json \ -o ai_decisions.json \ --provider ai \ --api-key "$OPENAI_API_KEY" \ --base-url "https://api.openai.com/v1" \ --model "gpt-4.1-mini" ``` Quick Web UI: ```bash cd resources/latex_convert_project python scripts/start_web.py ``` Open `http://127.0.0.1:5173`. ## Data and Network Policy Default rule-based conversion is local-only. It reads the user's document, invokes local Word or LibreOffice when needed, edits OOXML locally, and writes local output files. External network requests occur only when the user explicitly chooses AI review, clicks AI conversion in the Web UI, or tests a configured AI model. In that mode, the tool sends only formula-candidate data needed for classification and LaTeX normalization to the user-provided `base_url`: candidate id, formula text, nearby context, local LaTeX draft, confidence/default action, and model metadata. The whole Word file is not uploaded by the built-in AI review path. API keys are read from user input or local environment files and are not bundled in this skill. If an AI request times out or fails, the tool retries once by default and then falls back to local rule decisions, preserving task completion without requiring further external calls. ## Quality Checks - Confirm the output `.docx` opens in Word. - Confirm converted formulas are editable Word equations, not images. - Check `formulas_converted`, `formulas_kept`, and `failed` in the report. - Spot-check fractions, subscripts, superscripts, Greek letters, sums, and inequalities.
don't have the plugin yet? install it then click "run inline in claude" again.
convert manually typed formula text in Word documents (.doc, .docx, .wps) into editable Word equations while preserving document layout. use this skill for academic manuscripts, staged formula review, local batch conversion, or optional AI-assisted formula classification. formulas stay local by default. external AI classification happens only when you explicitly request it.
document file
project workspace
resources/latex_convert_project/microsoft word or libreoffice
.doc and .wps conversionoptional: openai api key (for ai-assisted formula classification)
OPENAI_API_KEY--provider ai in decide stephttps://api.openai.com/v1gpt-4-minioptional: custom ai endpoint
--base-url: override openai endpoint (e.g., self-hosted llm)--model: specify model name your endpoint recognizesinput: source word document (input.docx) output: candidates.json (list of formula candidates), optional candidates.docx (review doc with highlighted candidates)
run scan to locate all formula-like text in the document:
cd resources/latex_convert_project
python3 -m latex_convert.cli scan input.docx --out candidates.json --review-doc candidates.docx
the scanner identifies patterns matching likely formulas (math symbols, subscripts, superscripts, greek letters, operators). review candidates.docx to verify the scanner found real formulas and didn't over-match.
input: candidates.json output: decisions.json (conversion decisions for each candidate)
classify candidates using built-in rules:
cd resources/latex_convert_project
python3 -m latex_convert.cli decide candidates.json -o decisions.json --provider rule
this converts formula candidates to openxml math markup using local heuristics. no external calls. fast. suitable for most documents.
input: candidates.json, openai api key output: ai_decisions.json (ai-classified decisions)
if you want ai to normalize latex or improve confidence scores:
cd resources/latex_convert_project
python3 -m latex_convert.cli decide candidates.json \
-o ai_decisions.json \
--provider ai \
--api-key "$OPENAI_API_KEY" \
--base-url "https://api.openai.com/v1" \
--model "gpt-4-mini"
ai receives candidate id, formula text, nearby context, local latex draft, and confidence. the full word file is not sent. if the request times out or fails, the tool retries once and falls back to rule-based decisions automatically.
input: source document (input.docx), decisions.json or ai_decisions.json output: converted document (output.docx), apply_report.json (conversion log)
apply the conversion decisions to the source document:
cd resources/latex_convert_project
python3 -m latex_convert.cli apply input.docx --decisions decisions.json -o output.docx --report apply_report.json
the tool modifies only openxml formula nodes (math elements in the document.xml). it does not rebuild the document using high-level libraries. layout is preserved. the original source file is not modified.
input: source word document (input.docx) output: converted document (output.docx), report.json
if you want scan, decide, and apply in one call:
cd resources/latex_convert_project
python3 -m latex_convert.cli convert input.docx -o output.docx --report report.json
this uses rule-based decisions by default. suitable for quick batch jobs. does not create intermediate review or decision files.
input: output.docx, report.json output: visual confirmation
open output.docx in microsoft word or compatible editor. confirm:
check the report.json for summary:
formulas_converted: count of successful conversionsformulas_kept: count of text left unchangedfailed: count of conversion errorsspot-check a few formulas: fractions, subscripts, superscripts, greek letters, summation, integrals, inequalities.
if you have .doc or .wps files (not .docx)
--engine auto (default) to enable this fallback.if you want to skip bibliography sections
<w:tblPr> or marked as bibliography are not converted. if your formulas appear inside the bibliography, disable protection: --skip-bibliography false.if ai classification times out or fails
if the output document doesn't open in word
if you have no internet or want zero external calls
--provider rule in the decide step (step 2a). ai-assisted classification requires network access. rule-based classification is always local and fast.if you want to review decisions before applying
if you want to batch-convert multiple documents
candidates.json (output of scan)
{
"document_path": "input.docx",
"scan_timestamp": "2025-01-15T10:30:00Z",
"candidates": [
{
"id": "cand_001",
"text": "E=mc^2",
"context": "Einstein proved that E=mc^2 in 1905.",
"location": "paragraph_5",
"confidence": 0.92
}
]
}
decisions.json (output of decide with rule provider)
{
"candidates_processed": 42,
"decisions": [
{
"candidate_id": "cand_001",
"action": "convert",
"latex_draft": "E = mc^2",
"openxml_markup": "<m:oMath>...</m:oMath>",
"confidence": 0.92
}
],
"provider": "rule"
}
ai_decisions.json (output of decide with ai provider)
"provider": "ai"output.docx (output of apply or convert)
apply_report.json (output of apply or convert)
{
"document_path": "input.docx",
"output_path": "output.docx",
"conversion_timestamp": "2025-01-15T10:35:00Z",
"summary": {
"formulas_converted": 40,
"formulas_kept": 2,
"failed": 0
},
"conversions": [
{
"candidate_id": "cand_001",
"status": "success",
"original_text": "E=mc^2",
"formula_type": "equation"
}
]
}
candidates.docx (output of scan, optional)
formulas_converted > 0 and failed == 0