Skip to content

Polar-Line/thesis-formatter

Repository files navigation

Thesis Formatter

通用毕业论文格式自动调整工具。输入任意学校的论文格式模板 + 你的论文初稿,自动输出符合格式要求的论文终稿。

安装

pip install -e ".[dev]"

依赖:Python 3.10+ / python-docx / PyYAML

快速开始

# 一步到位(推荐)
thesis-fmt format 我的论文.docx --template 学校模板.docx -o 论文完成版.docx

# 或者分两步
thesis-fmt extract 学校模板.docx -o 学校格式.yaml   # 提取格式规则
thesis-fmt apply 我的论文.docx -c 学校格式.yaml -o 论文完成版.docx  # 应用格式

命令

命令 说明
thesis-fmt format <论文.docx> --template <模板.docx> [-o 输出.docx] 一步到位:提取 + 格式化 + 插入封面
thesis-fmt extract <模板.docx> [-o 配置.yaml] 从学校模板提取格式规则
thesis-fmt apply <论文.docx> -c <配置.yaml> [-o 输出.docx] 应用格式到论文
thesis-fmt validate <配置.yaml> 验证配置文件

封面页插入

# 指定封面页码(模板中第 1、2、3 页为封面)
thesis-fmt format 我的论文.docx --template 学校模板.docx --cover-page 1,2,3 -o 输出.docx

# 不插入封面
thesis-fmt format 我的论文.docx --template 学校模板.docx --cover-page 无 -o 输出.docx

# 不指定 --cover-page 时会交互式询问

功能

  • 自动识别段落类型:章标题、节标题、正文、参考文献、摘要、目录、图表题注、附录、致谢等
  • 应用对应格式:字体、字号、加粗、对齐、缩进、行距(固定值 / 倍数)
  • 按章分节:每章自动插入分节符,页眉跟随章标题
  • 封面页插入:从模板提取封面页(含图片/Logo),自动插入到论文开头
  • 大纲级别:自动设置,Word 中右键目录 → 更新域即可生成目录
  • 三线表:自动设置表格边框
  • 单位换算:支持 cm / mm / pt / chars 等多种单位

配置示例

page:
  size: A4
  margins: { top: 2.54cm, bottom: 2.54cm, left: 3.18cm, right: 3.18cm }
headings:
  - level: 1
    font: { east_asian: 黑体 }
    size: 16pt; bold: true; alignment: center
    numbering: "第%1章"
  - level: 2
    font: { east_asian: 黑体 }
    size: 14pt; bold: true; alignment: left
    numbering: "%1.%2"
body:
  font: { east_asian: 宋体, western: Times }
  size: 12pt; first_line_indent: 2chars
  line_spacing: 1.5
references:
  entry: { size: 10.5pt, hanging_indent: 2chars }

完整配置参见 configs/example_config.yaml

适用范围

  • 适用于任意学校的毕业论文格式模板,只需提供 .docx 模板文件即可
  • 只改格式,不改文字内容
  • 不支持 .doc 旧格式,需先另存为 .docx
  • 用 Word 打开输出文件后,右键目录 → 更新域(F9)刷新页码
  • 提取的 YAML 可以分享给同校同学,不用每人跑一次 extract

项目结构

thesis_formatter/
├── cli.py              # 命令行入口
├── engine.py           # 核心引擎(分节+页眉+段落格式)
├── extractor.py        # 模板格式提取
├── classifier.py       # 段落智能分类
├── cover_inserter.py   # 封面页提取与插入
├── units.py            # 单位换算
└── formatters/         # 14 个格式插件
    ├── page.py         # 页面/边距
    ├── defaults.py     # 默认字体
    ├── sections.py     # 分节/页眉/页码
    ├── headings.py     # 标题+编号
    ├── body.py         # 正文
    ├── figures.py      # 图题注
    ├── tables.py       # 三线表
    ├── references.py   # 参考文献
    ├── toc.py          # 目录
    ├── abstract.py     # 摘要
    ├── cover.py        # 封面
    ├── equations.py    # 公式
    ├── footnotes.py    # 脚注
    └── misc.py         # 附录/致谢

开发

pip install -e ".[dev]"
python -m pytest tests/ -v

许可证

MIT

About

Automated Paper Format Modification

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors