make_latex_model
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNSFC LaTeX 模板高保真优化器
NSFC LaTeX Template High-fidelity Optimizer
你应该先读什么
What You Should Read First
- 详细工作流(含命令与决策点):
skills/make_latex_model/docs/WORKFLOW.md - Word PDF 基准制作:
skills/make_latex_model/docs/BASELINE_GUIDE.md - 脚本用法全集:
skills/make_latex_model/scripts/README.md - 常见问题:
skills/make_latex_model/docs/FAQ.md
- Detailed Workflow (including commands and decision points):
skills/make_latex_model/docs/WORKFLOW.md - Word PDF Baseline Creation:
skills/make_latex_model/docs/BASELINE_GUIDE.md - Complete Script Usage:
skills/make_latex_model/scripts/README.md - Frequently Asked Questions:
skills/make_latex_model/docs/FAQ.md
深度参考
In-depth References
- 本项目的 CLAUDE.md 和 skills/README.md 规范
- 现有某个 project 的 的样式定义模式
@config.tex - ⚠️ 关于 的参考范围:
main.tex- ✅ 允许参考:中的
main.tex、\section{}标题文本\subsection{} - ❌ 禁止参考:中的
main.tex引用的正文内容文件\input{}
- ✅ 允许参考:
- Specifications in CLAUDE.md and skills/README.md of this project
- Style definition pattern of in an existing project
@config.tex - ⚠️ Reference Scope for :
main.tex- ✅ Allowed to reference: ,
\section{}title texts in\subsection{}main.tex - ❌ Forbidden to reference: Main content files referenced by in
\input{}main.tex
- ✅ Allowed to reference:
核心目标
Core Objective
确保 LaTeX 渲染的 PDF 与 Word 版打印的 PDF 像素级对齐:
Ensure pixel-level alignment between the PDF rendered by LaTeX and the PDF printed from the Word version:
样式要素(必须完全一致)
Style Elements (Must Be Fully Consistent)
- 标题层级格式(一级、二级、三级、四级)
- ⚠️ 标题文字内容(每年度的 Word 模板标题可能不同)
- 字体(中文楷体 + 英文 Times New Roman)
- 字号(三号、四号、小四等)
- 颜色(MsBlue RGB 0,112,192)
- 间距(行距、段前段后、缩进)
- 列表样式(编号格式、缩进)
- 页面设置(边距、版心)
- Title hierarchy format (Level 1, 2, 3, 4)
- ⚠️ Title text content (Word template titles may vary each year)
- Font (Chinese KaiTi + English Times New Roman)
- Font size (Size 3, Size 4, Small Size 4, etc.)
- Color (MsBlue RGB 0,112,192)
- Spacing (line spacing, before/after paragraph spacing, indentation)
- List style (numbering format, indentation)
- Page settings (margins, text area)
⚠️ 关键 1:标题文字对齐
⚠️ Key 1: Title Text Alignment
- 标题的文字内容必须与 Word 完全相同
- 标题的编号格式必须与 Word 完全相同(如"1." vs "1.")
- 标点符号必须与 Word 完全相同(如全角/半角符号)
- 例如:Word 是"1. 项目的立项依据",LaTeX 必须完全一致
- Title text content must be exactly the same as Word
- Title numbering format must be exactly the same as Word (e.g., "1." vs "1.")
- Punctuation must be exactly the same as Word (e.g., full-width/half-width symbols)
- Example: If Word shows "1. Project Establishment Basis", LaTeX must be identical
⚠️ 关键 2:每行字数对齐
⚠️ Key 2: Line-by-Line Word Count Alignment
- 每行的字数必须与 Word 完全相同
- 换行位置必须与 Word 完全一致
- 这需要精确调整:字号、字间距、行距、段间距
- Word count per line must be exactly the same as Word
- Line break positions must be exactly the same as Word
- This requires precise adjustments: font size, character spacing, line spacing, paragraph spacing
执行模式(简述)
Execution Mode (Brief)
本技能采用“硬编码工具 + AI 决策”的混合模式:
- 脚本负责确定性工作(提取/对比/验证/落盘产物)
- AI 负责启发式决策(调哪个参数、调多少、是否回滚/继续迭代)
工作空间(产物默认落在 )与更多脚本细节见:
projects/{project}/.make_latex_model/skills/make_latex_model/docs/WORKFLOW.mdskills/make_latex_model/scripts/README.md
This skill adopts a hybrid mode of "hard-coded tools + AI decision-making":
- Scripts handle deterministic tasks (extraction/comparison/validation/output artifact storage)
- AI handles heuristic decision-making (which parameter to adjust, how much to adjust, whether to roll back/continue iteration)
Workspace (artifacts are stored in by default) and more script details can be found in:
projects/{project}/.make_latex_model/skills/make_latex_model/docs/WORKFLOW.mdskills/make_latex_model/scripts/README.md
触发条件
Trigger Conditions
用户在以下场景触发本技能:
- NSFC 发布了新的年度 Word 模板
- 当前 LaTeX 模板与 Word 模板存在明显样式差异
- 用户主动要求"对齐 Word 样式""更新模板格式"
Users trigger this skill in the following scenarios:
- NSFC releases a new annual Word template
- Obvious style differences exist between the current LaTeX template and the Word template
- Users actively request "align with Word style" or "update template format"
输入参数
Input Parameters
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| string | 是 | 项目名称(如 |
| string | 是 | Word 模板年份(如 |
| string | 否 | 优化级别: |
| boolean | 否 | 预览模式,不实际修改文件,默认 |
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Project name (e.g., |
| string | Yes | Word template year (e.g., |
| string | No | Optimization level: |
| boolean | No | Preview mode, no actual file modification, default is |
快速开始(推荐路径)
Quick Start (Recommended Path)
- 预检查:
bash
python3 skills/make_latex_model/scripts/check_state.py projects/{project}- 验证(脚本会解析 ,支持
--project或NSFC_Young):projects/NSFC_Young
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}- 需要精细对齐时,跑迭代闭环:
python3 skills/make_latex_model/scripts/enhanced_optimize.py --project projects/{project} --max-iterations 30 --report
- Pre-check:
bash
python3 skills/make_latex_model/scripts/check_state.py projects/{project}- Validation (the script parses , supports
--projectorNSFC_Young):projects/NSFC_Young
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}- For fine-grained alignment, run the iterative loop:
python3 skills/make_latex_model/scripts/enhanced_optimize.py --project projects/{project} --max-iterations 30 --report
迭代优化闭环
Iterative Optimization Loop
本步骤实现全自动的"优化-对比-调整"循环,推荐在需要精细调整时使用。
This step implements a fully automated "optimize-compare-adjust" cycle, recommended for fine-grained adjustments.
一键启动
One-click Startup
bash
undefinedbash
undefined全自动迭代优化
Fully automated iterative optimization
python3 skills/make_latex_model/scripts/enhanced_optimize.py
--project projects/NSFC_Young
--max-iterations 30
--report
--project projects/NSFC_Young
--max-iterations 30
--report
如需启用“Analyzer → Reasoner → Executor → Memory”的 AI 优化闭环(最小可用版),可加:
```bash
python3 skills/make_latex_model/scripts/enhanced_optimize.py \
--project projects/NSFC_Young \
--max-iterations 30 \
--ai --ai-mode heuristic说明:当前脚本内部默认使用启发式决策;如需“宿主 AI 全程参与”,使用(会生成--ai-mode manual_file,等待写入projects/<project>/.make_latex_model/iterations/iteration_XXX/ai_request.json后再继续)。ai_response.json
python3 skills/make_latex_model/scripts/enhanced_optimize.py
--project projects/NSFC_Young
--max-iterations 30
--report
--project projects/NSFC_Young
--max-iterations 30
--report
To enable the AI optimization loop of "Analyzer → Reasoner → Executor → Memory" (minimum viable version), add:
```bash
python3 skills/make_latex_model/scripts/enhanced_optimize.py \
--project projects/NSFC_Young \
--max-iterations 30 \
--ai --ai-mode heuristicNote: The script currently uses heuristic decision-making by default; for "host AI full participation", use(which generates--ai-mode manual_file, waiting forprojects/<project>/.make_latex_model/iterations/iteration_XXX/ai_request.jsonto be written before continuing).ai_response.json
收敛条件(优先级从高到低)
Convergence Conditions (Priority from High to Low)
| 条件 | 阈值 | 说明 |
|---|---|---|
| 编译失败 | - | 立即停止,需人工修复 |
| 像素差异收敛 | | 达到像素级对齐 |
| 连续无改善 | 5 轮 | 指标不再优化,收敛 |
| 最大迭代 | 30 轮 | 强制停止 |
| Condition | Threshold | Description |
|---|---|---|
| Compilation Failure | - | Stop immediately, manual repair required |
| Pixel Difference Convergence | | Achieve pixel-level alignment |
| No Continuous Improvement | 5 rounds | Metrics no longer optimize, convergence achieved |
| Maximum Iterations | 30 rounds | Force stop |
相关脚本
Related Scripts
| 脚本 | 功能 |
|---|---|
| 一键迭代优化入口 |
| 预处理/恢复 main.tex |
| 生成 Word PDF 基准 |
| 收敛检测与报告 |
| AI 优化器(单轮调试入口) |
| 智能参数调整建议(旧版启发式,作为回退路径保留) |
| Script | Function |
|---|---|
| One-click iterative optimization entry |
| Preprocess/restore main.tex |
| Generate Word PDF baseline |
| Convergence detection and reporting |
| AI optimizer (single-round debugging entry) |
| Intelligent parameter adjustment suggestions (legacy heuristic, retained as fallback path) |
输出规范
Output Specifications
修改记录(Single Source of Truth)
Modification Records (Single Source of Truth)
- 所有可追溯的变更历史记录在仓库根
CHANGELOG.md - 在 内只保留必要的解释性注释(不要维护版本历史)
@config.tex
- All traceable change history is recorded in the root of the repository
CHANGELOG.md - Only keep necessary explanatory comments in (do not maintain version history)
@config.tex
代码变更
Code Changes
- 对 进行精确修改,保留:
projects/{project}/extraTex/@config.tex- 原有注释
- 代码风格
- 条件判断结构(如 )
\ifwindows
- 允许改 的标题文本(只改花括号内文字,不动
projects/{project}/main.tex)\input{}
快速验证(推荐):
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}- Precisely modify , retaining:
projects/{project}/extraTex/@config.tex- Original comments
- Code style
- Conditional judgment structures (e.g., )
\ifwindows
- Allowed to modify title text in (only modify text in curly braces, do not touch
projects/{project}/main.tex)\input{}
Quick Validation (Recommended):
bash
cd skills/make_latex_model
./scripts/validate.sh --project projects/{project}核心原则(底线)
Core Principles (Bottom Line)
绝对禁区
Absolute Forbidden Areas
⚠️ 永不触碰 中的正文段落内容
main.tex- 中的
main.tex引用的正文内容文件\input{extraTex/*.tex} - 文件中的用户撰写内容
extraTex/*.tex - 正文段落、表格、图片、公式等内容
✅ 允许修改 中的标题文本
main.tex- 中的标题文字
\section{标题文字} - 中的标题文字
\subsection{标题文字} - 标题的编号格式、标点符号等
- 理由:标题的文本结构也是模板样式的一部分,需要与 Word 模板对齐
⚠️ 边界示例:
latex
% ✅ 允许修改:标题文字
\section{{\bfseries(一)立项依据与研究内容}(建议8000字以内):} % 修改为
\section{{\bfseries(一)研究依据与内容}(建议8000字以内):}
% ❌ 禁止修改:正文内容
\input{extraTex/1.1.立项依据.tex} % 不改变引用关系
% extraTex/1.1.立项依据.tex 中的具体内容不修改⚠️ Never touch main paragraph content in
main.tex- Main content files referenced by in
\input{extraTex/*.tex}main.tex - User-written content in files
extraTex/*.tex - Main paragraphs, tables, images, formulas, etc.
✅ Allowed to modify title text in
main.tex- Title text in
\section{Title Text} - Title text in
\subsection{Title Text} - Title numbering format, punctuation, etc.
- Reason: The text structure of titles is also part of the template style and needs to align with the Word template
⚠️ Boundary Example:
latex
% ✅ Allowed modification: title text
\section{{\bfseries(一)立项依据与研究内容}(建议8000字以内):} % Modified to
\section{{\bfseries(一)研究依据与内容}(建议8000字以内):}
% ❌ Forbidden modification: main content
\input{extraTex/1.1.立项依据.tex} % Do not change the reference relationship
% Do not modify the specific content in extraTex/1.1.立项依据.tex轻量级修改优先
Prioritize Lightweight Modifications
- ✅ 调整参数值(字号 pt 值、颜色 RGB 值、间距 em/cm 值)
- ✅ 新增自定义命令
- ❌ 删除或重命名现有命令
- ❌ 改变宏包加载顺序
- ❌ 重构条件判断结构
- ✅ Adjust parameter values (font size pt value, color RGB value, spacing em/cm value)
- ✅ Add custom commands
- ❌ Delete or rename existing commands
- ❌ Change package loading order
- ❌ Refactor conditional judgment structures
保真度与稳定性平衡
Balance Between Fidelity and Stability
- 过度开发的风险:引入 bug、破坏已有功能、增加维护成本
- 开发不足的风险:样式不一致、不符合基金委要求
- 平衡策略:
- 默认使用 级别
moderate - 仅在必要时使用 级别
thorough - 保留老样式的核心架构
- 默认使用
- Risk of over-development: Introduce bugs, break existing functions, increase maintenance costs
- Risk of under-development: Inconsistent styles, non-compliance with NSFC requirements
- Balance Strategy:
- Use level by default
moderate - Use level only when necessary
thorough - Retain the core architecture of the old style
- Use
跨平台兼容性
Cross-platform Compatibility
- 保留 条件判断
\ifwindows - 确保 Mac/Windows/Linux 都能正确编译
- 外挂字体路径保持不变()
./fonts/
- Retain conditional judgments
\ifwindows - Ensure correct compilation on Mac/Windows/Linux
- Keep external font paths unchanged ()
./fonts/
验收清单(按优先级)
Acceptance Checklist (By Priority)
- 基础编译:无错误
xelatex -> bibtex -> xelatex -> xelatex - 样式参数:行距/字号/颜色/边距在容忍度内(以 为准)
skills/make_latex_model/config.yaml - 标题文字:与 Word 模板完全一致(文本/标点/编号/加粗位置)
- 像素对比:仅作为辅助;基准必须来自 Word/LibreOffice(不要用 QuickLook)
- Basic compilation: without errors
xelatex -> bibtex -> xelatex -> xelatex - Style parameters: Line spacing/font size/color/margins within tolerance (based on )
skills/make_latex_model/config.yaml - Title text: Exactly consistent with Word template (text/punctuation/numbering/bold position)
- Pixel comparison: Only as auxiliary; baseline must come from Word/LibreOffice (do not use QuickLook)
FAQ
FAQ
见:
skills/make_latex_model/docs/FAQ.mdSee:
skills/make_latex_model/docs/FAQ.md