Use when modifying fonts in Word documents, especially for thesis requirements like setting Times New Roman for English and numbers
Modify fonts in Word documents (.docx files) with precise control over which fonts to change for which character sets.
Use this skill whenever the user asks to:
This skill is NOT for:
docx skill instead)# User wants numbers and English in Times New Roman, Chinese in 宋体
python scripts/modify_font.py input.docx output.docx --western Times New Roman --cjk 宋体
# Change all Arial to Calibri
python scripts/modify_font.py input.docx output.docx --replace-font Arial --with Calibri
# Set all Western fonts to Times New Roman
python scripts/modify_font.py input.docx output.docx --western "Times New Roman"
DOCX uses these font attributes in <w:rFonts> elements:
w:ascii - ASCII/Western characters (0-127)w:hAnsi - High ANSI characters (extended ASCII)w:cs - Complex scriptw:eastAsia - East Asian characters (Chinese, Japanese, Korean)w:hint - Font hinting for fallbackFor Chinese thesis requirements:
python <skill-path>/scripts/unpack_docx.py input.docx unpacked/
Edit unpacked/word/document.xml and unpacked/word/styles.xml:
For document.xml - Find all <w:rFonts> elements and update:
<!-- Before -->
<w:rFonts w:ascii="宋体" w:eastAsia="宋体" w:hAnsi="宋体" w:cs="宋体"/>
<!-- After (Western→Times New Roman, East Asian→宋体) -->
<w:rFonts w:ascii="Times New Roman" w:eastAsia="宋体" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
For styles.xml - Also update the theme-based font references:
<!-- Theme references like w:asciiTheme="minorHAnsi" need explicit fonts -->
<w:rFonts w:ascii="Times New Roman" w:eastAsia="宋体" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
python <skill-path>/scripts/pack_docx.py unpacked/ output.docx --original input.docx
THESIS_PRESET = {
"western": "Times New Roman",
"cjk": "宋体",
"description": "数字和英文用Times New Roman,中文用宋体"
}
WESTERN_DOC = {
"western": "Times New Roman",
"cjk": "SimSun",
"description": "All text in Times New Roman"
}
Cause: The paragraph uses a style with theme-based font references (w:*Theme) instead of explicit fonts.
Solution: Also modify styles.xml - look for patterns like:
<w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorEastAsia"/>
Replace with explicit fonts:
<w:rFonts w:ascii="Times New Roman" w:eastAsia="宋体" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
Solution: Run pack with --validate false flag to skip validation:
python pack_docx.py unpacked/ output.docx --original input.docx --validate false
defusedxml - XML parsinglxml - XML validation (optional, needed for validation)Install with:
pip install defusedxml lxml
```37:["$","$L3e",null,{"content":"$3f","frontMatter":{"name":"docx-font-modifier","description":"Use when modifying fonts in Word documents, especially for thesis requirements like setting Times New Roman for English and numbers"}}]