Paper Compilation Compile a LaTeX paper to PDF with error detection and correction. Input - — Path to the main file Scripts Compile paper Reports: compilation status, page count, warnings, citation/reference stats, style issues. Validate citations before compiling Auto-fix LaTeX errors Fixes: HTML tags in LaTeX, mismatched environments, missing figures. Key flags: , Compile with auto-fix retry Runs fix latex errors.py + recompile up to 3 rounds until compilation succeeds. Workflow Step 1: Pre-Compilation Validation Run to catch issues before compiling: - Every has a matching entry - Every exi…

, 'html_subscript'),\n (r'\u003csup>(.*?)\u003c/sup>', r'$^{\\1}

Paper Compilation Compile a LaTeX paper to PDF with error detection and correction. Input - — Path to the main file Scripts Compile paper Reports: compilation status, page count, warnings, citation/reference stats, style issues. Validate citations before compiling Auto-fix LaTeX errors Fixes: HTML tags in LaTeX, mismatched environments, missing figures. Key flags: , Compile with auto-fix retry Runs fix latex errors.py + recompile up to 3 rounds until compilation succeeds. Workflow Step 1: Pre-Compilation Validation Run to catch issues before compiling: - Every has a matching entry - Every exi…

, 'html_superscript'),\n (r'\u003c/?(div|span|section|h[1-6])[^>]*>', '', 'html_block'),\n ]\n for pattern, repl, fix_name in replacements:\n matches = list(re.finditer(pattern, content, re.IGNORECASE))\n if matches:\n fixes.append(LatexFix(fix_name, f\"Replaced {len(matches)} HTML {fix_name} tags\"))\n content = re.sub(pattern, repl, content, flags=re.IGNORECASE)\n return content, fixes\n\n\ndef fix_mismatched_environments(content: str) -> tuple[str, list[LatexFix]]:\n \"\"\"Detect and report mismatched begin/end environments.\"\"\"\n fixes = []\n begins = re.findall(r'\\\\begin\\{(\\w+)\\}', content)\n ends = re.findall(r'\\\\end\\{(\\w+)\\}', content)\n begin_counts = {}\n end_counts = {}\n for b in begins:\n begin_counts[b] = begin_counts.get(b, 0) + 1\n for e in ends:\n end_counts[e] = end_counts.get(e, 0) + 1\n\n for env in set(list(begin_counts.keys()) + list(end_counts.keys())):\n bc = begin_counts.get(env, 0)\n ec = end_counts.get(env, 0)\n if bc > ec:\n # Missing \\end — add at end of document\n for _ in range(bc - ec):\n content = content.rstrip() + f\"\\n\\\\end{{{env}}}\\n\"\n fixes.append(LatexFix(f\"add_end_{env}\", f\"Added missing \\\\end{{{env}}}\"))\n elif ec > bc:\n # Extra \\end — remove last occurrence\n for _ in range(ec - bc):\n idx = content.rfind(f\"\\\\end{{{env}}}\")\n if idx >= 0:\n content = content[:idx] + content[idx + len(f\"\\\\end{{{env}}}\"):]\n fixes.append(LatexFix(f\"remove_end_{env}\", f\"Removed extra \\\\end{{{env}}}\"))\n\n return content, fixes\n\n\ndef fix_missing_math_mode(content: str) -> tuple[str, list[LatexFix]]:\n \"\"\"Fix common math-mode issues like unescaped underscores in text.\"\"\"\n fixes = []\n # Find _ outside math mode that's part of a variable name pattern\n # e.g., \"model_name\" should become \"model\\_name\" or \"$model\\_name$\"\n # This is a simplified heuristic\n return content, fixes\n\n\ndef fix_missing_figures(content: str, tex_dir: str) -> tuple[str, list[LatexFix]]:\n \"\"\"Comment out includegraphics for missing figure files.\"\"\"\n fixes = []\n for m in re.finditer(r'\\\\includegraphics(?:\\[.*?\\])?\\{([^}]+)\\}', content):\n fig_path = m.group(1)\n full_path = os.path.join(tex_dir, fig_path)\n # Check with and without common extensions\n found = os.path.exists(full_path)\n if not found:\n for ext in ['.png', '.pdf', '.jpg', '.jpeg', '.eps']:\n if os.path.exists(full_path + ext):\n found = True\n break\n if not found:\n # Comment out the line containing this includegraphics\n line_start = content.rfind('\\n', 0, m.start()) + 1\n line_end = content.find('\\n', m.end())\n if line_end == -1:\n line_end = len(content)\n original_line = content[line_start:line_end]\n if not original_line.strip().startswith('%'):\n commented = '% FIXME: missing file - ' + original_line\n content = content[:line_start] + commented + content[line_end:]\n fixes.append(LatexFix(\"comment_missing_figure\",\n f\"Commented out missing figure: {fig_path}\"))\n return content, fixes\n\n\ndef auto_detect_log(tex_file: str) -> str | None:\n \"\"\"Try to find the .log file for a .tex file.\"\"\"\n base = os.path.splitext(tex_file)[0]\n log_file = base + \".log\"\n if os.path.exists(log_file):\n return log_file\n return None\n\n\ndef main():\n parser = argparse.ArgumentParser(description=\"Automated LaTeX error fixer\")\n parser.add_argument(\"--tex\", required=True, help=\"Main .tex file\")\n parser.add_argument(\"--log\", help=\"pdflatex .log file\")\n parser.add_argument(\"--auto-detect\", action=\"store_true\", help=\"Auto-detect .log file\")\n parser.add_argument(\"--output\", \"-o\", help=\"Output .tex file\")\n parser.add_argument(\"--dry-run\", action=\"store_true\", help=\"Show fixes without applying\")\n args = parser.parse_args()\n\n if not os.path.exists(args.tex):\n print(f\"Error: {args.tex} not found\", file=sys.stderr)\n sys.exit(1)\n\n with open(args.tex, encoding=\"utf-8\", errors=\"replace\") as f:\n content = f.read()\n\n tex_dir = os.path.dirname(os.path.abspath(args.tex))\n\n # Load error log if available\n log_content = \"\"\n log_file = args.log\n if not log_file and args.auto_detect:\n log_file = auto_detect_log(args.tex)\n if log_file and os.path.exists(log_file):\n with open(log_file, encoding=\"utf-8\", errors=\"replace\") as f:\n log_content = f.read()\n\n errors = parse_errors(log_content) if log_content else []\n if errors:\n print(f\"Found {len(errors)} errors/warnings in log\", file=sys.stderr)\n for e in errors[:10]:\n print(f\" [{e['type']}] {e['message'][:80]}\", file=sys.stderr)\n\n # Apply fixes\n all_fixes = []\n\n content, fixes = fix_html_tags(content)\n all_fixes.extend(fixes)\n\n content, fixes = fix_mismatched_environments(content)\n all_fixes.extend(fixes)\n\n content, fixes = fix_missing_figures(content, tex_dir)\n all_fixes.extend(fixes)\n\n content, fixes = fix_missing_math_mode(content)\n all_fixes.extend(fixes)\n\n if args.dry_run:\n print(f\"\\n## Fixes that would be applied ({len(all_fixes)}):\")\n for fix in all_fixes:\n print(f\" - [{fix.name}] {fix.description}\")\n if not all_fixes:\n print(\" No fixes needed.\")\n sys.exit(0)\n\n if not all_fixes:\n print(\"No fixes needed.\", file=sys.stderr)\n sys.exit(0)\n\n print(f\"\\nApplied {len(all_fixes)} fixes:\", file=sys.stderr)\n for fix in all_fixes:\n print(f\" - [{fix.name}] {fix.description}\", file=sys.stderr)\n\n if args.output:\n with open(args.output, \"w\", encoding=\"utf-8\") as f:\n f.write(content)\n print(f\"Fixed file written to {args.output}\", file=sys.stderr)\n else:\n sys.stdout.write(content)\n\n\nif __name__ == \"__main__\":\n main()\n","content_type":"text/x-python; charset=utf-8","language":"python","size":11460,"content_sha256":"80ccd9cc3fff82110530b88d92fe693cd4997de9d2cfc20f274cce114c278850"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Paper Compilation","type":"text"}]},{"type":"paragraph","content":[{"text":"Compile a LaTeX paper to PDF with error detection and correction.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Input","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"$ARGUMENTS","type":"text","marks":[{"type":"code_inline"}]},{"text":" — Path to the main ","type":"text"},{"text":".tex","type":"text","marks":[{"type":"code_inline"}]},{"text":" file","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Scripts","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Compile paper","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/paper-compilation/scripts/compile_paper.py paper/main.tex\npython ~/.claude/skills/paper-compilation/scripts/compile_paper.py paper/main.tex --check-style\npython ~/.claude/skills/paper-compilation/scripts/compile_paper.py paper/main.tex --output paper/output.pdf","type":"text"}]},{"type":"paragraph","content":[{"text":"Reports: compilation status, page count, warnings, citation/reference stats, style issues.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Validate citations before compiling","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/citation-management/scripts/validate_citations.py \\\n --tex paper/main.tex --bib paper/references.bib --check-figures --figures-dir paper/figures/","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Auto-fix LaTeX errors","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/paper-compilation/scripts/fix_latex_errors.py \\\n --tex paper/main.tex --log compile.log --output paper/main_fixed.tex","type":"text"}]},{"type":"paragraph","content":[{"text":"Fixes: HTML tags in LaTeX, mismatched environments, missing figures. Key flags: ","type":"text"},{"text":"--dry-run","type":"text","marks":[{"type":"code_inline"}]},{"text":", ","type":"text"},{"text":"--auto-detect","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Compile with auto-fix retry","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python ~/.claude/skills/paper-compilation/scripts/compile_paper.py paper/main.tex --auto-fix","type":"text"}]},{"type":"paragraph","content":[{"text":"Runs fix_latex_errors.py + recompile up to 3 rounds until compilation succeeds.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Workflow","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Step 1: Pre-Compilation Validation","type":"text"}]},{"type":"paragraph","content":[{"text":"Run ","type":"text"},{"text":"validate_citations.py","type":"text","marks":[{"type":"code_inline"}]},{"text":" to catch issues before compiling:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Every ","type":"text"},{"text":"\\cite{key}","type":"text","marks":[{"type":"code_inline"}]},{"text":" has a matching ","type":"text"},{"text":".bib","type":"text","marks":[{"type":"code_inline"}]},{"text":" entry","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Every ","type":"text"},{"text":"\\includegraphics{file}","type":"text","marks":[{"type":"code_inline"}]},{"text":" exists","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"No duplicate labels or sections","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Step 2: Compile","type":"text"}]},{"type":"paragraph","content":[{"text":"Run ","type":"text"},{"text":"compile_paper.py","type":"text","marks":[{"type":"code_inline"}]},{"text":" which executes: ","type":"text"},{"text":"pdflatex → bibtex → pdflatex → pdflatex","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Step 3: Error Correction Loop (up to 5 rounds)","type":"text"}]},{"type":"paragraph","content":[{"text":"If compilation fails, read the error output and fix:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"! Undefined control sequence","type":"text","marks":[{"type":"code_inline"}]},{"text":" → Add missing package or fix typo","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"! Missing $ inserted","type":"text","marks":[{"type":"code_inline"}]},{"text":" → Wrap math in ","type":"text"},{"text":"$...$","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"! Missing } inserted","type":"text","marks":[{"type":"code_inline"}]},{"text":" → Fix unmatched brace","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Citation 'key' undefined","type":"text","marks":[{"type":"code_inline"}]},{"text":" → Add to .bib or fix ","type":"text"},{"text":"\\cite","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\u003c/end{figure}>","type":"text","marks":[{"type":"code_inline"}]},{"text":" → Replace with ","type":"text"},{"text":"\\end{figure}","type":"text","marks":[{"type":"code_inline"}]},{"text":" (HTML syntax in LaTeX)","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"Apply minimal fixes. Do not remove packages unnecessarily. Recompile after each fix.","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Step 4: Post-Compilation Report","type":"text"}]},{"type":"paragraph","content":[{"text":"Check: page count vs venue limit, remaining warnings, chktex style issues.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Troubleshooting","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"pdflatex not found","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# macOS\nbrew install --cask mactex-no-gui\n# Ubuntu\nsudo apt install texlive-full","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Alternative: latexmk (auto-handles multiple passes)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"latexmk -pdf -interaction=nonstopmode main.tex","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Related Skills","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Upstream: ","type":"text"},{"text":"latex-formatting","type":"text","marks":[{"type":"link","attrs":{"href":"../latex-formatting/","title":null}}]},{"text":", ","type":"text"},{"text":"citation-management","type":"text","marks":[{"type":"link","attrs":{"href":"../citation-management/","title":null}}]},{"text":", ","type":"text"},{"text":"figure-generation","type":"text","marks":[{"type":"link","attrs":{"href":"../figure-generation/","title":null}}]},{"text":", ","type":"text"},{"text":"table-generation","type":"text","marks":[{"type":"link","attrs":{"href":"../table-generation/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Downstream: ","type":"text"},{"text":"self-review","type":"text","marks":[{"type":"link","attrs":{"href":"../self-review/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"See also: ","type":"text"},{"text":"paper-assembly","type":"text","marks":[{"type":"link","attrs":{"href":"../paper-assembly/","title":null}}]}]}]}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"paper-compilation","author":"@skillopedia","source":{"stars":92,"repo_name":"agent-research-skills","origin_url":"https://github.com/lingzhi227/agent-research-skills/blob/HEAD/skills/paper-compilation/SKILL.md","repo_owner":"lingzhi227","body_sha256":"745ecc498aa9b156cc6288448045363627ef9ac86943ecfae081f4e472f72e15","cluster_key":"e0e3131e97d627a175773e2a9d43a2c17fdebe9cbbc369349f924cece7a418e6","clean_bundle":{"format":"clean-skill-bundle-v1","source":"lingzhi227/agent-research-skills/skills/paper-compilation/SKILL.md","attachments":[{"id":"a5e4325e-0859-54c8-96e7-d6bdf907791c","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/a5e4325e-0859-54c8-96e7-d6bdf907791c/attachment.py","path":"scripts/compile_paper.py","size":9653,"sha256":"46d784d31282a1e0e804094d14bd4e7f6378539ff1b0f15b1cfa2728b248ab39","contentType":"text/x-python; charset=utf-8"},{"id":"6d6e11c1-4a41-5fe1-b696-5871e3fcfb3d","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/6d6e11c1-4a41-5fe1-b696-5871e3fcfb3d/attachment.py","path":"scripts/fix_latex_errors.py","size":11460,"sha256":"80ccd9cc3fff82110530b88d92fe693cd4997de9d2cfc20f274cce114c278850","contentType":"text/x-python; charset=utf-8"}],"bundle_sha256":"4bc77c1e7e16b74c4569b7d37cf8d90d94a661c1cb0b12b3d1d5c3c48dd66c51","attachment_count":2,"text_attachments":2,"attachment_storage":"skillopedia-attachments-v1","binary_attachments":0,"excluded_attachments":[]},"cluster_size":1,"skill_md_path":"skills/paper-compilation/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"documents-office","category_label":"Documents"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"documents-office","import_tag":"clean-skills-v1","description":"Compile LaTeX papers to PDF with automatic error detection, chktex style checking, and citation/reference validation. Runs the full pdflatex + bibtex pipeline. Use when the user wants to compile a paper, fix compilation errors, or debug LaTeX.","argument-hint":["tex-file-path"]}},"renderedAt":1782979948450}

Paper Compilation Compile a LaTeX paper to PDF with error detection and correction. Input - — Path to the main file Scripts Compile paper Reports: compilation status, page count, warnings, citation/reference stats, style issues. Validate citations before compiling Auto-fix LaTeX errors Fixes: HTML tags in LaTeX, mismatched environments, missing figures. Key flags: , Compile with auto-fix retry Runs fix latex errors.py + recompile up to 3 rounds until compilation succeeds. Workflow Step 1: Pre-Compilation Validation Run to catch issues before compiling: - Every has a matching entry - Every exi…