Docx
Skill MrSGSA/math-modeling-skill-dify/.agents/skills/math-modeling/tools/docx
创建、编辑、校验和转换 Word DOCX,支持数学建模论文模板、原生公式、三线表、修订和批注。From its SKILL.md
npx -y skills add MrSGSA/math-modeling-skill-dify --skill docxAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.1 KB, ~1.4k tokens by cl100k_base, as published. Nobody here has run it
DOCX 工具
路径与写入
- 当前目录为本工具根目录,只读。
- 模板和脚本从本目录读取。
- 生成或修改后的 DOCX 必须写入用户
PROJECT_ROOT。 - 默认不覆盖输入文件或 Skill 文件。
数学建模论文推荐流程
采用“当届官方参考模板 + python-docx 构建 + OMML 公式 + OOXML 校验 + 渲染抽检”。官方模板控制页面、样式、分节、页眉页脚和编号;代码负责稳定写入内容。
from pathlib import Path
import sys
scripts = Path("<SKILL_ROOT>") / "tools" / "docx" / "scripts"
sys.path.insert(0, str(scripts))
import paper_format as pf
doc = pf.new_document(
contest="cumcm",
template_path=Path("<PROJECT_ROOT>") / "当届官方模板.docx",
preserve_template_content=False,
)
# 此示例只借用模板样式后追加正文。
# 若官方模板包含固定摘要页或编号页,应改为 True 并在原位置填充。
pf.title(doc, "论文题目")
pf.abstract_title(doc)
pf.body(doc, "摘要正文。")
pf.keywords(doc, "优化;预测")
pf.equation(doc, r"\min f(x)=\sum_{i=1}^{n}x_i^2")
pf.three_line_table(doc, [["符号", "说明"], ["x", "决策变量"]])
pf.save_document(doc, Path("<PROJECT_ROOT>"), contest="cumcm")
公式
直接写入
scripts/equations.py 把常用 LaTeX 子集转成 Word 原生 OMML。未知命令、未闭合分组和不支持环境会报错,不会静默生成错误文本。
python scripts/equations.py replace "输入.docx" `
--replace "EQ_OBJECTIVE" "\min f(x)=\sum_{i=1}^{n}x_i^2" `
--output "<PROJECT_ROOT>/输出.docx"
同一占位符出现多次时会全部替换。支持分式、上下标、根式、n 次根、常用希腊字母与关系符号、反三角函数和常见矩阵,包括 \nu、\mu、\approx、\arcsin、\arccos、\arctan。
复杂公式
复杂 LaTeX 优先使用 Pandoc 的成熟转换:
python scripts/equations.py generate "论文.md" `
--output "<PROJECT_ROOT>/论文.docx" `
--template "官方模板.docx"
转换后仍须校验和渲染抽检。
解包、校验与重打包
DOCX/XLSX 共用的 OOXML 基础工具只保留在 scripts/office/:
python scripts/office/unpack.py "输入.docx" "<PROJECT_ROOT>/unpacked"
python scripts/office/validate.py "<PROJECT_ROOT>/输出.docx"
python scripts/office/pack.py "<PROJECT_ROOT>/unpacked" "<PROJECT_ROOT>/输出.docx" --original "输入.docx"
不要在不理解 OOXML 关系和内容类型的情况下直接修改压缩包。
修订
python scripts/accept_changes.py "输入.docx" "<PROJECT_ROOT>/已接受修订.docx"
工具使用隔离的 LibreOffice 配置。超时、非零退出或残留修订标记都会失败,失败时不发布输出文件。
批注
先解包,再添加批注元数据和文档标记。父批注不存在或批注 ID 重复时,工具会在写入前失败。
python scripts/comment.py "<PROJECT_ROOT>/unpacked" 0 "批注意见"
python scripts/comment.py "<PROJECT_ROOT>/unpacked" 1 "回复意见" --parent 0
必做验证
python scripts/check_env.py
python scripts/self_check.py
python scripts/office/validate.py "<PROJECT_ROOT>/完整论文.docx"
调用 validate_paper_structure() 检查官方前置结构、摘要页渲染填充率、正文篇幅质量目标、公式/图/表数量、图表编号与正文引用、参考文献双向对应,并分别传入PDF总页数、正文页数、摘要有效区域填充率和电子文件大小。CUMCM默认以摘要充实且不溢出一页、正文恰好30页为优选质量目标;以2026年官方规范为例,正文不超过30页、电子论文不超过20MB才是硬约束,附录和PDF总页数不限。一级标题默认连续排版,不得逐章强制分页制造空白。结构校验后,把DOCX渲染成PDF或图片抽检分页、公式、表格、图片、页眉页脚和字体替换。
What ships with it: 69 files
1194.8 KB alongside SKILL.md, 22 of them executable
agents/
- openai.yaml308 B
references/
scripts/
- accept_changes.pyruns5.7 KB
- check_env.pyruns840 B
- comment.pyruns11.2 KB
- equations.pyruns24.4 KB
- __init__.pyruns1 B
- inspect_template_format.pyruns7.2 KB
- office/helpers/__init__.pyruns0 B
- office/helpers/merge_runs.pyruns5.4 KB
- office/helpers/safe_zip.pyruns6.7 KB
- office/helpers/simplify_redlines.pyruns5.6 KB
- office/pack.pyruns4.9 KB
- office/schemas/ecma/fouth-edition/opc-contentTypes.xsd1.9 KB
- office/schemas/ecma/fouth-edition/opc-coreProperties.xsd2.5 KB
- office/schemas/ecma/fouth-edition/opc-digSig.xsd2.8 KB
- office/schemas/ecma/fouth-edition/opc-relationships.xsd1.3 KB
- office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd6.8 KB
- office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd73.2 KB
- office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd50.1 KB
- office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd624 B
- office/schemas/ISO-IEC29500-4_2016/dml-main.xsd148.5 KB
- office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd1.2 KB
- office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd8.7 KB
- office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd14.4 KB
- office/schemas/ISO-IEC29500-4_2016/pml.xsd81.7 KB
- office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd1.2 KB
- office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd7.2 KB
- office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd6.2 KB
- office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd1.2 KB
- office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd880 B
- office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd2.5 KB
- office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd3.4 KB
- office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd7.3 KB
- office/schemas/ISO-IEC29500-4_2016/shared-math.xsd22.8 KB
- office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd1.3 KB
- office/schemas/ISO-IEC29500-4_2016/sml.xsd236.6 KB
- office/schemas/ISO-IEC29500-4_2016/vml-main.xsd25.5 KB
- office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd24.7 KB
- LICENSE.txt1.4 KB
29 more files not listed here. See all 69 in the repository.