/paper-draft
Draft a complete LaTeX paper from the PAPER_PLAN.md generated by /paper-plan.
Write section by section: each section draws material from wiki claims/experiments/papers/concepts,
generates LaTeX + figures + tables. BibTeX is fetched from DBLP/CrossRef (following citation-verification).
Apply de-AI polish after completion (following academic-writing).
Optional per-section Review LLM review. Output a compilable paper/ directory.
Inputs
plan: path to PAPER_PLAN.md (e.g. wiki/outputs/paper-plan-sparse-lora-2026-04-08.md)
--review (optional): enable per-section Review LLM review
--sections (optional): write only specified sections (e.g. --sections 3,4 writes only Method + Experiments); used for incremental writing
Outputs
paper/ directory (under the wiki project root):
paper/main.tex — master file (includes each section)
paper/sections/introduction.tex
paper/sections/related_work.tex
paper/sections/method.tex
paper/sections/experiments.tex
paper/sections/conclusion.tex
paper/sections/appendix.tex (if applicable)
paper/figures/ — generated figures (PDF/PNG)
paper/tables/ — standalone table files (optional)
paper/math_commands.tex — shared math symbol definitions
paper/references.bib — verified BibTeX entries
wiki/log.md — appended log entry
Wiki Interaction
Reads
wiki/outputs/paper-plan-*.md — PAPER_PLAN (section outline, evidence map, figure plan, citation plan)
wiki/claims/*.md — Statement, Evidence summary, Conditions of target claims
wiki/experiments/*.md — Results, Analysis, key_result, metrics data
wiki/papers/*.md — Method, Results, Related (as citation content and baseline reference)
wiki/concepts/*.md — Definition, Formal notation, Variants (supports Method writing)
wiki/topics/*.md — Overview, Timeline, SOTA tracker (supports Introduction context)
wiki/ideas/*.md — Motivation, Hypothesis (supports gap narrative in Introduction)
wiki/people/*.md — author names and institutions (citation formatting)
wiki/graph/edges.jsonl — relationship graph (build argumentative logic chain)
wiki/graph/open_questions.md — known limitations (write Limitations and Future Work)
.claude/skills/shared-references/academic-writing.md — writing standards
.claude/skills/shared-references/citation-verification.md — citation discipline
Writes
paper/ directory (all files)
wiki/log.md — appended operation log
Graph edges created
- None (paper-plan already created derived_from edges)
Workflow
Precondition: confirm the working directory is the wiki project root (the directory containing wiki/, raw/, tools/).
Step 1: Initialize Paper Directory
- Read PAPER_PLAN.md; extract venue, title, section list
- If
paper/ directory already exists:
- Back up as
paper.bak-{timestamp}/
- Prompt user to confirm overwrite
- Create directory structure:
paper/
├── main.tex
├── math_commands.tex
├── references.bib
├── sections/
└── figures/
- Copy venue template from
templates/ if it exists:
templates/{venue}.sty or templates/{venue}/
- If no template: use generic article class; note in main.tex that the official template must be substituted
- Generate
math_commands.tex:
- Collect all Formal notation from wiki/concepts/
- Unify symbol definitions (vectors, matrices, sets, common operators)
- Generate
main.tex skeleton:\documentclass{article} % replace with venue template
\input{math_commands}
% packages
\usepackage{booktabs,graphicx,amsmath,hyperref}
\title{<title>}
\author{} % leave empty for anonymous submission
\begin{document}
\maketitle
\begin{abstract}
% generated in Step 3
\end{abstract}
\input{sections/introduction}
\input{sections/related_work}
\input{sections/method}
\input{sections/experiments}
\input{sections/conclusion}
\bibliography{references}
\bibliographystyle{plain} % replace with venue-required style
% \input{sections/appendix} % uncomment if needed
\end{document}
Step 2: Generate Figures and Tables
For each entry in the Figure Plan from PAPER_PLAN:
Diagram type (architecture diagrams, etc.):
- Use TikZ or pgfplots to generate native LaTeX figures
- If too complex: generate a matplotlib Python script → output PDF
- Save to
paper/figures/{figure-name}.pdf
Plot type (experimental result charts):
Table type:
- Use booktabs style (toprule, midrule, bottomrule)
- Best result bold, second-best underline
- Embed directly in section .tex file (small tables) or standalone
paper/tables/{name}.tex (large tables)
Step 3: Write Sections
For each section (in the outline order from PAPER_PLAN); if --sections is specified, write only those sections:
3a. Collect Material
From the section definition in PAPER_PLAN, extract:
- the claims this section supports
- the list of corresponding wiki pages
- planned figures/tables
- citation list
Read the relevant portions of all related wiki pages:
- Introduction → wiki/ideas/{idea}.md#Motivation + wiki/topics/{topic}.md#Overview
- Related Work → wiki/papers/.md#Related + wiki/concepts/.md#Comparison
- Method → wiki/concepts/*.md#Formal_notation + wiki/claims/{claim}.md#Statement
- Experiments → wiki/experiments/.md#Results + wiki/experiments/.md#Analysis
- Conclusion → wiki/graph/open_questions.md + wiki/claims/*.md#Open_questions
3b. Write LaTeX
Following shared-references/academic-writing.md:
- Write according to the paragraph plan for that section
- Insert
\cite{key} citations (keys mapped from citation plan)
- Insert
\ref{fig:name} / \ref{tab:name} references to figures/tables
- Use symbols defined in
math_commands.tex
- Begin each paragraph with a topic sentence
- Experiments section: claim-first structure ("We claim X. To verify, we...")
3c. De-AI Polish
Apply de-AI polish to each written section (per academic-writing.md):
- Scan and replace AI-signature vocabulary (delve, leverage, utilize, comprehensive...)
- Remove excessive hedging
- Vary sentence openings (avoid consecutive identical sentence structures)
- Remove filler sentences (sentences that add no information)
- Ensure active voice predominates
- Check notation consistency
3d. Optional Review LLM Review (--review)
If --review is enabled, for each section:
mcp__llm-review__chat:
system: "You are a senior ML researcher reviewing one section of a paper draft.
Focus on: clarity, logical flow, claim-evidence alignment, notation consistency.
Point out any remaining AI-sounding language patterns.
Suggest specific rewrites for unclear passages."
message: |
## Section: {section name}
{LaTeX content}
## Claims this section should support
{claims from matrix}
## Review this section for:
1. Does it clearly support its target claims?
2. Is the writing clear and precise?
3. Any AI-generated language patterns remaining?
4. Is the notation consistent with other sections?
5. Missing content that reviewers will expect?
Revise the section based on Review LLM feedback (inline edits; do not rewrite the entire section).
Step 4: Build Bibliography
Following shared-references/citation-verification.md:
- Collect all
\cite{key} citations used across sections
- For each citation, retrieve BibTeX from the PAPER_PLAN's citation plan:
- Verified: write directly to
references.bib
- [UNCONFIRMED]: write to the bottom of
references.bib with a % [UNCONFIRMED] comment
- Exclude unused entries (do not use
\nocite{*})
- Validate BibTeX format correctness (each entry has title, author, year)
- Output bibliography statistics:
references.bib: {N} entries, {M} verified, {K} [UNCONFIRMED]
Step 5: Full-Paper Cross-Review
After all sections are complete:
mcp__llm-review__chat:
system: "You are a senior ML researcher performing a final review of a complete paper draft.
Focus on: cross-section coherence, claim-evidence thread (does the paper prove what it claims?),
narrative flow, notation consistency across sections, figure/table referencing.
This is NOT a line-by-line review — focus on structural and argumentative issues."
message: |
## Full Paper Draft
{concatenated LaTeX of all sections}
## Evidence Map
{from PAPER_PLAN}
## Review Focus
1. Does the paper tell a coherent story from Introduction to Conclusion?
2. Are all claims from the matrix adequately supported in the text?
3. Is there notation inconsistency between sections?
4. Are all figures/tables referenced and discussed?
5. Any redundancy between sections?
6. Overall readiness for submission (1-10)?
Make final adjustments based on Review LLM feedback.
Step 6: Finalize Output
- Confirm all files are written to the
paper/ directory
- Verify basic integrity:
- all files referenced by
\input{sections/X} exist
- all files referenced by
\includegraphics{figures/X} exist
- all
\cite{key} keys have a corresponding entry in references.bib
- all
\ref{label} have a corresponding \label{label}
- Append log:
python3 tools/research_wiki.py log wiki/ \
"paper-draft | drafted {venue} paper '{title}' | {N} sections, {M} figures, {K} citations ({V} verified)"
- Print to terminal:
# Paper Write Complete
## Files
- paper/main.tex (master file)
- paper/sections/ ({N} section files)
- paper/figures/ ({M} figure files)
- paper/references.bib ({K} entries, {V_count} [UNCONFIRMED])
- paper/math_commands.tex
## Status
- Sections written: {list}
- De-AI polish: applied
- Review LLM review: {yes/no, if yes: overall score}
- [UNCONFIRMED] citations: {count} (resolve before /paper-compile)
## Next Steps
- Run `/paper-compile paper/` to compile and verify
- Resolve [UNCONFIRMED] citations manually
- Run `/refine paper/main.tex --focus writing` for further polish
Constraints
- Each section draws from wiki: do not generate content from nothing; every technical claim must trace back to a wiki page
- BibTeX follows citation-verification.md: fetch from DBLP/CrossRef/S2; do not generate from LLM memory
- De-AI polish is mandatory: each section must receive a polish pass after writing; cannot be skipped
- Figures follow academic-writing.md: colorblind-safe, font size >= 8pt, vector format preferred
- Anonymous submission: do not write author names, institutions, or acknowledgements (per venue anonymity requirements)
- \nocite{*} is forbidden: only cite entries actually used
- Notation consistency: all sections use unified symbols from math_commands.tex
- Back up existing paper/ before overwriting: do not overwrite directly; back up first
- Wikilink → \cite conversion: [[slug]] references in PAPER_PLAN are converted to \cite{key} in LaTeX
- Tables use booktabs: no vertical lines or full grid
Error Handling
- PAPER_PLAN not found: error; suggest running /paper-plan first
- PAPER_PLAN format incomplete: list missing sections; suggest re-running /paper-plan
- Wiki page not found (claim/experiment/paper referenced in plan does not exist): warn and skip that reference; annotate as missing
- Figure generation failed (matplotlib error): output placeholder
% TODO: generate figure {name}; continue with other sections
- All BibTeX fetches failed: use [UNCONFIRMED] placeholders; report the count requiring manual handling in the terminal
- Review LLM unavailable (--review mode): skip section review and cross-review; annotate as "unreviewed"
- Venue template not found: use generic article class; note in main.tex
- Section too long (exceeds plan page budget): warn; suggest moving to appendix or compressing
Dependencies
Tools(via Bash)
python3 tools/research_wiki.py log wiki/ "<message>" — append log
python3 tools/fetch_s2.py search "<title>" — BibTeX fallback (S2 search)
python3 — execute matplotlib figure scripts
MCP Servers
mcp__llm-review__chat — per-section review (optional, --review) + full-paper cross-review (Step 5)
Claude Code Native
Read — read wiki pages and PAPER_PLAN
Glob — find wiki pages
Write — write files to paper/ directory
Bash — execute figure scripts, create directories
WebFetch — DBLP / CrossRef BibTeX fetch
Shared References
.claude/skills/shared-references/academic-writing.md — writing standards + de-AI polish rules + figure design
.claude/skills/shared-references/citation-verification.md — BibTeX fetch workflow + [UNCONFIRMED] protocol
Called by
/research Stage 5 (paper writing stage)
- Manual user invocation
1---2name: paper-draft3description: Draft a LaTeX paper from PAPER_PLAN — write each section from wiki sources + generate figures/tables + BibTeX verification + de-AI polish4---56# /paper-draft78> Draft a complete LaTeX paper from the PAPER_PLAN.md generated by /paper-plan.9> Write section by section: each section draws material from wiki claims/experiments/papers/concepts,10> generates LaTeX + figures + tables. BibTeX is fetched from DBLP/CrossRef (following citation-verification).11> Apply de-AI polish after completion (following academic-writing).12> Optional per-section Review LLM review. Output a compilable paper/ directory.1314## Inputs1516- `plan`: path to PAPER_PLAN.md (e.g. `wiki/outputs/paper-plan-sparse-lora-2026-04-08.md`)17- `--review` (optional): enable per-section Review LLM review18- `--sections` (optional): write only specified sections (e.g. `--sections 3,4` writes only Method + Experiments); used for incremental writing1920## Outputs2122- `paper/` directory (under the wiki project root):23 - `paper/main.tex` — master file (includes each section)24 - `paper/sections/introduction.tex`25 - `paper/sections/related_work.tex`26 - `paper/sections/method.tex`27 - `paper/sections/experiments.tex`28 - `paper/sections/conclusion.tex`29 - `paper/sections/appendix.tex` (if applicable)30 - `paper/figures/` — generated figures (PDF/PNG)31 - `paper/tables/` — standalone table files (optional)32 - `paper/math_commands.tex` — shared math symbol definitions33 - `paper/references.bib` — verified BibTeX entries34- `wiki/log.md` — appended log entry3536## Wiki Interaction3738### Reads39- `wiki/outputs/paper-plan-*.md` — PAPER_PLAN (section outline, evidence map, figure plan, citation plan)40- `wiki/claims/*.md` — Statement, Evidence summary, Conditions of target claims41- `wiki/experiments/*.md` — Results, Analysis, key_result, metrics data42- `wiki/papers/*.md` — Method, Results, Related (as citation content and baseline reference)43- `wiki/concepts/*.md` — Definition, Formal notation, Variants (supports Method writing)44- `wiki/topics/*.md` — Overview, Timeline, SOTA tracker (supports Introduction context)45- `wiki/ideas/*.md` — Motivation, Hypothesis (supports gap narrative in Introduction)46- `wiki/people/*.md` — author names and institutions (citation formatting)47- `wiki/graph/edges.jsonl` — relationship graph (build argumentative logic chain)48- `wiki/graph/open_questions.md` — known limitations (write Limitations and Future Work)49- `.claude/skills/shared-references/academic-writing.md` — writing standards50- `.claude/skills/shared-references/citation-verification.md` — citation discipline5152### Writes53- `paper/` directory (all files)54- `wiki/log.md` — appended operation log5556### Graph edges created57- None (paper-plan already created derived_from edges)5859## Workflow6061**Precondition**: confirm the working directory is the wiki project root (the directory containing `wiki/`, `raw/`, `tools/`).6263### Step 1: Initialize Paper Directory64651. Read PAPER_PLAN.md; extract venue, title, section list662. If `paper/` directory already exists:67 - Back up as `paper.bak-{timestamp}/`68 - Prompt user to confirm overwrite693. Create directory structure:70 ```71 paper/72 ├── main.tex73 ├── math_commands.tex74 ├── references.bib75 ├── sections/76 └── figures/77 ```784. Copy venue template from `templates/` if it exists:79 - `templates/{venue}.sty` or `templates/{venue}/`80 - If no template: use generic article class; note in main.tex that the official template must be substituted815. Generate `math_commands.tex`:82 - Collect all Formal notation from wiki/concepts/83 - Unify symbol definitions (vectors, matrices, sets, common operators)846. Generate `main.tex` skeleton:85 ```latex86 \documentclass{article} % replace with venue template87 \input{math_commands}88 % packages89 \usepackage{booktabs,graphicx,amsmath,hyperref}9091 \title{<title>}92 \author{} % leave empty for anonymous submission9394 \begin{document}95 \maketitle96 \begin{abstract}97 % generated in Step 398 \end{abstract}99 \input{sections/introduction}100 \input{sections/related_work}101 \input{sections/method}102 \input{sections/experiments}103 \input{sections/conclusion}104 \bibliography{references}105 \bibliographystyle{plain} % replace with venue-required style106 % \input{sections/appendix} % uncomment if needed107 \end{document}108 ```109110### Step 2: Generate Figures and Tables111112For each entry in the Figure Plan from PAPER_PLAN:1131141. **Diagram type** (architecture diagrams, etc.):115 - Use TikZ or pgfplots to generate native LaTeX figures116 - If too complex: generate a matplotlib Python script → output PDF117 - Save to `paper/figures/{figure-name}.pdf`1181192. **Plot type** (experimental result charts):120 - Extract data from `wiki/experiments/{slug}.md`121 - Generate matplotlib script (following figure design standards in academic-writing):122 - Colorblind-safe palette123 - Font size >= 8pt124 - Error bars / confidence bands125 - Clear legend126 - Execute script to generate PDF:127 ```bash128 python3 paper/figures/plot_{name}.py129 ```130 - Save to `paper/figures/{figure-name}.pdf`1311323. **Table type**:133 - Use booktabs style (toprule, midrule, bottomrule)134 - Best result bold, second-best underline135 - Embed directly in section .tex file (small tables) or standalone `paper/tables/{name}.tex` (large tables)136137### Step 3: Write Sections138139For each section (in the outline order from PAPER_PLAN); if `--sections` is specified, write only those sections:140141**3a. Collect Material**142143From the section definition in PAPER_PLAN, extract:144- the claims this section supports145- the list of corresponding wiki pages146- planned figures/tables147- citation list148149Read the relevant portions of all related wiki pages:150- Introduction → wiki/ideas/{idea}.md#Motivation + wiki/topics/{topic}.md#Overview151- Related Work → wiki/papers/*.md#Related + wiki/concepts/*.md#Comparison152- Method → wiki/concepts/*.md#Formal_notation + wiki/claims/{claim}.md#Statement153- Experiments → wiki/experiments/*.md#Results + wiki/experiments/*.md#Analysis154- Conclusion → wiki/graph/open_questions.md + wiki/claims/*.md#Open_questions155156**3b. Write LaTeX**157158Following `shared-references/academic-writing.md`:159- Write according to the paragraph plan for that section160- Insert `\cite{key}` citations (keys mapped from citation plan)161- Insert `\ref{fig:name}` / `\ref{tab:name}` references to figures/tables162- Use symbols defined in `math_commands.tex`163- Begin each paragraph with a topic sentence164- Experiments section: claim-first structure ("We claim X. To verify, we...")165166**3c. De-AI Polish**167168Apply de-AI polish to each written section (per academic-writing.md):1691. Scan and replace AI-signature vocabulary (delve, leverage, utilize, comprehensive...)1702. Remove excessive hedging1713. Vary sentence openings (avoid consecutive identical sentence structures)1724. Remove filler sentences (sentences that add no information)1735. Ensure active voice predominates1746. Check notation consistency175176**3d. Optional Review LLM Review (--review)**177178If `--review` is enabled, for each section:179180```181mcp__llm-review__chat:182 system: "You are a senior ML researcher reviewing one section of a paper draft.183 Focus on: clarity, logical flow, claim-evidence alignment, notation consistency.184 Point out any remaining AI-sounding language patterns.185 Suggest specific rewrites for unclear passages."186 message: |187 ## Section: {section name}188 {LaTeX content}189190 ## Claims this section should support191 {claims from matrix}192193 ## Review this section for:194 1. Does it clearly support its target claims?195 2. Is the writing clear and precise?196 3. Any AI-generated language patterns remaining?197 4. Is the notation consistent with other sections?198 5. Missing content that reviewers will expect?199```200201Revise the section based on Review LLM feedback (inline edits; do not rewrite the entire section).202203### Step 4: Build Bibliography204205Following `shared-references/citation-verification.md`:2062071. Collect all `\cite{key}` citations used across sections2082. For each citation, retrieve BibTeX from the PAPER_PLAN's citation plan:209 - Verified: write directly to `references.bib`210 - [UNCONFIRMED]: write to the bottom of `references.bib` with a `% [UNCONFIRMED]` comment2113. Exclude unused entries (do not use `\nocite{*}`)2124. Validate BibTeX format correctness (each entry has title, author, year)2135. Output bibliography statistics:214 ```215 references.bib: {N} entries, {M} verified, {K} [UNCONFIRMED]216 ```217218### Step 5: Full-Paper Cross-Review219220After all sections are complete:221222```223mcp__llm-review__chat:224 system: "You are a senior ML researcher performing a final review of a complete paper draft.225 Focus on: cross-section coherence, claim-evidence thread (does the paper prove what it claims?),226 narrative flow, notation consistency across sections, figure/table referencing.227 This is NOT a line-by-line review — focus on structural and argumentative issues."228 message: |229 ## Full Paper Draft230 {concatenated LaTeX of all sections}231232 ## Evidence Map233 {from PAPER_PLAN}234235 ## Review Focus236 1. Does the paper tell a coherent story from Introduction to Conclusion?237 2. Are all claims from the matrix adequately supported in the text?238 3. Is there notation inconsistency between sections?239 4. Are all figures/tables referenced and discussed?240 5. Any redundancy between sections?241 6. Overall readiness for submission (1-10)?242```243244Make final adjustments based on Review LLM feedback.245246### Step 6: Finalize Output2472481. Confirm all files are written to the `paper/` directory2492. Verify basic integrity:250 - all files referenced by `\input{sections/X}` exist251 - all files referenced by `\includegraphics{figures/X}` exist252 - all `\cite{key}` keys have a corresponding entry in references.bib253 - all `\ref{label}` have a corresponding `\label{label}`2543. Append log:255 ```bash256 python3 tools/research_wiki.py log wiki/ \257 "paper-draft | drafted {venue} paper '{title}' | {N} sections, {M} figures, {K} citations ({V} verified)"258 ```2594. Print to terminal:260 ```markdown261 # Paper Write Complete262263 ## Files264 - paper/main.tex (master file)265 - paper/sections/ ({N} section files)266 - paper/figures/ ({M} figure files)267 - paper/references.bib ({K} entries, {V_count} [UNCONFIRMED])268 - paper/math_commands.tex269270 ## Status271 - Sections written: {list}272 - De-AI polish: applied273 - Review LLM review: {yes/no, if yes: overall score}274 - [UNCONFIRMED] citations: {count} (resolve before /paper-compile)275276 ## Next Steps277 - Run `/paper-compile paper/` to compile and verify278 - Resolve [UNCONFIRMED] citations manually279 - Run `/refine paper/main.tex --focus writing` for further polish280 ```281282## Constraints283284- **Each section draws from wiki**: do not generate content from nothing; every technical claim must trace back to a wiki page285- **BibTeX follows citation-verification.md**: fetch from DBLP/CrossRef/S2; do not generate from LLM memory286- **De-AI polish is mandatory**: each section must receive a polish pass after writing; cannot be skipped287- **Figures follow academic-writing.md**: colorblind-safe, font size >= 8pt, vector format preferred288- **Anonymous submission**: do not write author names, institutions, or acknowledgements (per venue anonymity requirements)289- **\nocite{*} is forbidden**: only cite entries actually used290- **Notation consistency**: all sections use unified symbols from math_commands.tex291- **Back up existing paper/ before overwriting**: do not overwrite directly; back up first292- **Wikilink → \cite conversion**: [[slug]] references in PAPER_PLAN are converted to \cite{key} in LaTeX293- **Tables use booktabs**: no vertical lines or full grid294295## Error Handling296297- **PAPER_PLAN not found**: error; suggest running /paper-plan first298- **PAPER_PLAN format incomplete**: list missing sections; suggest re-running /paper-plan299- **Wiki page not found** (claim/experiment/paper referenced in plan does not exist): warn and skip that reference; annotate as missing300- **Figure generation failed** (matplotlib error): output placeholder `% TODO: generate figure {name}`; continue with other sections301- **All BibTeX fetches failed**: use [UNCONFIRMED] placeholders; report the count requiring manual handling in the terminal302- **Review LLM unavailable** (--review mode): skip section review and cross-review; annotate as "unreviewed"303- **Venue template not found**: use generic article class; note in main.tex304- **Section too long** (exceeds plan page budget): warn; suggest moving to appendix or compressing305306## Dependencies307308### Tools(via Bash)309- `python3 tools/research_wiki.py log wiki/ "<message>"` — append log310- `python3 tools/fetch_s2.py search "<title>"` — BibTeX fallback (S2 search)311- `python3` — execute matplotlib figure scripts312313### MCP Servers314- `mcp__llm-review__chat` — per-section review (optional, --review) + full-paper cross-review (Step 5)315316### Claude Code Native317- `Read` — read wiki pages and PAPER_PLAN318- `Glob` — find wiki pages319- `Write` — write files to paper/ directory320- `Bash` — execute figure scripts, create directories321- `WebFetch` — DBLP / CrossRef BibTeX fetch322323### Shared References324- `.claude/skills/shared-references/academic-writing.md` — writing standards + de-AI polish rules + figure design325- `.claude/skills/shared-references/citation-verification.md` — BibTeX fetch workflow + [UNCONFIRMED] protocol326327### Called by328- `/research` Stage 5 (paper writing stage)329- Manual user invocation