LaTeX Document Skill
Create any LaTeX document, compile to PDF, and generate PNG previews. Convert PDFs of any type to LaTeX.
Workflow: Create Documents
- Determine document type (resume, report, letter, invoice, article, thesis, academic CV, presentation, poster, exam, book, cheat sheet)
- If poster: Run the poster sub-workflow (see Poster Sub-Workflow below), then skip to step 5.
- If cheat sheet / reference card: Run the cheat sheet sub-workflow (see Cheat Sheet / Reference Card Sub-Workflow below), then skip to step 5.
- Ask the user which enrichment elements they want (use AskUserQuestion tool with multiSelect). Offer relevant options based on document type:
- AI-generated images -- custom illustrations, diagrams, photos (uses generate-image skill)
- Charts/graphs -- bar, line, pie, scatter, heatmap (pgfplots or matplotlib)
- Flowcharts/diagrams -- process flows, architecture, decision trees (TikZ or Mermaid)
- Citations/bibliography -- academic references, footnotes, works cited (BibTeX/biblatex)
- Tables with data -- comparison matrices, financial data, statistics (booktabs)
- Watermarks -- DRAFT, CONFIDENTIAL, or company logo background
- Skip this step for simple documents (cover letters, invoices) or when the user has already specified exactly what they want.
- Copy the appropriate template from
assets/templates/ or write from scratch
- Customize content based on user requirements
- Generate external assets based on user's element choices:
- AI images:
python3 <skill_path>/../generate-image/scripts/generate_image.py "prompt" --output ./outputs/figure.png
- matplotlib charts:
python3 <skill_path>/scripts/generate_chart.py <type> --data '<json>' --output chart.png
- Mermaid diagrams:
bash <skill_path>/scripts/mermaid_to_image.sh diagram.mmd output.png
- For documents 5+ pages: Review the Long-Form Document Anti-Patterns section and run the Content Generation Checklist before compiling. Key rules: prefer prose over bullets, include global list compaction, escape
</> in text mode, vary section formats, limit ewpage, size images at 0.75-0.85 textwidth.
- Compile with
scripts/compile_latex.sh (auto-detects XeLaTeX for CJK/RTL, glossaries, bibliography)
- Show PNG preview to user, deliver PDF
Poster Sub-Workflow
When the user requests a poster: read references/poster-design-guide.md for the complete workflow including conference size presets (NeurIPS/ICML/CVPR/ICLR dimensions), layout archetypes (Traditional/BetterPoster/Visual-Heavy), color schemes, and typography standards. Use poster.tex (portrait) or poster-landscape.tex (landscape). Ask the user for conference/orientation, layout style, and color scheme using AskUserQuestion, then proceed to step 5.
Cheat Sheet / Reference Card Sub-Workflow
When the user requests a cheat sheet, reference card, or formula sheet:
- Read references/cheatsheet-guide.md for the complete workflow including template selection, content budgets, typography rules, and the PDF-to-cheatsheet pipeline.
- Select template:
cheatsheet.tex (general, 3-col landscape), cheatsheet-exam.tex (exam formula, 2-col portrait), or cheatsheet-code.tex (programming, 4-col landscape).
- Follow the guide's workflow steps, then return to main workflow step 5.
Workflow: Mail Merge (Batch Personalized Documents)
Generate N personalized documents from a LaTeX template + CSV/JSON data source using scripts/mail_merge.py. Template syntax: {{variable}} for simple substitution, Jinja2 (<< >>, <% %>) for conditionals/loops. See assets/templates/mail-merge-letter.tex for an example. Full guide: references/interactive-features.md.
Workflow: Version Diffing (latexdiff)
Generate highlighted change-tracked PDFs using scripts/latex_diff.sh. Supports file-to-file diff, git revision diff, multi-file flatten, and custom markup styles. Full guide: references/interactive-features.md.
Workflow: Convert Document Formats
Convert between Markdown, DOCX, HTML, and LaTeX using scripts/convert_document.sh. Full guide: references/format-conversion.md.
Workflow: Convert PDF to LaTeX
Convert existing PDFs (handwritten notes, printed reports, legal docs) to LaTeX. Full pipeline: references/pdf-conversion.md.
Quick steps: Split PDF into page images (scripts/pdf_to_images.sh), select a conversion profile, create shared preamble, apply scaling strategy, validate with scripts/validate_latex.py, concatenate, compile.
Scaling strategy: 1-10 pages = single agent; 11-20 pages = split in half (2 agents); 21+ pages = batch-7 pipeline (ceil(N/7) agents with run_in_background: true).
Conversion profiles (in references/profiles/): math-notes.md (equations, theorems -- has beautiful mode), business-document.md (reports, memos), legal-document.md (contracts, statutes), general-notes.md (handwritten, mixed content).
Workflow: Fill PDF Forms
Fill existing PDF forms -- both fillable (with form fields) and non-fillable (image-based). Full guide: references/pdf-operations.md.
Step 1: Check form type:
python3 <skill_path>/scripts/pdf_check_form.py form.pdf
If fillable (has form fields):
# Extract field metadata
python3 <skill_path>/scripts/pdf_extract_fields.py form.pdf field_info.json
# Create field_values.json with values for each field, then fill
python3 <skill_path>/scripts/pdf_fill_form.py form.pdf field_values.json output.pdf
If non-fillable (no form fields):
# Convert to images for visual analysis
bash <skill_path>/scripts/pdf_to_images.sh form.pdf ./tmp/pages
# Visually identify fields, create fields.json with bounding boxes
# Validate bounding boxes (+ optional validation image)
python3 <skill_path>/scripts/pdf_validate_boxes.py fields.json --image page_1.png --output validation.png --page 1
# Fill with text annotations
python3 <skill_path>/scripts/pdf_fill_annotations.py form.pdf fields.json output.pdf
Workflow: Advanced PDF Operations
For text/table extraction (pdfplumber), OCR (pytesseract), programmatic PDF creation (reportlab), watermarking, page rotation/cropping, metadata extraction, JavaScript libraries (pdf-lib, pdfjs-dist), and batch processing, see references/pdf-operations.md.
Compile Script
# Basic compile (auto-detects engine)
bash <skill_path>/scripts/compile_latex.sh document.tex
# Compile + generate PNG previews
bash <skill_path>/scripts/compile_latex.sh document.tex --preview
# Compile + PNG in specific directory
bash <skill_path>/scripts/compile_latex.sh document.tex --preview --preview-dir ./outputs
# Force a specific engine
bash <skill_path>/scripts/compile_latex.sh document.tex --engine xelatex
bash <skill_path>/scripts/compile_latex.sh document.tex --engine lualatex
# Use latexmk for automatic multi-pass (recommended for complex documents)
bash <skill_path>/scripts/compile_latex.sh document.tex --use-latexmk --preview
# PDF/A output for thesis submissions and archival compliance
bash <skill_path>/scripts/compile_latex.sh document.tex --pdfa
# Verbose output for debugging compilation issues
bash <skill_path>/scripts/compile_latex.sh document.tex --verbose
# Quiet mode for batch/CI jobs (only errors shown)
bash <skill_path>/scripts/compile_latex.sh document.tex --quiet
# Clean auxiliary files only (no compilation)
bash <skill_path>/scripts/compile_latex.sh document.tex --clean
Compilation Flags
| Flag |
Description |
--preview |
Generate PNG previews of each page after compilation |
--preview-dir DIR |
Directory for PNG output (default: same as .tex file) |
--engine ENGINE |
Force engine: pdflatex, xelatex, or lualatex |
--use-latexmk |
Use latexmk as compilation backend (auto multi-pass, bibliography, index) |
--verbose |
Show full compilation output (all engine logs) |
--quiet |
Suppress all non-error output |
--clean |
Remove auxiliary files (.aux, .log, .bbl, .fdb_latexmk, etc.) and exit |
--pdfa |
Produce PDF/A-2b compliant output (auto-injects pdfx package) |
--auto-fix |
Auto-fix common compilation errors (float placement, encoding) |
Compilation Backends
Manual multi-pass (default): Runs the engine multiple times with bibliography/index/glossary passes as needed. This is the traditional approach and works without latexmk installed.
latexmk (--use-latexmk): Uses latexmk for automatic dependency-driven compilation. Recommended for complex documents with bibliographies, indexes, glossaries, or cross-references -- latexmk determines the correct number of passes automatically. Requires latexmk (included with TeX Live).
Log Filtering (texfot)
When texfot is installed (included with TeX Live), compilation output is automatically filtered to show only relevant warnings and errors, suppressing noisy package loading messages. This applies in the default verbosity mode. Use --verbose to see unfiltered output, or --quiet to suppress all non-error output.
Engine auto-detection: If the .tex file uses fontspec, xeCJK, or polyglossia, the script automatically uses xelatex. If it uses luacode or luatextra, it uses lualatex. Otherwise defaults to pdflatex. Override with --engine.
The script auto-installs texlive (including texlive-science, texlive-xetex, texlive-luatex, biber) and poppler-utils if missing. It auto-detects ibliography{} (runs bibtex), ddbibresource{} (runs biber), \makeindex (runs makeindex), \makeglossaries (runs makeglossaries), runs the correct number of passes, generates PNG previews with pdftoppm, and cleans auxiliary files.
Script & Tool Reference
For PDF utilities (encrypt, merge, optimize, extract pages, pdf-to-images), LaTeX quality tools (lint, word count, analysis, package check, citations), compilation auto-fix, bibliography fetching, and diagram scripts (Mermaid, Graphviz, PlantUML), see references/script-tools.md.
Templates
Copy from assets/templates/ and customize.
Resume Templates (5 ATS-Compatible Options)
Select based on experience level, industry, and ATS requirements. See references/resume-ats-guide.md for full ATS guidance.
| Template |
Best For |
Key Feature |
ATS Score |
resume-classic-ats.tex |
Finance, law, government, any ATS portal |
Zero graphics, plain text only, maximum parse safety |
10/10 |
resume-modern-professional.tex |
Tech, corporate, general professional |
Subtle color accents, clean design, good ATS + human appeal |
9/10 |
resume-executive.tex |
VP, Director, C-suite (5-15+ years) |
Two-page, executive summary, board roles, P&L focus |
9/10 |
resume-technical.tex |
Software, data, engineering roles |
Skills-first hybrid, projects section, tech stack emphasis |
9/10 |
resume-entry-level.tex |
New graduates, career starters |
Education-first, one page, coursework, activities |
9/10 |
All 5 templates follow ATS rules: single-column, no graphics/images, no tables for layout, standard section headings, contact info in body (not header/footer).
STEM Student Templates
homework.tex -- Homework/assignment submission template (article class, 11pt) with toggle-able solutions (\showsolutionstrue/\showsolutionsfalse), custom problem/solution environments, honor code section, fancyhdr headers, amsmath+amssymb+amsthm math, listings code highlighting (Python, Java, C++, Matlab styles), enumitem for (a), (b), (c) sub-parts, hyperref. Customization via `
1---2name: latex-document3description: Universal LaTeX document skill: create, compile, and convert any document to professional PDF with PNG previews. Supports resumes, reports, cover letters, invoices, academic papers, theses/dissertations, academic CVs, presentations (Beamer), scientific posters, formal letters, exams/quizzes, books, cheat sheets, reference cards, exam formula sheets, fillable PDF forms (hyperref form fields), conditional content (etoolbox toggles), mail merge from CSV/JSON (Jinja2 templates), version diffing (latexdiff), charts (pgfplots + matplotlib), tables (booktabs + CSV import), images (TikZ), Mermaid diagrams, AI-generated images, watermarks, landscape pages, bibliography/citations (BibTeX/biblatex), multi-language/CJK (auto XeLaTeX), algorithms/pseudocode, colored boxes (tcolorbox), SI units (siunitx), Pandoc format conversion (Markdown/DOCX/HTML ↔ LaTeX), and PDF-to-LaTeX conversion of handwritten or printed documents (math, business, legal, general). Compile script supports pdflatex, xelatex, lualatex with auto-detect4---56<!--7 ╔══════════════════════════════════════════════════════════════╗8 ║ 本文件为开源 Skill 原始文档,收录仅供学习与研究参考 ║9 ║ CoPaper.AI 收集整理 | https://copaper.ai ║10 ╚══════════════════════════════════════════════════════════════╝1112 来源仓库: https://github.com/ndpvt-web/latex-document-skill13 项目名称: latex-document-skill14 开源协议: MIT License15 收录日期: 2026-04-021617 声明: 本文件版权归原作者所有。此处收录旨在为社会科学实证研究者18 提供 AI Agent Skills 的集中参考。如有侵权,请联系删除。19-->2021# LaTeX Document Skill2223Create any LaTeX document, compile to PDF, and generate PNG previews. Convert PDFs of any type to LaTeX.2425## Workflow: Create Documents26271. Determine document type (resume, report, letter, invoice, article, thesis, academic CV, presentation, poster, exam, book, cheat sheet)282. **If poster:** Run the poster sub-workflow (see [Poster Sub-Workflow](#poster-sub-workflow) below), then skip to step 5.293. **If cheat sheet / reference card:** Run the cheat sheet sub-workflow (see [Cheat Sheet / Reference Card Sub-Workflow](#cheat-sheet--reference-card-sub-workflow) below), then skip to step 5.304. **Ask the user which enrichment elements they want** (use AskUserQuestion tool with multiSelect). Offer relevant options based on document type:31 - **AI-generated images** -- custom illustrations, diagrams, photos (uses generate-image skill)32 - **Charts/graphs** -- bar, line, pie, scatter, heatmap (pgfplots or matplotlib)33 - **Flowcharts/diagrams** -- process flows, architecture, decision trees (TikZ or Mermaid)34 - **Citations/bibliography** -- academic references, footnotes, works cited (BibTeX/biblatex)35 - **Tables with data** -- comparison matrices, financial data, statistics (booktabs)36 - **Watermarks** -- DRAFT, CONFIDENTIAL, or company logo background37 - Skip this step for simple documents (cover letters, invoices) or when the user has already specified exactly what they want.385. Copy the appropriate template from `assets/templates/` or write from scratch396. Customize content based on user requirements407. Generate external assets based on user's element choices:41 - AI images: `python3 <skill_path>/../generate-image/scripts/generate_image.py "prompt" --output ./outputs/figure.png`42 - matplotlib charts: `python3 <skill_path>/scripts/generate_chart.py <type> --data '<json>' --output chart.png`43 - Mermaid diagrams: `bash <skill_path>/scripts/mermaid_to_image.sh diagram.mmd output.png`448. **For documents 5+ pages:** Review the [Long-Form Document Anti-Patterns](#long-form-document-anti-patterns-must-read-for-reports-theses-books) section and run the Content Generation Checklist before compiling. Key rules: prefer prose over bullets, include global list compaction, escape `<`/`>` in text mode, vary section formats, limit `45ewpage`, size images at 0.75-0.85 textwidth.469. Compile with `scripts/compile_latex.sh` (auto-detects XeLaTeX for CJK/RTL, glossaries, bibliography)4710. Show PNG preview to user, deliver PDF4849### Poster Sub-Workflow5051When the user requests a poster: read [references/poster-design-guide.md](references/poster-design-guide.md) for the complete workflow including conference size presets (NeurIPS/ICML/CVPR/ICLR dimensions), layout archetypes (Traditional/BetterPoster/Visual-Heavy), color schemes, and typography standards. Use `poster.tex` (portrait) or `poster-landscape.tex` (landscape). Ask the user for conference/orientation, layout style, and color scheme using AskUserQuestion, then proceed to step 5.5253### Cheat Sheet / Reference Card Sub-Workflow5455When the user requests a cheat sheet, reference card, or formula sheet:56571. Read [references/cheatsheet-guide.md](references/cheatsheet-guide.md) for the complete workflow including template selection, content budgets, typography rules, and the PDF-to-cheatsheet pipeline.582. Select template: `cheatsheet.tex` (general, 3-col landscape), `cheatsheet-exam.tex` (exam formula, 2-col portrait), or `cheatsheet-code.tex` (programming, 4-col landscape).593. Follow the guide's workflow steps, then return to main workflow step 5.6061## Workflow: Mail Merge (Batch Personalized Documents)6263Generate N personalized documents from a LaTeX template + CSV/JSON data source using `scripts/mail_merge.py`. Template syntax: `{{variable}}` for simple substitution, Jinja2 (`<< >>`, `<% %>`) for conditionals/loops. See `assets/templates/mail-merge-letter.tex` for an example. Full guide: [references/interactive-features.md](references/interactive-features.md).6465## Workflow: Version Diffing (latexdiff)6667Generate highlighted change-tracked PDFs using `scripts/latex_diff.sh`. Supports file-to-file diff, git revision diff, multi-file flatten, and custom markup styles. Full guide: [references/interactive-features.md](references/interactive-features.md).6869## Workflow: Convert Document Formats7071Convert between Markdown, DOCX, HTML, and LaTeX using `scripts/convert_document.sh`. Full guide: [references/format-conversion.md](references/format-conversion.md).7273## Workflow: Convert PDF to LaTeX7475Convert existing PDFs (handwritten notes, printed reports, legal docs) to LaTeX. Full pipeline: [references/pdf-conversion.md](references/pdf-conversion.md).7677**Quick steps**: Split PDF into page images (`scripts/pdf_to_images.sh`), select a conversion profile, create shared preamble, apply scaling strategy, validate with `scripts/validate_latex.py`, concatenate, compile.7879**Scaling strategy**: 1-10 pages = single agent; 11-20 pages = split in half (2 agents); 21+ pages = batch-7 pipeline (ceil(N/7) agents with `run_in_background: true`).8081**Conversion profiles** (in `references/profiles/`): `math-notes.md` (equations, theorems -- has beautiful mode), `business-document.md` (reports, memos), `legal-document.md` (contracts, statutes), `general-notes.md` (handwritten, mixed content).8283## Workflow: Fill PDF Forms8485Fill existing PDF forms -- both fillable (with form fields) and non-fillable (image-based). Full guide: [references/pdf-operations.md](references/pdf-operations.md).8687**Step 1: Check form type:**88```bash89python3 <skill_path>/scripts/pdf_check_form.py form.pdf90```9192**If fillable** (has form fields):93```bash94# Extract field metadata95python3 <skill_path>/scripts/pdf_extract_fields.py form.pdf field_info.json96# Create field_values.json with values for each field, then fill97python3 <skill_path>/scripts/pdf_fill_form.py form.pdf field_values.json output.pdf98```99100**If non-fillable** (no form fields):101```bash102# Convert to images for visual analysis103bash <skill_path>/scripts/pdf_to_images.sh form.pdf ./tmp/pages104# Visually identify fields, create fields.json with bounding boxes105# Validate bounding boxes (+ optional validation image)106python3 <skill_path>/scripts/pdf_validate_boxes.py fields.json --image page_1.png --output validation.png --page 1107# Fill with text annotations108python3 <skill_path>/scripts/pdf_fill_annotations.py form.pdf fields.json output.pdf109```110111## Workflow: Advanced PDF Operations112113For text/table extraction (pdfplumber), OCR (pytesseract), programmatic PDF creation (reportlab), watermarking, page rotation/cropping, metadata extraction, JavaScript libraries (pdf-lib, pdfjs-dist), and batch processing, see [references/pdf-operations.md](references/pdf-operations.md).114115## Compile Script116117```bash118# Basic compile (auto-detects engine)119bash <skill_path>/scripts/compile_latex.sh document.tex120121# Compile + generate PNG previews122bash <skill_path>/scripts/compile_latex.sh document.tex --preview123124# Compile + PNG in specific directory125bash <skill_path>/scripts/compile_latex.sh document.tex --preview --preview-dir ./outputs126127# Force a specific engine128bash <skill_path>/scripts/compile_latex.sh document.tex --engine xelatex129bash <skill_path>/scripts/compile_latex.sh document.tex --engine lualatex130131# Use latexmk for automatic multi-pass (recommended for complex documents)132bash <skill_path>/scripts/compile_latex.sh document.tex --use-latexmk --preview133134# PDF/A output for thesis submissions and archival compliance135bash <skill_path>/scripts/compile_latex.sh document.tex --pdfa136137# Verbose output for debugging compilation issues138bash <skill_path>/scripts/compile_latex.sh document.tex --verbose139140# Quiet mode for batch/CI jobs (only errors shown)141bash <skill_path>/scripts/compile_latex.sh document.tex --quiet142143# Clean auxiliary files only (no compilation)144bash <skill_path>/scripts/compile_latex.sh document.tex --clean145```146147### Compilation Flags148149| Flag | Description |150|---|---|151| `--preview` | Generate PNG previews of each page after compilation |152| `--preview-dir DIR` | Directory for PNG output (default: same as .tex file) |153| `--engine ENGINE` | Force engine: `pdflatex`, `xelatex`, or `lualatex` |154| `--use-latexmk` | Use `latexmk` as compilation backend (auto multi-pass, bibliography, index) |155| `--verbose` | Show full compilation output (all engine logs) |156| `--quiet` | Suppress all non-error output |157| `--clean` | Remove auxiliary files (.aux, .log, .bbl, .fdb_latexmk, etc.) and exit |158| `--pdfa` | Produce PDF/A-2b compliant output (auto-injects `pdfx` package) |159| `--auto-fix` | Auto-fix common compilation errors (float placement, encoding) |160161### Compilation Backends162163**Manual multi-pass (default):** Runs the engine multiple times with bibliography/index/glossary passes as needed. This is the traditional approach and works without `latexmk` installed.164165**latexmk (`--use-latexmk`):** Uses `latexmk` for automatic dependency-driven compilation. Recommended for complex documents with bibliographies, indexes, glossaries, or cross-references -- latexmk determines the correct number of passes automatically. Requires `latexmk` (included with TeX Live).166167### Log Filtering (texfot)168169When `texfot` is installed (included with TeX Live), compilation output is automatically filtered to show only relevant warnings and errors, suppressing noisy package loading messages. This applies in the default verbosity mode. Use `--verbose` to see unfiltered output, or `--quiet` to suppress all non-error output.170171**Engine auto-detection**: If the .tex file uses `fontspec`, `xeCJK`, or `polyglossia`, the script automatically uses `xelatex`. If it uses `luacode` or `luatextra`, it uses `lualatex`. Otherwise defaults to `pdflatex`. Override with `--engine`.172173The script auto-installs `texlive` (including `texlive-science`, `texlive-xetex`, `texlive-luatex`, `biber`) and `poppler-utils` if missing. It auto-detects `ibliography{}` (runs bibtex), `ddbibresource{}` (runs biber), `\makeindex` (runs makeindex), `\makeglossaries` (runs makeglossaries), runs the correct number of passes, generates PNG previews with `pdftoppm`, and cleans auxiliary files.174175## Script & Tool Reference176177For PDF utilities (encrypt, merge, optimize, extract pages, pdf-to-images), LaTeX quality tools (lint, word count, analysis, package check, citations), compilation auto-fix, bibliography fetching, and diagram scripts (Mermaid, Graphviz, PlantUML), see [references/script-tools.md](references/script-tools.md).178179## Templates180181Copy from `assets/templates/` and customize.182183### Resume Templates (5 ATS-Compatible Options)184185Select based on experience level, industry, and ATS requirements. See [references/resume-ats-guide.md](references/resume-ats-guide.md) for full ATS guidance.186187| Template | Best For | Key Feature | ATS Score |188|---|---|---|---|189| **`resume-classic-ats.tex`** | Finance, law, government, any ATS portal | Zero graphics, plain text only, maximum parse safety | 10/10 |190| **`resume-modern-professional.tex`** | Tech, corporate, general professional | Subtle color accents, clean design, good ATS + human appeal | 9/10 |191| **`resume-executive.tex`** | VP, Director, C-suite (5-15+ years) | Two-page, executive summary, board roles, P&L focus | 9/10 |192| **`resume-technical.tex`** | Software, data, engineering roles | Skills-first hybrid, projects section, tech stack emphasis | 9/10 |193| **`resume-entry-level.tex`** | New graduates, career starters | Education-first, one page, coursework, activities | 9/10 |194195All 5 templates follow ATS rules: single-column, no graphics/images, no tables for layout, standard section headings, contact info in body (not header/footer).196197### STEM Student Templates198199- **`homework.tex`** -- Homework/assignment submission template (`article` class, 11pt) with toggle-able solutions (`\showsolutionstrue`/`\showsolutionsfalse`), custom problem/solution environments, honor code section, `fancyhdr` headers, `amsmath`+`amssymb`+`amsthm` math, `listings` code highlighting (Python, Java, C++, Matlab styles), `enumitem` for (a), (b), (c) sub-parts, `hyperref`. Customization via `