| name | comp-paper-en |
| description | Mathematical modeling competition paper writing in English (MCM/ICM/APMCM). Generate complete LaTeX paper following COMAP format. Use when user says "write MCM paper", "美赛论文", "English competition paper". |
| argument-hint | ["competition-type"] |
| allowed-tools | Bash(*), Read, Write, Edit, Grep, Glob, Agent, WebSearch, WebFetch |
Competition Paper Writing (English)
Write a competition paper: $ARGUMENTS
Constants
Inputs
-
PROBLEM_ANALYSIS.md, MODELING_REPORT.md, RESULTS.md
-
figures/, code/
Load shared rules
cat _utils/writing_rules.md 2>/dev/null || cat skills/shared-scripts/writing_rules.md
MCM/ICM Paper Structure
Summary Sheet (1 page — most important page in the entire paper)
Table of Contents
1. Introduction (1-2 pages)
2. Assumptions and Justifications (0.5 page)
3. Notations (0.5 page)
4. Model Design and Solution (per sub-problem, 4-5 pages each)
5. Sensitivity Analysis (1-2 pages)
6. Model Evaluation (Strengths + Weaknesses)
7. Conclusions (0.5 page)
References
Appendix A: Code
Workflow
Step 0: Backup + resume check
Back up existing paper/. Check for incomplete sections:
echo "=== Resume check ==="
if [ -d "paper/sections" ]; then
for f in paper/sections/*.tex; do
[ -f "$f" ] || continue
chars=$(wc -c < "$f")
[ "$chars" -lt 500 ] && echo "⚠ Placeholder: $(basename $f) ($chars chars)" || echo "✅ Complete: $(basename $f) ($chars chars)"
done
fi
Resume: only write placeholder sections, skip completed ones (>2000 chars). Save each section immediately. If approaching output limit, create % [PLACEHOLDER] files.
Step 1: Select template
mkdir -p paper/sections
TMPL_BASE="_templates"
[ -d "$TMPL_BASE" ] || TMPL_BASE="templates"
if echo "$ARGUMENTS" | grep -qi "mcm\|MCM\|ICM" || grep -qi "mcm\|MCM" CLAUDE.md 2>/dev/null; then
echo "Using MCM template"
cp "$TMPL_BASE/mcm/"* paper/ 2>/dev/null
elif echo "$ARGUMENTS" | grep -qi "apmcm\|APMCM\|亚太" || grep -qi "apmcm" CLAUDE.md 2>/dev/null; then
echo "Using APMCM template"
cp "$TMPL_BASE/apmcm/"* paper/ 2>/dev/null
else
echo "Using default English template"
cp "$TMPL_BASE/default/"* paper/ 2>/dev/null
fi
[ -f paper/main.tex ] && echo "Template copied: $(wc -l < paper/main.tex) lines" || echo "ERROR: template not found!"
MCM/ICM uses mcmthesis.cls (included in template folder). APMCM uses article class.
⛔ Do not write main.tex from scratch — copy the template and only replace placeholders. The template handles fonts, margins, headers, and formatting.
Step 2: Figure inventory
Before writing any section, build a complete inventory of available figures:
echo "=== Available PDF figures ==="
ls -la figures/*.pdf 2>/dev/null || echo "No PDF figures found"
echo ""
echo "=== Available LaTeX table files ==="
ls -la figures/TABLE_*.tex 2>/dev/null || echo "No TABLE files found"
echo ""
echo "=== latex_includes.tex content (figure→PDF mapping) ==="
cat figures/latex_includes.tex 2>/dev/null || echo "No latex_includes.tex"
echo ""
echo "=== TikZ architecture diagrams ==="
[ -s figures/tikz_architecture_examples.tex ] && echo "YES — must embed" || echo "No TikZ diagrams"
⛔ MANDATORY: Build a FIGURE EMBEDDING PLAN before writing any section:
FIGURE EMBEDDING PLAN:
1. fig_p1_result.pdf → Problem 1 section → caption: "Figure X: ..."
2. fig_p2_result.pdf → Problem 2 section → caption: "Figure X: ..."
3. TABLE_comparison.tex → Results section → caption: "Table X: ..."
4. tikz_problem_relation (from tikz_architecture_examples.tex) → Introduction
Rules:
-
⛔ Must use figure blocks from latex_includes.tex, not write \includegraphics from scratch
-
⛔ TikZ diagrams must be embedded: copy from figures/tikz_architecture_examples.tex into sections
-
⛔ Image paths must be ../figures/xxx.pdf
-
Only embed figures whose PDF files actually exist
⛔⛔⛔ DrawIO figure embedding (most commonly missed — check each one):
DrawIO figures (roadmap, flow charts, pipeline diagrams) are appended at the end of latex_includes.tex by the paper-figure-drawio step. You MUST embed them:
| DrawIO figure type | Embed location | Section file |
|-------------------|---------------|-------------|
| Technical roadmap (fig_roadmap) | End of Introduction/Problem Restatement | 1_introduction.tex |
| Sub-problem flow chart (fig_flow_q1/q2/q3) | Inside each sub-problem's "Model Construction" subsection, preceded by 2-3 sentences introducing the solving approach and main steps | 4_problem1.tex, 5_problem2.tex etc. |
| Data pipeline (fig_pipeline) | Data preprocessing section | Data/method section |
| Model architecture (tikz_*) | Corresponding model's "Model Construction" subsection | Model section |
After writing all sections, verify DrawIO/TikZ figures are embedded:
echo "=== DrawIO/TikZ embedding check ==="
for pdf in figures/fig_roadmap.pdf figures/fig_flow_*.pdf figures/fig_pipeline*.pdf figures/fig_framework*.pdf; do
[ -f "$pdf" ] || continue
bn=$(basename "$pdf")
grep -rq "$bn" paper/sections/*.tex paper/main.tex 2>/dev/null && echo "✅ $bn embedded" || echo "❌ $bn NOT embedded — fix now!"
done
if [ -s figures/tikz_architecture_examples.tex ]; then
for lbl in $(grep -oh '\\label{[^}]*}' figures/tikz_architecture_examples.tex 2>/dev/null); do
grep -rq "$lbl" paper/sections/*.tex 2>/dev/null && echo "✅ TikZ $lbl embedded" || echo "❌ TikZ $lbl NOT embedded — fix now!"
done
fi
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 > _tmp/all_fig_labels.txt
grep -oh '\\label{[^}]*}' paper/sections/*.tex paper/main.tex 2>/dev/null | sort -u > _tmp/embedded_labels.txt
comm -23 _tmp/all_fig_labels.txt _tmp/embedded_labels.txt
Follow interleaving and embedding rules from _utils/writing_rules.md.
⛔ Figure-text interleaving hard rules (every section must follow):
-
All \begin{figure} must use [H], never [htbp]
-
Every figure/table must be followed by ≥5 lines of analysis text (data interpretation + comparison + conclusion) before the next figure
-
Absolutely no consecutive figures/tables without analysis paragraphs between them
-
Use \includegraphics[width=0.85\textwidth,height=0.38\textheight,keepaspectratio]
Step 2.5: Pre-fetch verified reference pool
⛔ MUST complete before writing any \citep{} in Step 3.
PYTHON=$(command -v python3 2>/dev/null || command -v python 2>/dev/null)
mkdir -p _tmp
Create _tmp/_verified_refs.txt with verified papers. Only cite papers from this pool when writing. Search and verify before adding new citations.
Fallback: If scholar_fetch.py returns no results or match_label="low" for a topic, use WebSearch to find the paper on Google Scholar / Semantic Scholar website, then manually verify title + authors + year before adding to the pool.
Step 3: Write each section
⛔ MCM/ICM chapter order (must follow template):
1_introduction.tex — Problem background + restatement + approach overview
2_assumptions.tex — Assumptions and justifications
3_symbols.tex — Notation table (use non-floating table: \begin{center}\begin{tabular}, NOT \begin{table})
4_model.tex — Model development (or split per sub-problem)
5_results.tex — Results and analysis
6_sensitivity.tex — Sensitivity analysis
7_strengths.tex — Strengths and weaknesses
A_code.tex — Appendix: code
File names must match template \input{sections/...} lines.
⛔ Before writing each section, read MODELING_REPORT.md and RESULTS.md for exact numbers and formulas.
⛔ No \begin{itemize} or \begin{enumerate} in body text — use flowing prose. Inline numbering "(1)...(2)..." is acceptable.
<exemplar_depth>
Writing depth reference
MCM/ICM Outstanding Paper (25 pages total, including everything):
-
Summary Sheet (1p): 300-400 words, self-contained with specific numerical results. Structure: problem statement (1-2 sentences) → method (2-3 sentences) → key results (3-4 sentences with numbers) → conclusion (1-2 sentences)
-
Introduction (2p): problem context + literature + approach overview
-
Assumptions (0.5p): each assumption with justification (not just a bullet list)
-
Notations (0.5p): use non-floating table (\begin{center}\begin{tabular} + \captionof{table}{}, NOT \begin{table}). This prevents the section title and table from being split across pages. Keep to 15-20 symbols max.
-
Each sub-problem (4-5p): model formulation (1.5p, with derivation) + solution method (1p, with algorithm) + results with table+figure+numbers (1p) + analysis (0.5-1p, interpretation + comparison)
-
Sensitivity Analysis (2-3p): ≥2 key parameters, each with variation plot + analysis paragraph
-
Model Evaluation (1.5p): 3-5 strengths + 2-3 weaknesses (honest, not token weaknesses) + generalization discussion
-
References + Appendix (3-4p)
APMCM First Prize (25-30 pages): similar but can be longer, 5-6 pages per sub-problem with more detailed analysis.
</exemplar_depth>
After each chapter, check chars:
chars=$(wc -c < "paper/sections/current_chapter.tex")
echo "Current chapter: $chars chars"
Expansion strategies (not padding — substantive content):
-
Formula without derivation → add step-by-step derivation with physical meaning
-
Result with only "as shown in Table X" → add 2-3 paragraphs (what numbers mean, comparison with expectations, why this result makes sense)
-
Algorithm as pseudocode only → add explanation of key steps, complexity analysis, convergence discussion
Summary Sheet is the most important page — invest the most effort here. Must be self-contained, one page, ≥300 words, with quantitative results.
Each sub-problem chapter: model formulation → solution method → results (table + figure + numbers) → result analysis (2-3 paragraphs of interpretation)
Sensitivity Analysis: parameter sensitivity + robustness + error analysis
Model Evaluation: Strengths 3-5 points + Weaknesses 2-3 points (honest) — do not write token weaknesses like "limited by time"
Step 4: Build bibliography
Follow the <references_workflow> in _utils/writing_rules.md.
Search DBLP/CrossRef for real BibTeX. \usepackage[hidelinks]{hyperref}.
⛔ Use scholar_fetch.py for ALL reference retrieval. NEVER fabricate BibTeX from memory.
⛔ Citation key rule: when writing body text, citation keys MUST contain descriptive keywords, format: author_year_topic_keywords.
Example: \citep{wang_2023_supply_chain_resilience} not \citep{wang2023supply}.
If unsure about author/year, use TODO__ prefix: \citep{TODO__digital_economy_spatial_spillover}.
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 "Cited keys: $(wc -l < _tmp/_cited_keys.txt)"
PYTHON=$(command -v python3 2>/dev/null || command -v python 2>/dev/null)
while IFS= read -r key; do
query=$(echo "$key" | sed 's/^TODO__//; s/_/ /g')
echo "--- Fetching: $key (query: $query) ---"
$PYTHON "$SCHOLAR_SCRIPT" bibtex "$query" --max 3
sleep 0.5
done < _tmp/_cited_keys.txt
For each result:
-
Check match_label: "good" → use directly. "partial" → verify title. "low" → likely wrong paper, re-search or use WebSearch.
-
match_score < 0.3 means the result probably doesn't match your citation intent. Do NOT blindly use it.
-
Replace citation keys in .tex files with actual keys from BibTeX entries.
-
Mark bibtex_source=auto with % [VERIFY]. Mark match_label="low" with % [LOW_MATCH].
Step 4.5: De-AI polish
See <de_ai_polish> in _utils/writing_rules.md.
Step 5: Final verification
bash _utils/writing_check.sh paper/ 2>/dev/null || bash skills/shared-scripts/writing_check.sh paper/
Also check:
echo "=== Section character counts ==="
total=0
for f in paper/sections/*.tex; do
chars=$(wc -c < "$f")
total=$((total + chars))
echo " $(basename $f): $chars chars (~$(echo "scale=1; $chars/2200" | bc) pages)"
done
echo " Total: $total chars (~$(echo "scale=1; $total/2200" | bc) pages)"
-
Total chars ≥ MAX_PAGES × 1800 (expand thinnest chapters if not)
-
Any sub-problem chapter <8000 chars (~4 pages) needs expansion
-
Summary Sheet exists (MCM/ICM critical)
-
All figures/.pdf and TABLE_.tex referenced in sections
-
No \input{figures} patterns
-
Team Control Number placeholder present
⛔ Page count pre-check (MUST pass before finishing):
total_chars=0
for f in paper/sections/*.tex; do
[ -f "$f" ] || continue
chars=$(wc -c < "$f")
total_chars=$((total_chars + chars))
done
est_pages=$((total_chars / 2200))
echo "Total chars: $total_chars, Est pages: ~$est_pages, Target: ≥ MAX_PAGES"
If estimated pages < 80% of MAX_PAGES, expand the thinnest chapters before finishing.
⛔ Figure embedding verification (must pass before finishing):
echo "=== Figure embedding check ==="
missing=0
for pdf in figures/*.pdf; do
[ -f "$pdf" ] || continue
bn=$(basename "$pdf")
if ! grep -rq "$bn" paper/sections/*.tex paper/main.tex 2>/dev/null; then
echo "MISSING: $bn not embedded in any section"
missing=$((missing + 1))
fi
done
echo "Missing: $missing"
⛔ Do NOT proceed to Step 6 until missing = 0.
Step 6: Compliance check
Page count, Summary Sheet, Team Control Number, anonymous, APMCM commitment letter not in PDF, code appendix.
Key Rules
-
Summary Sheet is everything — invest the most effort here
-
Specific numbers — never say "good results", give exact values
-
Figure paths: ../figures/xxx.pdf
-
[H] float specifier, not [htbp]
-
Wide tables (≥6 cols): wrap with \resizebox{\textwidth}{!}{...}
-
Narrow tables (≤4 cols): do not use \resizebox
-
Code appendix: complete runnable code
-
No team info — use placeholders
-
\usepackage[hidelinks]{hyperref}
-
Primary output: paper/ directory, temp files: _tmp/
-
⛔ This step only writes paper .tex files. Do NOT regenerate figure PDFs, modify code/*.py, or re-run analysis scripts. Figures and data are already produced by prior steps (paper-figure / comp-code) — just reference them
-
Large files: Bash heredoc