
Paper Compilation
Compile LaTeX research drafts to PDF with a full pdflatex–bibtex pipeline and readable error reports for agent-driven paper workflows.
Overview
Paper Compilation is an agent skill for the Idea phase that compiles LaTeX papers to PDF via pdflatex and bibtex with automated error reporting.
Install
npx skills add https://github.com/lingzhi227/agent-research-skills --skill paper-compilationWhat is this skill?
- Runs pdflatex → bibtex → pdflatex → pdflatex pipeline from a single main.tex entry
- Surfaces compile failures with stdout/stderr capture and timeout handling
- Optional chktex style checking via --check-style flag
- Stdlib-only Python script—no extra package deps beyond local TeX install
- Supports custom --output PDF path for agent artifact handoff
- Full pdflatex → bibtex → pdflatex → pdflatex pipeline
- Optional chktex style pass via --check-style
Adoption & trust: 693 installs on skills.sh; 114 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent edited a .tex file but you lack a repeatable compile script that catches LaTeX and bibliography failures in one run.
Who is it for?
Solo builders running AI-scientist or research agents who already maintain LaTeX sources and local TeX Live.
Skip if: Teams that only need Markdown READMEs or cloud-only doc pipelines with no local pdflatex installed.
When should I use this skill?
User needs to compile a LaTeX paper to PDF, fix compile errors from an agent-written manuscript, or run the compile_paper.py workflow.
What do I get? / Deliverables
You get a built PDF—or a clear error log your agent can use to fix the source on the next pass.
- Compiled PDF at default or --output path
- Compile error and stderr summary when the build fails
Recommended Skills
Journey fit
Research-phase shelf fits because the skill closes the loop on academic writeups before you productize findings. It targets paper compilation and style checks tied to literature and experiment writeups, not production app deploys.
How it compares
Use as a compile workflow script, not as a citation search or literature-review MCP.
Common Questions / FAQ
Who is paper-compilation for?
Researchers and indie ML writers using agent-research-skills who need deterministic LaTeX-to-PDF builds from the repo.
When should I use paper-compilation?
After drafting or revising main.tex during idea-phase research, before sending a PDF to collaborators or dropping it into a validate prototype appendix.
Is paper-compilation safe to install?
The script runs local shell commands against your tex tree; review the Security Audits panel on this Prism page and inspect subprocess usage before running on sensitive paths.
SKILL.md
READMESKILL.md - Paper Compilation
#!/usr/bin/env python3 """Compile a LaTeX paper to PDF with error detection. Runs the full pdflatex → bibtex → pdflatex → pdflatex pipeline, reports errors, and optionally runs chktex for style checking. Self-contained: uses only stdlib. Adapted from AI-Scientist (compile_latex) and data-to-paper (save_latex_and_compile_to_pdf). Usage: python compile_paper.py paper/main.tex python compile_paper.py paper/main.tex --check-style python compile_paper.py paper/main.tex --output paper/output.pdf """ import argparse import os import re import shutil import subprocess import sys def run_command(cmd: list[str], cwd: str, timeout: int = 60) -> tuple[int, str, str]: """Run a command and return (returncode, stdout, stderr).""" try: result = subprocess.run( cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=timeout, ) return result.returncode, result.stdout, result.stderr except subprocess.TimeoutExpired: return -1, "", f"Command timed out after {timeout}s: {' '.join(cmd)}" except FileNotFoundError: return -2, "", f"Command not found: {cmd[0]}" def check_bib_exists(tex_content: str) -> bool: """Check if the tex file references a bibliography.""" return bool(re.search(r"\\bibliography\{", tex_content) or re.search(r"\\begin\{filecontents\}\{.*\.bib\}", tex_content) or re.search(r"\\addbibresource\{", tex_content)) def extract_errors(log_content: str) -> list[str]: """Extract LaTeX errors from log file.""" errors = [] lines = log_content.split("\n") for i, line in enumerate(lines): if line.startswith("! "): # Grab the error line and a few lines of context context = lines[i:i+5] errors.append("\n".join(context)) return errors def extract_warnings(log_content: str) -> list[str]: """Extract significant warnings from log file.""" warnings = [] for line in log_content.split("\n"): line = line.strip() if "Overfull \\hbox" in line: warnings.append(line) elif "Underfull \\vbox" in line: warnings.append(line) elif "Citation" in line and "undefined" in line: warnings.append(line) elif "Reference" in line and "undefined" in line: warnings.append(line) elif "LaTeX Warning: There were undefined references" in line: warnings.append(line) return warnings def count_pages(pdf_path: str) -> int | None: """Try to count PDF pages using python.""" try: with open(pdf_path, "rb") as f: content = f.read() # Simple heuristic: count /Type /Page entries count = len(re.findall(rb"/Type\s*/Page[^s]", content)) return count if count > 0 else None except Exception: return None def compile_latex(tex_file: str, output_pdf: str | None = None, check_style: bool = False, timeout: int = 60) -> bool: """Compile LaTeX to PDF. Returns True on success.""" tex_file = os.path.abspath(tex_file) if not os.path.exists(tex_file): print(f"Error: {tex_file} not found", file=sys.stderr) return False cwd = os.path.dirname(tex_file) basename = os.path.splitext(os.path.basename(tex_file))[0] with open(tex_file, encoding="utf-8", errors="replace") as f: tex_content = f.read() has_bib = check_bib_exists(tex_content) # Build compilation sequence commands = [ ["pdflatex", "-interaction=nonstopmode", "-halt-on-error", os.path.basename(tex_file)], ] if has_bib: commands.append(["bibtex", basename]) commands.append(["pdflatex", "-interaction=nonstopmode", os.path.basename(tex_file)]) commands.append(["pdflatex", "-interaction=nonstopmode", os.path.basename(tex_file)]) print(f"Compiling {tex_file}") print(f" Working directory: {cwd}") pr