Paper write zh

From FOURTEEN1416/academic-agent-toolkit · View interactive version

Paper write zh is an AI agent skill from the GitHub repository FOURTEEN1416/academic-agent-toolkit. Draft a Chinese academic paper in LaTeX using XeLaTeX + ctex. Use when user says ”写中文论文”, ”中文LaTeX”, ”Chinese paper”。区别于 paper-write:本技能面向中文学位论文/中文期刊(ctex 本科/硕士/期刊三模板 + GB/T 7714),英文会议稿改用 paper-write;Word(docx) 输出改用 paper-write-zh-docx。

How to use this skill

Skill file

Chinese Paper LaTeX Writing

Draft a Chinese LaTeX paper section by section: $ARGUMENTS

Constants

Inputs

  1. PAPER_PLAN.md — outline with data analysis summary
  1. NARRATIVE_REPORT.md — research narrative
  1. figures/ — PDFs + latex_includes*.tex + tikz_diagrams.tex(TikZ,编译为 tikz_diagrams.pdf)
  1. user_data/ — user materials (.cls/.docx templates, data files)

If user_data/ has CSV/JSON, read exact values with pandas before writing experiment chapters.

Load shared rules


cat _utils/writing_rules.md 2>/dev/null || cat skills/shared-scripts/writing_rules.md

Template selection

Priority: user .cls > user .docx > built-in template

Built-in templates in templates/:

Copy template to paper/main.tex, replace all bracket placeholders with actual content.

Template handles fonts, spacing, margins, gbt7714, headers/footers — do not write main.tex from scratch.

⛔ 栏数(单栏/双栏) — 以 AGENTS.md 里的「栏数」指令为准(如有):

⛔ CRITICAL TEMPLATE RULES:

  1. NEVER rewrite main.tex from scratch — the template has carefully tuned preamble
  1. NEVER replace \listoftables/\listoffigures with hand-written text — use auto-generated lists
  1. Only replace bracket placeholders ([论文标题], [作者], etc.) with actual content
  1. Only modify \input{sections/...} lines to match actual section filenames

<abstract_format>

Abstract format

The template uses manual typesetting for abstracts (\begin{center}{\heiti 摘要}\end{center} + \begin{center}{\bfseries Abstract}\end{center}). Do not use two \begin{abstract} environments — ctexart's abstract title is fixed as "摘要", so the English abstract would also show a Chinese title.

Chinese abstract: 500-700 characters. Aim to fill most of one page but leave 3-4 lines margin at the bottom — overflowing onto a second page looks worse than being slightly short. Content chain: 研究背景与意义 → 现有方法不足 → 本文方法 → 数据来源与处理 → 关键数值结果(精度、R²、p值等)→ 应用价值与建议.

English abstract: 350-500 words, faithful translation covering the same structure and all numerical results. Same principle — fit on one page, do not overflow.

</abstract_format>

完成铁律(产出契约)

根据 params.output_format 决定主产物路径(AGENTS.md 含「Word(.docx)」即 docx 模式,否则 PDF):

产出结构、存在性与最低完整性由 finish 按模板 output_contract 自动核验(引擎检查 paper_write_gate,finish 自动跑;交付档 blocking——未过不得 finish,探索档 advisory 留痕;单跑 cd academic-toolkit && python engine/quality_gates.py gate <工作区> --check paper_write_gate),按返回的 fix_hint 补全产出,不自行复制验证脚本。

执行与产出

使用当前执行会话完成本步工作;产物路径按当前步骤合同。程序采集真实操作、输入输出、版本与运行清单,模型只负责实质成果和领域质量。

建议额外记录:模板来源哈希、BibTeX 条目数、引用格式。

Workflow

Step 0: Backup + resume check + 上游验证

上游输出预检(写论文前必做):

上游各步的产物已由各自的 output_contract / figure_provenance 在 finish 时核验;写稿前仍按此清单确认,缺件不要凭记忆补:

文件过小或缺失时继续执行,但结果可能欠佳——按上面的缺件项回溯上游,不要在写稿步伪造上游产物。

Back up existing paper/ to paper-backup-{timestamp}/;章节是否完成由引擎 paper_write_gate 按「每章 ≥500 字符」判定(finish 自动跑),据此决定续写还是跳过。

Resume: only write placeholder sections (<500 chars or contains "待补充"/"placeholder"), skip completed ones (>2000 chars). See <resume_strategy> in writing_rules.md for full details.

⛔ 数值来源规则(全文遵守):

所有论文中的数值(精度、RMSE、R²、p-value、系数、训练时间等)必须来自 figures/all_results.json 或 RESULTS.md。

⛔ 禁止 cat figures/*_results.json。 这些结果文件可能含全精度时序数组(可达数十 MB / 数十万行),整读会撑爆上下文——本地大模型直接失败、经中转的 GPT 因协议翻译超长反复 api_retry 卡死。论文正文只用标量数值(精度/RMSE/R²/p 值/系数/训练时间等),巨型数组是给图表用的、不进正文。 写任何含数值的章节之前,用下面的 summarize 脚本拿 KB 级摘要(标量原样显示、精度零损失,只把大数组压成「长度+范围+前3样本」):


[ -f RESULTS.md ] && cat RESULTS.md

python3 - <<'PY'

import json, os, glob

def summarize(v, depth=0):

    if isinstance(v, list):

        n=len(v); nums=[x for x in v if isinstance(x,(int,float))]

        if nums: return f'list[{n}] range=[{min(nums):.4g},{max(nums):.4g}] sample={v[:3]}'

        if v and isinstance(v[0], (list,dict)): return f'list[{n}] of {type(v[0]).__name__}, first_shape={len(v[0]) if hasattr(v[0],"__len__") else "?"}'

        return f'list[{n}] sample={str(v[:3])[:80]}'

    if isinstance(v, dict) and depth<2:

        return 'dict{'+', '.join(f'{k}: {summarize(x,depth+1)}' for k,x in list(v.items())[:6])+'}'

    return f'{type(v).__name__}={str(v)[:60]}'

for f in sorted(glob.glob('figures/*_results.json')):

    sz=os.path.getsize(f); d=json.load(open(f,encoding='utf-8'))

    print(f'\n=== {os.path.basename(f)} ({sz//1024}KB) ===')

    if isinstance(d, dict):

        for k,v in d.items(): print(f'  {k}: {summarize(v)}')

    else: print(f'  {summarize(d)}')

PY

论文要引的标量都在 RESULTS.md 和上面摘要的 range/sample 里;若某个标量摘要没显示全,用 python3 -c "import json;d=json.load(open('figures/all_results.json'));print(d['键名'])" 定点取那一个值,仍然不要整读。原样复制数字填入论文,不要凭记忆估算、四舍五入或编造数值。最终的 quality gate 会做数值一致性检查,编造的数字会被发现。

⛔ Claims-Evidence 对照(必须严格遵循规划):

写每个章节前,先重读 PAPER_PLAN.md 中的 claims-evidence 矩阵:


grep -A 100 'Claims-Evidence\|claim.*evidence\|claim-evidence\|观点.*证据' PAPER_PLAN.md 2>/dev/null | head -30

写作纪律:

如果某个规划中的论断在数据中找不到证据,诚实写"初步结果提示 X,更严谨的验证留待未来工作",不要编造证据。

Step 1: Initialize

Create paper/, copy template to main.tex, generate math_commands.tex (paper-specific commands only — do not redefine \sin, \cos, \log, etc.).

Step 2: Figure inventory

Before writing any section, build a complete inventory of available figures. This prevents empty figure environments (caption without image).


echo "=== Available PDF figures ==="

ls -la figures/*.pdf 2>/dev/null || echo "No PDF figures found"

echo ""

echo "=== Available table files (PDF模式: .tex / Word模式: .md) ==="

ls -la figures/TABLE_*.tex figures/TABLE_*.md 2>/dev/null || echo "No TABLE files found"

echo ""

echo "=== TikZ 几何/算法/架构图 ==="

# TikZ 图由 paper-figure-drawio 生成为 figures/tikz_diagrams.tex → 编译成 figures/tikz_diagrams.pdf

# (历史命名可能是 tikz_architecture_examples.tex,一并兼容)。TikZ 的 PDF 已被写进 latex_includes.tex。

ls -la figures/tikz_*.pdf figures/tikz_*.tex 2>/dev/null || echo "No TikZ diagrams"

grep -l 'tikz_' figures/latex_includes.tex >/dev/null 2>&1 && echo "→ TikZ 已在 latex_includes.tex 中,按其图块嵌入对应章节" || true

echo ""

echo "=== latex_includes.tex content (figure→PDF mapping) ==="

cat figures/latex_includes.tex 2>/dev/null || echo "No latex_includes.tex"

From the output above, build a mapping table: figure label → PDF filename → target section. Only embed figures whose PDF files actually exist — do not create figure environments for PDFs that don't exist (this causes empty figures with just a caption and no image).

⛔ TikZ 图(如 figures/tikz_diagrams.pdf / figures/tikz_*.pdf)必须嵌入论文。 它们已在 latex_includes.tex 中有对应 \includegraphics 图块,按几何/算法/架构图的章节归属嵌入(几何示意图→对应子问题章节,算法流程图→模型建立章节)。禁止漏掉任何 tikz_*.pdf。

⛔ 中文论文的图表 caption 必须是中文。 如果 latex_includes.tex 里的 caption 是英文,嵌入时必须翻译成中文。例如:\caption{Model Performance Comparison} → \caption{模型性能对比}。

Also scan figures/*.tex for all \begin{figure} / \begin{table} blocks with their \label{}. After writing, verify all embedded:


grep -oh '\\label{[^}]*}' figures/*.tex 2>/dev/null | sort -u > _all_fig_labels.txt

grep -oh '\\label{[^}]*}' paper/sections/*.tex paper/main.tex 2>/dev/null | sort -u > _embedded_labels.txt

comm -23 _all_fig_labels.txt _embedded_labels.txt  # should be empty

Step 2.5: 文献预检索(写正文之前必须完成)

⛔ 在写任何 \cite{} 之前,必须先建立已验证的文献池。

目的:先搜索到真实存在的论文,写正文时只引用池子里的论文,避免编造不存在的文献。


PYTHON=""; for _c in "$MH_PYTHON" python python3; do [ -z "$_c" ] && continue; if $_c -c "import sys" >/dev/null 2>&1; then PYTHON="$_c"; break; fi; done; [ -z "$PYTHON" ] && PYTHON=python

mkdir -p _tmp



# 根据论文的关键主题领域搜索真实论文

# (根据你的具体选题调整搜索词)

# 示例:

#   $PYTHON "$SCHOLAR_SCRIPT" bibtex "空间杜宾模型 数字经济" --max 5

#   $PYTHON "$SCHOLAR_SCRIPT" bibtex "算力基础设施 区域发展" --max 5

搜索后,创建 _tmp/_verified_refs.txt,每行一篇已验证论文:


key: lesage_2009_spatial | title: Introduction to Spatial Econometrics | authors: LeSage, Pace | year: 2009 | match: good

写正文时只能引用这个池子里的论文。 如果需要引用池子外的论文,先搜索验证后再加入池子。

兜底:如果 scholar_fetch.py 搜不到或 match_label="low",用 WebSearch 在 Google Scholar / Semantic Scholar 网站上搜索,手动核实标题+作者+年份后再加入池子。

Step 3: Write each section

⛔ CRITICAL: Do NOT write the abstract now. 跳过摘要章节,先写正文。摘要位置先写占位符 % [摘要待 Step 4.5 正文完成后填写]。摘要必须最后写,因为要从各章节摘取具体数值——先写就是凭印象编数字。

Step 4.5 才回来填摘要:到时候读 RESULTS.md / experiment_results.md / figures/all_results.json 和所有 sections/*.tex,提取实测数值后写摘要。

Writing order: method/core → experiments → introduction → related work → conclusion.

Save each section immediately. If approaching output limit, create % [PLACEHOLDER] files for remaining sections.

⛔ 写实验/结果章节前,必须先读 experiment_results.md / RESULTS.md / figures/*.json 获取精确数值。 不要凭记忆编造结果——所有数值(精度、R²、p 值、系数等)必须从数据文件中提取。

⛔ 写作风格铁律:

Follow all rules from _utils/writing_rules.md (interleaving, embedding, LaTeX constraints, page filling, resume strategy).

⛔ 跨章上下文 + 图数据绑定(防"两张皮"):

⛔ 图文并茂硬规则(每个章节都必须遵守):

After each section, check chars:


chars=$(wc -c < "paper/sections/当前章节.tex")

echo "当前章节: $chars 字符"

# Chinese LaTeX ≈ 800-1000 chars/page

# If chapter page budget in PAPER_PLAN.md is 5 pages but only 2000 chars (~2.5 pages), expand immediately

<exemplar_depth>

Writing depth by paper type

本科毕业论文 (30 pages, 5 chapters):

硕士论文 — CS/AI (80 pages, 6 chapters):

硕士论文 — 经管/统计 (80 pages):

期刊论文 (15 pages, 5-6 sections):

| Type | Pages | Characters | References |

|------|-------|-----------|------------|

| 本科 (30p) | 25-30 | 10000-15000 | ≥20 |

| 硕士 (80p) | 50-60 | 30000-50000 | ≥50 |

| 期刊 (15p) | 12-15 | 6000-8000 | ≥30 |

</exemplar_depth>

Per-section minimum figures/citations

Core result tables (主结果对比表, 消融实验表) and key analysis figures belong in the body, not appendix. Appendix only: code, very long auxiliary tables, extra experiment details.

Expansion strategies (not padding — substantive content):

Figure usage principle

"字不如表,表不如图" — but figures only where data needs visualization (data description, experiment results). Do not force figures into pure literature review or theoretical derivation. 执行 Agent decides figure count and placement based on content needs.

Step 4: Build references

Follow the <references_workflow> in _utils/writing_rules.md.

gbt7714 package handles bibliographystyle — only need \bibliography{references}.

Verify references.bib is non-empty before proceeding to next step.

⛔ 使用 scholar_fetch.py 工具获取所有参考文献的 BibTeX。禁止凭记忆编造 BibTeX。

⛔ 引用写法规则:写正文时,citation key 必须包含描述性关键词,格式为 作者姓_年份_主题关键词。

例如:\cite{wang_2023_supply_chain_resilience} 而不是 \cite{wang2023supply}。

这样搜索时能用关键词找到正确的论文。如果不确定作者/年份,用 TODO__ 前缀:\cite{TODO__digital_economy_spatial_spillover}。


# Step 4a: 收集所有引用 key 并提取搜索关键词

grep -roh '\\cite[tp]*{[^}]*}' paper/sections/*.tex paper/main.tex 2>/dev/null \

  | grep -oP '\{[^}]+\}' | tr -d '{}' | tr ',' '\n' | sed 's/^ *//;s/ *$//' | sort -u > _tmp/_cited_keys.txt

echo "引用 key 数量: $(wc -l < _tmp/_cited_keys.txt)"

cat _tmp/_cited_keys.txt



# Step 4b: 逐个搜索并获取 BibTeX(用描述性关键词搜索)

PYTHON=""; for _c in "$MH_PYTHON" python python3; do [ -z "$_c" ] && continue; if $_c -c "import sys" >/dev/null 2>&1; then PYTHON="$_c"; break; fi; done; [ -z "$PYTHON" ] && PYTHON=python

while IFS= read -r key; do

    # 将 citation key 转为搜索词:去掉 TODO__ 前缀,下划线替换为空格

    query=$(echo "$key" | sed 's/^TODO__//; s/_/ /g')

    echo "--- 获取: $key (搜索: $query) ---"

    $PYTHON "$SCHOLAR_SCRIPT" bibtex "$query" --max 3

    sleep 0.5

done < _tmp/_cited_keys.txt

处理每个搜索结果:

  1. 检查 match_label:"good" → 直接使用。"partial" → 核实标题是否匹配你的引用意图。"low" → 很可能搜错了,换更好的关键词重新搜索或用 WebSearch。
  1. 检查 match_score:分数 < 0.3 说明搜索结果大概率不是你想引用的论文,不要盲目使用。
  1. 选择正确的论文,将其 bibtex 字段复制到 paper/references.bib。
  1. 将 .tex 文件中的 citation key 替换为 BibTeX 条目中的实际 key。
  1. 如果 bibtex_source=auto,在条目上方加 % [VERIFY]。
  1. 如果 match_label="low" 且找不到更好的结果,加 % [LOW_MATCH - 请核实是否为目标论文],并用 WebSearch 兜底。

Step 5: De-AI polish

See <de_ai_polish> in _utils/writing_rules.md.

Step 5.5: 最后写摘要 ⛔

⛔ MANDATORY: 现在才写摘要(替换 Step 3 留的占位符)。

先读 RESULTS.md / experiment_results.md / figures/all_results.json 和所有 sections/*.tex 文件,提取实测数值(准确率、F1、p 值、系数等)。然后用这些已验证的数字写摘要,不要编造任何数值。

结构:研究背景 → 现有方法不足 → 本文方法 → 数据来源 → 关键数值结果 → 应用价值。中文摘要 500-700 字,英文摘要 350-500 词,填满一页但留 3-4 行底部空白(宁短勿溢)。

摘要里每个数字必须在正文中出现(引擎 paper_write_gate 核验摘要数字溯源,finish 自动跑)。

Step 6: Cross-review

Send draft to external reviewer for feedback:


mkdir -p _tmp

cat << 'REVIEW_EOF' > _tmp/_review_prompt.txt

请评审这篇中文学术论文草稿。重点关注:

1. 逻辑流畅性和论证结构

2. 论点-证据对齐(每个论点是否有数据支撑?)

3. 写作清晰度和简洁性

4. 缺失内容或薄弱章节

5. 评分(1-10)和最需要改进的 3 个方面



## 论文各章节:

REVIEW_EOF

for f in paper/sections/*.tex; do

    [ -f "$f" ] && echo "### $(basename $f)" >> _tmp/_review_prompt.txt && cat "$f" >> _tmp/_review_prompt.txt

done

PYTHON=""; for _c in "$MH_PYTHON" python python3; do [ -z "$_c" ] && continue; if $_c -c "import sys" >/dev/null 2>&1; then PYTHON="$_c"; break; fi; done; [ -z "$PYTHON" ] && PYTHON=python

$PYTHON "$REVIEWER_SCRIPT" --prompt-file _tmp/_review_prompt.txt --thread-file _tmp/_reviewer_thread.json 2>&1 | tee _tmp/_cross_review.txt

If reviewer script unavailable, skip this step.

Step 7: Final verification


bash _utils/writing_check.sh paper/ 2>/dev/null || bash skills/shared-scripts/writing_check.sh paper/

字符数、paper/references.bib、估算页数与图表对账的机器判据由引擎承接,finish 自动跑(单跑 cd academic-toolkit && python engine/quality_gates.py gate <工作区> --check paper_write_gate,图表对账项把 --check 的值换成 figure_plan_reconciliation):每章 ≥ 500 字符、配了 MAX_PAGES 时估算页数不低于目标 80%、规划清单每张图要有产物文件 + 可编辑源(.drawio/.tex)+ 正文引用(missing_files / missing_sources / unembedded 三类缺口逐项补到 0);未达标的扩充最薄章节。

不在上述检查器覆盖范围、仍需人工核实:模板括号占位符([论文标题]、[作者] 等)全部替换;章节文件不出现 \input{../figures/...}(图表走 figures/latex_includes.tex 图块);无 FIGURE_MANIFEST 时确认 figures/ 每张 PDF 与 \label{} 都已落到正文。

页数口径:⛔ MAX_PAGES 指正文页数(章节 1 - 结论,含图表)— 不含 摘要 / 目录 / 参考文献 / 附录代码;统计面只有 paper/sections/*.tex,附录代码归 paper/appendix/*.tex。正文估算页数(字符数 ÷ 900)与「正文含代码块」同样由 paper_write_gate 承接(finish 自动跑,单跑同上、--check paper_write_gate);估算页数低于 MAX_PAGES 80% 时扩充最薄章节,不要把代码挪进正文凑页数。

⛔ 正文 vs 附录归档约束:

Key Rules


FIGURE_MANIFEST 对账(规划了几张就必须嵌入几张)

规划清单藏在 PROBLEM_ANALYSIS.md / PAPER_PLAN.md / MODELING_REPORT.md / TOPIC_PLAN.md 任一文件的 <!-- BEGIN FIGURE_MANIFEST --> 与 <!-- END FIGURE_MANIFEST --> 之间,每行一张图。清单里的每张图都要三对齐:

三类缺口分别对应 missing_files / missing_sources / unembedded。缺哪类补哪类;靠删清单条目「过关」等于丢掉规划过的图。

对账由引擎 figure_plan_reconciliation 承接(finish 自动跑;单跑 cd academic-toolkit && python engine/quality_gates.py gate <工作区> --check figure_plan_reconciliation),fix_hint 即三类缺口的修复口径。

⛔ 通用 paper-stage 审计(所有写稿步骤共用,跨工作流)

写完正文 / 编译前必须跑一次通用审计,独立于 PROBLEM_FACTS.json 是否存在:


# 通用 paper 审计:[13] 正文结论与 results.json 一致(防"最优解 X 但正文写 Y");

# [14] 事件源归属(防"凭变量名脑补撞击 / 命中 / 拦截")。

# 即使没 PROBLEM_FACTS.json(普通学术 / 课程论文 / 人文社科),也会以"简化模式"跑独立审计。

# 审计已并入共享脚本 paper_write_audit.sh(_utils/ 与 shared-scripts/ 双副本),同时执行 figure embedding check 与 FIGURE_MANIFEST audit:

bash _utils/paper_write_audit.sh --mode latex   # 本目录无 _utils 时: bash skills/shared-scripts/paper_write_audit.sh --mode latex

# 审计输出由程序采集留痕,不再写入手写审计文件;有引擎 finish 时以 output_contract/paper_write_gate 自动核验为准。

怎么读结果:输出 ❌ / MISSING: / ⛔ 即有缺件、图未嵌入或正文与 results.json 不一致——按提示修正后重跑至无 ❌。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.