Paper Formatter - 本科毕业论文排版
Overview
This skill automates the formatting of Chinese undergraduate thesis Word documents (.docx) according to common national standards (GB/T 7713, GB/T 7714). It applies page setup, font and paragraph styles, heading hierarchy detection, figure/table caption formatting, page numbering, table of contents insertion, reference formatting, and PDF conversion.
When to Use
Trigger this skill when the user wants to:
- Format a thesis or academic paper in Word
- Adjust paper fonts, line spacing, margins, or indentation
- Generate or update a table of contents
- Format references according to GB/T 7714-2015
- Convert a Word document to PDF
- Check or fix paper formatting issues
Typical user phrases: "排版论文", "格式化毕业论文", "调整论文格式", "设置论文字体", "生成目录", "排版参考文献", "论文转PDF".
Prerequisites
- Python 3.10+ with python-docx installed
- For PDF conversion: Microsoft Word (docx2pdf) or LibreOffice
- The skill scripts use the managed Python venv at
~/.workbuddy/binaries/python/envs/default
Quick Start
1. Format a Paper
# Basic formatting (creates *_formatted.docx)
python scripts/format_paper.py thesis.docx
# Format with table of contents
python scripts/format_paper.py thesis.docx --add-toc
# Format in-place (overwrites original)
python scripts/format_paper.py thesis.docx --inplace
# Custom margins
python scripts/format_paper.py thesis.docx --margin-top 3.5 --margin-left 2.8
2. Format References
# Renumber and format references
python scripts/format_references.py thesis.docx
# Check only (no changes)
python scripts/format_references.py thesis.docx --check-only
3. Convert to PDF
# Auto-detect conversion method
python scripts/docx_to_pdf.py thesis.docx
# Use specific method
python scripts/docx_to_pdf.py thesis.docx --method libreoffice
Workflow
Full Thesis Formatting Process
Execute the following steps in order:
-
Backup: Copy the original document before any modification.
-
Run format_paper.py: Apply page setup, styles, heading detection, and page numbers.
bash python scripts/format_paper.py input.docx --add-toc
This producesinput_formatted.docx. -
Run format_references.py: Renumber and format the references section.
bash python scripts/format_references.py input_formatted.docx --inplace -
Review heading detection: Check the script output for heading counts. If headings are misclassified (e.g., a list item detected as a heading), manually fix the heading styles in Word.
-
Update TOC: Open the document in Word, right-click the table of contents, and select "Update Field" → "Update entire table".
-
Check references: Review the format_issues output from format_references.py. Manually add missing document type markers ([M], [J], [D], etc.) and verify author name formats.
-
Convert to PDF (optional):
bash python scripts/docx_to_pdf.py input_formatted.docx
Scripts
scripts/format_paper.py
Main formatting script. Uses python-docx to:
- Set A4 page size and margins (top 2.5, bottom 2.5, left 2.75, right 2.5 cm by default; gutter on left)
- Configure Normal style: SimSun + Times New Roman, 12pt (xiao-4), fixed 21pt line spacing, 2-char first-line indent, 0pt before/after
- Configure Heading 1-3 styles: SimHei (hei-ti), sizes 16/12/10.5pt, with appropriate spacing
- Configure Caption style: SimHei, 10.5pt (wu-hao), centered, single line spacing
- Auto-detect headings by text patterns:
- "第一章" / "第X章" → Heading 1
- "摘要" / "目录" / "参考文献" / "致谢" etc. → Heading 1
- "1.1" pattern → Heading 2
- "1.1.1" pattern → Heading 3
- "1." / "1、" pattern → Heading 1 (short text only)
- Auto-detect figure/table captions ("图1-1..." / "表1-1...")
- Add centered page numbers in footer
- Insert TOC field after "目录" heading (with --add-toc flag)
Key options:
- --no-detect: Skip heading auto-detection (use existing styles only)
- --no-page-numbers: Skip page number insertion
- --add-toc: Insert table of contents field
- --margin-top/bottom/left/right: Custom page margins (cm)
scripts/format_references.py
Reference formatting helper. Uses python-docx to:
- Locate the "参考文献" section in the document
- Renumber references sequentially: [1] [2] [3]...
- Set font to SimSun + Times New Roman, 10.5pt (wu-hao)
- Apply flush-left formatting (no indent, top-aligned)
- Set single line spacing
- Check for common issues: missing type markers ([M]/[J]/[D] etc.), missing years
Key options:
- --check-only: Only report issues without modifying the document
- --inplace: Overwrite the original file
scripts/docx_to_pdf.py
PDF conversion utility. Supports two methods:
- docx2pdf (default on Windows): Uses Microsoft Word COM automation
- LibreOffice: Cross-platform, headless conversion
Auto-detects the best available method. Falls back automatically if one method fails.
Reference Documents
references/formatting_rules.md
Detailed formatting specifications for Chinese undergraduate theses:
- Document structure (cover → declaration → abstract → TOC → body → references → acknowledgments)
- Page setup (A4, margins, header/footer distance)
- Font/size/spacing for every element (title, headings, body, captions, references, page numbers)
- Page numbering scheme (Roman for front matter, Arabic for body)
- Section break instructions for split page numbering
- Figure, table, and formula formatting guidelines
Load this document when:
- The user asks about specific formatting requirements
- Manual adjustments are needed (e.g., split page numbering, cover page)
- The user has school-specific requirements to compare against
references/reference_styles.md
GB/T 7714-2015 reference citation format reference:
- Sequential numbering system rules
- Document type markers ([M], [J], [D], [C], [R], [S], [P], [N], [EB/OL])
- Author name formatting (Chinese and English)
- Complete format examples for each document type
- In-text citation formatting
- Common errors and corrections
Load this document when:
- The user asks how to format a specific reference
- Manual reference formatting is needed (scripts cannot auto-detect document types)
- Checking or correcting reference formatting issues
Limitations and Manual Steps
The scripts handle deterministic formatting automatically. The following require manual work or AI assistance:
-
Cover page: The cover page layout (title, name, student ID, etc.) must be formatted manually or using a school-provided template.
-
Split page numbering: Roman numerals for front matter (abstract, TOC) and Arabic for body requires section breaks and per-section footer settings. This must be done manually in Word.
-
Table of contents update: The script inserts a TOC field, but the actual content is generated by Word when the user right-clicks and selects "Update Field".
-
Reference content parsing: The script can renumber and format references, but cannot parse citation metadata (author, title, publisher) to apply GB/T 7714 formatting from scratch. Use the AI to help format each reference according to
references/reference_styles.md. -
Heading detection accuracy: Pattern-based detection may misclassify list items or short paragraphs as headings. Always review the script output and manually fix any misclassified paragraphs.
-
School-specific requirements: Default settings follow common national standards. If the user has school-specific requirements, adjust the command-line parameters or manually modify the formatted document.
Python Environment
All scripts require python-docx. The managed venv is at:
~/.workbuddy/binaries/python/envs/default
Run scripts using:
"~/.workbuddy/binaries/python/envs/default/Scripts/python.exe" scripts/format_paper.py input.docx
If python-docx is not installed:
"~/.workbuddy/binaries/python/envs/default/Scripts/pip.exe" install python-docx docx2pdf