latex-document
git clone https://github.com/ndpvt-web/latex-document-skill
git clone --depth=1 https://github.com/ndpvt-web/latex-document-skill ~/.claude/skills/ndpvt-web-latex-document-skill-latex-document
SKILL.mdLaTeX 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
or write from scratchassets/templates/ - 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
- AI images:
- 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>
, size images at 0.75-0.85 textwidth.\newpage - Compile with
(auto-detects XeLaTeX for CJK/RTL, glossaries, bibliography)scripts/compile_latex.sh - 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:
(general, 3-col landscape),cheatsheet.tex
(exam formula, 2-col portrait), orcheatsheet-exam.tex
(programming, 4-col landscape).cheatsheet-code.tex - 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 |
|---|---|
| Generate PNG previews of each page after compilation |
| Directory for PNG output (default: same as .tex file) |
| Force engine: , , or |
| Use as compilation backend (auto multi-pass, bibliography, index) |
| Show full compilation output (all engine logs) |
| Suppress all non-error output |
| Remove auxiliary files (.aux, .log, .bbl, .fdb_latexmk, etc.) and exit |
| Produce PDF/A-2b compliant output (auto-injects package) |
| 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 (
): Uses --use-latexmk
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 \bibliography{} (runs bibtex), \addbibresource{} (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 |
|---|---|---|---|
| Finance, law, government, any ATS portal | Zero graphics, plain text only, maximum parse safety | 10/10 |
| Tech, corporate, general professional | Subtle color accents, clean design, good ATS + human appeal | 9/10 |
| VP, Director, C-suite (5-15+ years) | Two-page, executive summary, board roles, P&L focus | 9/10 |
| Software, data, engineering roles | Skills-first hybrid, projects section, tech stack emphasis | 9/10 |
| 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/assignment submission template (homework.tex
class, 11pt) with toggle-able solutions (article
/\showsolutionstrue
), custom problem/solution environments, honor code section,\showsolutionsfalse
headers,fancyhdr
+amsmath
+amssymb
math,amsthm
code highlighting (Python, Java, C++, Matlab styles),listings
for (a), (b), (c) sub-parts,enumitem
. Customization viahyperref
,\coursename
,\assignmentnumber
,\studentname
,\studentid
. Example problems: calculus, proof by induction, Python coding, matrix algebra, kinematics, Java OOP.\duedate
-- STEM lab report template (lab-report.tex
class, 11pt) witharticle
for uncertainties and SI units,siunitx
for data visualization,pgfplots
for professional tables,booktabs
for equations,amsmath
headers,fancyhdr
+caption
for figures. Structured sections: abstract, theory, procedure, data/results (with uncertainty tables), analysis (pgfplots graphs), discussion (error analysis), conclusion, references, appendix. Example: pendulum period measurement with error propagation.subcaption
Other Templates
-- Beautiful lecture notes (lecture-notes.tex
KOMA-Script class) with Palatino font,scrartcl
typography, color-codedmicrotype
theorem environments (blue theorems, green definitions, orange examples, purple remarks), TikZ graph theory diagram styles and macros (tcolorbox
,\CompleteGraph
,\CycleGraph
), styled section headings with\PathGraph
,titlesec
headers,fancyhdr
+hyperref
navigation. Ideal for converting handwritten math/science notes to beautiful PDFs. Includes graph theory custom commands (cleveref
,\V
,\E
,\deg
). Used by the math-notes conversion profile in beautiful mode.\chr
-- Thesis/dissertation (thesis.tex
class) with title page, declaration, abstract, acknowledgments, TOC, list of figures/tables, chapters, appendices, bibliography. Front matter uses roman numerals, main matter uses arabic. Includes theorem environments.book
-- Multi-page academic CV with publications (journal/conference/preprint sections), grants and funding, teaching, advising (current/graduated students), awards, professional service, invited talks. ORCID and Google Scholar links.academic-cv.tex
-- Full book (book.tex
class) with half-title, title page, copyright page, dedication, preface, acknowledgments, TOC, list of figures/tables, parts, chapters, appendix, bibliography, index. Custom chapter headings, epigraphs, fancyhdr, microtype.book
-- Conference poster (poster.tex
class, A0 portrait) with 2-column layout, QR code, 5 color schemes, tikzfigure charts, tables, coloredbox highlights. Includes commented #BetterPoster layout variant (central billboard + sidebars). Portrait is standard for most conferences. See poster design guide for conference size presets.tikzposter
-- Landscape conference poster (poster-landscape.tex
class, A0 landscape) with 3-column (30/40/30) layout, QR code, tech purple color scheme. For CS/ML conferences (NeurIPS, ICML, CVPR, ICLR). Includes commentedtikzposter
presets for CVPR/NeurIPS custom sizes.\geometry{}
-- General reference card (cheatsheet.tex
class, landscape A4, 7pt base font) with 3-columnextarticle
layout,multicols
colored section boxes, tight spacing. For command references, concept summaries, quick-reference guides. Supports front+back printing.tcolorbox
-- Exam formula sheet (cheatsheet-exam.tex
class, portrait A4, 6pt base font) with 2-column layout, maximum content density, black-and-white printer-safe. For university exam "allowed cheat sheets" with formulas, theorems, definitions. Optimized for single-sided printing.extarticle
-- Programming reference card (cheatsheet-code.tex
class, landscape A4, 7pt base font) with 4-column layout,extarticle
syntax highlighting, monospace font emphasis. For language syntax, API reference, CLI commands, keyboard shortcuts.minted
-- Formal business letter with colored letterhead bar, TikZ logo placeholder, company info, recipient block, date, subject line, signature. Professional corporate appearance.letter.tex
-- Exam/quiz (exam.tex
class) with grading table, multiple question types (multiple choice, true/false, fill-in-blank, matching, short answer, essay), point values, solution toggle viaexam
.\printanswers
-- Business report with TOC, headers/footers, data tables, bar chart (pgfplots), process flowchart (TikZ), recommendationsreport.tex
-- Professional cover letter with sender/recipient blockscover-letter.tex
-- Invoice with company header, line items table, subtotal/tax/totalinvoice.tex
-- Research paper with abstract, sections, bibliography, figures. Includes exampleacademic-paper.tex
file (.bib
) for BibTeX citations.references.bib
-- Beamer presentation with title slide, content frames, columnspresentation.tex
-- Fillable PDF form (fillable-form.tex
class) with hyperref form fields: text inputs, checkboxes, radio buttons, dropdowns, push buttons. Two-column layout witharticle
. Customtabularx
,\FormField
,\FormCheck
helper commands. Requires Adobe Reader for full form support (browser PDF viewers have limited form capabilities).\FormDropdown
-- Configurable document (conditional-document.tex
class) with etoolbox toggle system: show/hide TOC, appendix, watermark, draft mode, confidential marking, abstract. Template variables viaarticle
(title, author, org, version). Three visual profiles (corporate, academic, minimal). Supports command-line variable passing for CI/CD.\providecommand
-- Mail merge letter template withmail-merge-letter.tex
placeholders for use with{{variable}}
. Company-branded letterhead, recipient address block, body text with data-driven personalization. Pair with CSV/JSON data source.scripts/mail_merge.py
-- Legacy resume template (has photo area and tables -- not ATS-optimized)resume.tex
Usage:
cp <skill_path>/assets/templates/resume-classic-ats.tex ./outputs/my_resume.tex # Edit content, then compile bash <skill_path>/scripts/compile_latex.sh ./outputs/my_resume.tex --preview --preview-dir ./outputs
Document Type Selection
| User Request | Template | Document Class |
|---|---|---|
| Resume, CV (ATS-safe) | | |
| Resume (modern look) | | |
| Resume (senior/executive) | | |
| Resume (technical/engineering) | | |
| Resume (new graduate) | | |
| Homework, assignment, problem set | | |
| Lab report, experiment writeup | | |
| Lecture notes, math notes (beautiful) | | |
| Thesis, dissertation | | |
| Academic CV (publications, grants) | | |
| Report, analysis | | |
| Cover letter | | |
| Invoice | | |
| Academic paper | + | |
| Book | | |
| Scientific poster (portrait) | | |
| Scientific poster (landscape) | | |
| Cheat sheet, reference card | | |
| Exam formula sheet, crib sheet | | |
| Programming reference card | | |
| Formal business letter | | |
| Exam, quiz, test | | |
| Slides, presentation | | |
| Fillable PDF form | | |
| Conditional/configurable document | | |
| Mail merge, batch letters | + | |
| Version diff (latexdiff) | Use + see interactive-features.md | varies |
| Convert PDF to LaTeX | Select profile + see pdf-conversion.md | varies |
| Convert formats | Use + see format-conversion.md | varies |
| Mail merge from CSV/JSON | Use + see interactive-features.md | varies |
Key LaTeX Patterns
Escaping Special Characters
Always escape:
% → \%, $ → \$, & → \&, # → \#, _ → \_
Angle brackets in text mode:
< and > are NOT valid in LaTeX text mode with T1 encoding. They render as inverted question marks (¡ or ¿). Always use math mode or text commands:
→<5%
or$<$5\%\textless 5\%
→>50
or$>$50\textgreater 50
→<$300$<$\$300
→>=
,$\geq$
→<=$\leq$
This is one of the most common silent errors in generated LaTeX — the document compiles without errors but the PDF shows garbage characters.
Date ranges use en-dash:
2019--2025 (double hyphen).
Standard Preamble
\documentclass[11pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{geometry} \usepackage{hyperref} \usepackage{xcolor} \usepackage{graphicx} \usepackage{tabularx} \usepackage{colortbl} \usepackage{enumitem} \usepackage{titlesec}
Code Patterns (load as needed)
For ready-to-use LaTeX code snippets (tables, charts, flowcharts, bibliography, watermarks, landscape pages, multi-language, images, Mermaid diagrams, matplotlib charts, CSV tables, AI images, fillable forms, conditional content, mail merge, version diff), read references/code-patterns.md.
Visual Elements in Reports
When creating reports, use the enrichment elements the user selected in step 4. For the quick reference table of visual element tools (charts, flowcharts, AI images, tables, timelines) and sizing guidelines, see references/advanced-features.md. Use
\begin{figure}[H] (from float package) to prevent figures from floating. Size TikZ diagrams with width=0.8\textwidth or smaller.
Reference Guides (load as needed)
When uncertain about LaTeX patterns, compilation issues, or document quality, consult this table and load relevant files.
| Topic | File | When to Read |
|---|---|---|
| Long-Form Best Practices | long-form-best-practices.md | MUST READ for 5+ page documents: 9 anti-patterns, report preamble, content generation checklist |
| Code Patterns (LaTeX snippets) | code-patterns.md | Ready-to-use LaTeX code: tables, charts, flowcharts, bibliography, watermarks, landscape, multi-lang, images, forms, mail merge, diffs |
| Script & Tool Reference | script-tools.md | PDF utilities (encrypt, merge, optimize, extract), LaTeX quality tools (lint, wordcount, analysis), compilation auto-fix, bibliography, diagrams |
| Bibliography/Citations | bibliography-guide.md | BibTeX/biblatex, citation styles, .bib format |
| Advanced Features & Visual Elements | advanced-features.md | Watermarks, landscape, multi-lang, code, algorithms, tcolorbox, siunitx, advanced charts, AI images, visual elements reference table |
| Mermaid Diagrams | mermaid-diagrams.md | Flowcharts, sequence, class, ER, Gantt, pie, mindmap |
| Python Charts (matplotlib) | python-charts.md | Bar, line, scatter, pie, heatmap, box, histogram, area, radar |
| Format Conversion (Pandoc) | format-conversion.md | Markdown/DOCX/HTML to/from LaTeX |
| Tables and Images | tables-and-images.md | Colored rows, multi-row/column, booktabs, long tables, images, TikZ |
| Charts and Graphs (pgfplots) | charts-and-graphs.md | Line plots, bar charts, scatter plots, pie charts in pgfplots |
| LaTeX Packages | packages.md | Common packages reference |
| Poster Design Guide | poster-design-guide.md | Conference size presets, typography, color schemes, layout archetypes, content guidelines |
| Resume ATS Guide | resume-ats-guide.md | ATS rules, LaTeX pitfalls, keywords |
| PDF-to-LaTeX Pipeline | pdf-conversion.md | Full conversion pipeline, scaling strategy, worker agents, validation |
| Interactive Features | interactive-features.md | Fillable PDF forms, conditional content, mail merge from CSV/JSON, latexdiff version tracking |
| Cheat Sheet Design | cheatsheet-guide.md | Template selection, typography, density optimization, PDF-to-cheatsheet pipeline |
| PDF-to-Cheatsheet Prompts | pdf-extraction-prompts.md | LLM prompts for extraction stages: structure analysis, subject-specific extraction, compression, formatting |
| Visual Packages (TikZ) | visual-packages.md | 24 installed TikZ/visualization packages with working examples |
| Graphviz & PlantUML | graphviz-plantuml.md | .dot to PDF/PNG, .puml to PDF/PNG, LaTeX integration |
| Debugging & Errors | debugging-guide.md | Reading LaTeX errors, 20 common errors, .log analysis, silent failures |
| Accessibility & PDF/A | accessibility-guide.md | PDF/A for thesis, PDF/UA for screen readers, tagged PDFs, alt text |
| Beamer Presentations | beamer-guide.md | Themes, overlays/animations, code slides, handouts, presenter notes |
| Font Selection | font-guide.md | Font families, fontspec, mathematical fonts, fontawesome5, microtype, CJK |
| Collaboration & CI/CD | collaboration-guide.md | Git for LaTeX, GitHub Actions, Docker, multi-author workflows |
| PDF Operations | pdf-operations.md | Form filling (fillable + non-fillable), text/table extraction (pdfplumber), OCR (pytesseract), programmatic PDF creation (reportlab), watermarking, rotation/cropping, metadata, JavaScript (pdf-lib, pdfjs-dist), batch processing, performance tips |
Critical Notes and Common Mistakes
Compile & Output
- Run compile script from the directory containing the .tex file, or use absolute paths
- Place output .tex files in
for user visibility./outputs/ - After compilation, read the PNG preview files to show the user how the document looks
- PNG previews require
(auto-installed by script)poppler-utils
Package Dependency Errors (MUST READ)
These cause
Undefined control sequence -- always include the required package:
| If you use... | You MUST include | Error without it |
|---|---|---|
| | Undefined control sequence |
in .bib with natbib | | Undefined control sequence |
| | Undefined control sequence |
| | Unknown float option |
| or | Undefined control sequence |
hyperref Package
is fine for normal documents (most templates use it).hyperref- Only avoid it in PDF-to-LaTeX converted documents with theorem environments, where it causes
errors.\set@color
Compilation Environment
- If texlive is not installed, the compile script auto-installs it. Do NOT run multiple compile commands in parallel before texlive is installed -- they will all try to install simultaneously, causing dpkg lock contention. Install once first or run compiles sequentially.
- The compile script uses
(not-interaction=nonstopmode
) to ensure PDFs are produced even with warnings. This is intentional -- many documents produce warnings on first pass that resolve on subsequent passes.-halt-on-error - latexmk and texfot are included with TeX Live. The setup script (
) verifies their availability. latexmk is used whensetup.sh
is passed; texfot is used automatically when available (default verbosity mode).--use-latexmk - A
configuration file is included at the skill root to suppress common false positives when linting generated LaTeX documents. The.chktexrc
script uses it automatically.latex_lint.sh
Long-Form Document Anti-Patterns
For documents 5+ pages (reports, theses, books), read references/long-form-best-practices.md for 9 critical anti-patterns, the report preamble best practices, and the content generation checklist. This is MUST-READ material before generating any long document.