Thai DOCX Fixer: Thai That Renders Right in Word

    1

    Stop broken Thai in generated Word files: wrong font, tiny text, thin bold and floating tone marks, fixed with one call before save, plus a scanner that proves it.

    Free

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Thai DOCX Fixer: Thai That Renders Right in Word

    Example session with this skill installed

    Write a one-page Thai service agreement as a .docx with python-docx: a bold title, 16pt TH Sarabun New body, and a two-column table for the parties. It will be opened in Microsoft Word by the client, so make sure the Thai renders correctly there.

    • Read your context and instructions
    • Compiled the thai docx fixer

    Summary

    Built service_agreement.docx, patched the Thai complex-script slots with enforce_thai(doc), and ran the scanner: 6 of 6 Thai runs pass. Before the patch the same file failed on all 6.

    Code

    from docx import Document
    from docx.shared import Pt
    from enforce_thai import enforce_thai, add_word_breaks
    
    doc = Document()
    doc.add_heading("สัญญาจ้างบริการ", level=1)
    
    p = doc.add_paragraph()
    p.add_run("Agreement No. 12 ")
    title = p.add_run("ฉบับนี้ทำขึ้นเมื่อวันที่ 1 มกราคม 2569")
    title.bold = True
    
    body = doc.add_paragraph().add_run("ผู้ว่าจ้างและผู้รับจ้างตกลงกันดังต่อไปนี้")
    body.font.size = Pt(16)
    
    table = doc.add_table(rows=1, cols=2)
    table.rows[0].cells[0].text = "ผู้ว่าจ้าง"
    table.rows[0].cells[1].text = "ผู้รับจ้าง"
    doc.sections[0].header.paragraphs[0].text = "หน้า 1"
    
    add_word_breaks(doc)   # word-boundary hints for justified Thai
    enforce_thai(doc)      # one call, right before save
    doc.save("service_agreement.docx")
    

    Scanner before the patch

    python verify_thai_docx.py service_agreement.docx

    LocationThai runProblem
    body para 0สัญญาจ้างบริการno rPr: font, size and bold all unset
    body para 1 run 1ฉบับนี้ทำขึ้น...w:cs missing, w:bCs missing: Thai not bold
    body para 2ผู้ว่าจ้าง...w:szCs missing: Thai smaller than the 16pt Latin
    table r0 c0, r0 c1ผู้ว่าจ้าง / ผู้รับจ้างno rPr
    headerหน้า 1no rPr

    ✗ FAIL — 6/6 Thai run(s) have issues.

    Scanner after the patch

    ✓ PASS — 6 Thai run(s) checked, all OK. File is ready to send.

    Opened in Microsoft Word: every Thai run reports TH Sarabun New, 16pt where a size was set, bold where set. <w:rPr> children are in schema order, so Word shows no repair prompt.

    Next steps

    1. Replace the placeholder clauses with the reviewed contract text.
    2. If the text came from a PDF, pass it through clean_pdf_thai() first.
    3. Re-run the scanner after every edit that regenerates the file.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    python-docx writes only the Latin font slot. Microsoft Word draws Thai from the complex-script slot, so a Thai .docx that looks fine in a preview opens on a client's Word with the wrong font, Thai text smaller than the English next to it, bold and italic missing on the Thai part, and tone marks floating off their consonants.

    This skill teaches your agent to fix that every time it writes a Thai Word file:

    • enforce_thai(doc) — one call before doc.save(). Fills w:cs, w:szCs, w:bCs, w:iCs and w:lang on every run, style, table cell, header and footer, in the child order the OOXML schema requires.
    • verify_thai_docx.py — a CLI scanner that fails the build when any Thai run is still missing a slot (exit 1), so the agent checks instead of guessing.
    • add_word_breaks(doc) — optional zero-width break hints so justified Thai paragraphs wrap at word boundaries (uses pythainlp).
    • clean_pdf_thai(text) — repairs Thai pasted from PDFs: injected spaces, zero-width characters, NFD tone marks, split sara am.
    • selftest.py — proves the whole thing works on the buyer's machine in one command.

    Defaults follow the Thai government document standard (TH Sarabun New, 16pt); font and size are parameters.

    Requires: Python 3.9+, python-docx. Optional: pythainlp. Tested: output opened in Microsoft Word on Windows; Word reports TH Sarabun New, correct size, bold and italic on the Thai runs.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Writing & Content.

    Requires python-docx; the word-break helper also needs pythainlp. Patches paragraphs in the body, top-level tables, headers and footers. Text inside nested tables, text boxes, footnotes and hyperlinks is not patched yet. Preview tools (LibreOffice, Word Online) hide the bug, so check with the scanner, not by eye.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 18 days ago

    • Free with an Agensi account

    Software
    Python 3.9+python-docx
    Optional
    pythainlp

    Permissions

    Terminal / Shell
    Write Files
    Read Files

    File Scopes

    *.docx

    Runs Python scripts in the terminal, reads the .docx you generate, and writes the patched .docx back. No network access, no accounts.

    Listed18 days ago

    What's inside

    Frequently Asked Questions

    python-docx only writes the Latin font slot. LibreOffice and Word previews pick a Thai font on their own, so the file looks right there, but desktop Word reads the empty complex-script slot and falls back. enforce_thai(doc) fills that slot plus size, bold, italic and language on every Thai run.

    Yes, this skill is designed to work with any standard python-docx project; you simply build your document as usual and call the enforcement function right before saving.

    The core rendering fixes only require python-docx, but if you want to use the automatic word-break and justification features, you will need to install the pythainlp library.

    SKILL.md (the workflow your agent follows), enforce_thai.py (enforce_thai, add_word_breaks, clean_pdf_thai), verify_thai_docx.py (the CLI scanner, exit 0 pass / 1 fail), selftest.py (one-command check on your machine) and an XML reference explaining each Word complex-script slot.

    Run python scripts/selftest.py once after install. For each real file, run python verify_thai_docx.py yourfile.docx: exit 0 means every Thai run has its font, size, bold, italic and language slots set. Don't judge by LibreOffice or Word Online previews; they hide the bug.

    New in Writing & Content

    Free