home / skills / terrylica / cc-skills / latex-build

This skill automates LaTeX builds with latexmk and enables live preview, simplifying multi-file projects and troubleshooting compilation.

npx playbooks add skill terrylica/cc-skills --skill latex-build

Review the files below or copy the command above to add this skill to your agents.

Files (6)
SKILL.md
3.9 KB
---
name: latex-build
description: LaTeX builds with latexmk and live preview. TRIGGERS - latexmk, LaTeX build, live preview, compilation.
allowed-tools: Read, Edit, Bash
---

# LaTeX Build Automation

## When to Use This Skill

Use this skill when:

- Compiling LaTeX documents
- Setting up live preview with auto-rebuild
- Managing multi-file projects
- Troubleshooting build failures
- Cleaning build artifacts
- Automating compilation workflows

## Quick Reference

## Why latexmk?

Industry standard build tool:

- Auto-detects dependencies (bibliography, index, etc.)
- Runs correct number of times (handles cross-references)
- Live preview mode watches for file changes
- Works with Skim for SyncTeX auto-reload
- Bundled with MacTeX (no separate install needed)

---

## Basic Usage

### One-Time Build

```bash
latexmk -pdf document.tex
# Result: document.pdf created
```

### Live Preview (Watch Mode)

```bash
latexmk -pvc -pdf document.tex

# What happens:
# - Compiles document initially
# - Watches for file changes
# - Auto-recompiles when files change
# - Auto-reloads PDF in Skim viewer
```

**Stop watching:** Press `Ctrl+C`

---

## Quick Reference Card

```bash
# Build once
latexmk -pdf document.tex

# Live preview (watch mode)
latexmk -pvc -pdf document.tex

# Build with SyncTeX
latexmk -pdf -synctex=1 document.tex

# Clean artifacts
latexmk -c              # Keep PDF
latexmk -C              # Remove PDF too

# Force rebuild
latexmk -gg -pdf document.tex

# Non-interactive (for CI)
latexmk -pdf -interaction=nonstopmode document.tex
```

---

## Build Checklist

- [ ] Verify latexmk installed: `which latexmk`
- [ ] Test basic build: `latexmk -pdf document.tex`
- [ ] Enable SyncTeX: Add `-synctex=1` flag
- [ ] Test live preview: `latexmk -pvc -pdf document.tex`
- [ ] Configure Skim for auto-reload
- [ ] Create Makefile for common tasks (optional)
- [ ] Create .latexmkrc for project-specific settings (optional)
- [ ] Test clean: `latexmk -c` removes artifacts

---

## Reference Documentation

For detailed information, see:

- [Common Commands](./references/common-commands.md) - Build options and output formats
- [Multi-File Projects](./references/multi-file-projects.md) - Automatic dependency tracking for complex documents
- [Configuration](./references/configuration.md) - .latexmkrc and Makefile integration
- [Troubleshooting](./references/troubleshooting.md) - Common build issues and solutions
- [Advanced Patterns](./references/advanced-patterns.md) - Parallel builds and CI/CD integration

**Official Docs**: Run `man latexmk` or `latexmk -help` for complete reference

**See Also**:

- Use `latex/setup` skill for installing LaTeX and configuring environment
- Use `latex/tables` skill for creating tables with tabularray

---

## Troubleshooting

| Issue                      | Cause                         | Solution                                             |
| -------------------------- | ----------------------------- | ---------------------------------------------------- |
| latexmk not found          | Not in PATH                   | Add `/Library/TeX/texbin` to PATH                    |
| Undefined control sequence | Missing package               | Check `\usepackage` statements for required packages |
| References show ??         | Need multiple runs            | latexmk handles this automatically; ensure no errors |
| Live preview not updating  | Skim auto-reload disabled     | Skim Preferences → Sync → Check for file changes     |
| Build hangs                | Input prompt in nonstop mode  | Use `-interaction=nonstopmode` flag                  |
| PDF not updating           | Build error preventing output | Check .log file for specific error                   |
| SyncTeX not working        | Missing -synctex=1 flag       | Add `-synctex=1` to build command                    |
| Too many aux files         | Normal build artifacts        | Run `latexmk -c` to clean (keeps PDF)                |

Overview

This skill automates LaTeX builds using latexmk and provides a live preview workflow for fast iteration. It handles dependency detection, correct multi-pass compilation, SyncTeX integration, and artifact cleanup to keep projects tidy. Use it to add repeatable, CI-friendly LaTeX compilation and reliable local live-preview capabilities.

How this skill works

The skill runs latexmk with configurable flags to perform one-time builds or a persistent watch (-pvc) that auto-recompiles on file changes and triggers viewer reloads. It supports SyncTeX for source↔︎PDF synchronization, non-interactive modes for CI, force-rebuilds, and cleaning commands to remove auxiliary files. Project-level settings can be supplied via a .latexmkrc or Makefile to standardize behavior.

When to use it

  • Compile a single LaTeX document to PDF reliably
  • Set up live preview while editing complex documents
  • Automate multi-file project builds with correct dependency handling
  • Run non-interactive builds in CI/CD pipelines
  • Clean build artifacts before packaging or commit

Best practices

  • Verify latexmk is in PATH before automating builds (which latexmk)
  • Enable SyncTeX (-synctex=1) for editor↔︎PDF sync and accurate jumps
  • Use -interaction=nonstopmode for CI to avoid prompts and capture logs
  • Create a .latexmkrc for project-specific flags and a Makefile for common tasks
  • Regularly run latexmk -c or -C to remove stale auxiliary files and keep repo clean

Example use cases

  • Quick one-off build: latexmk -pdf document.tex to produce a PDF
  • Live preview during drafting: latexmk -pvc -pdf document.tex to auto-recompile on edits
  • CI job: latexmk -pdf -interaction=nonstopmode document.tex to build without user interaction
  • Force a full rebuild when dependencies change: latexmk -gg -pdf document.tex
  • Clean artifacts before release: latexmk -C to remove PDF and auxiliary files

FAQ

Why use latexmk instead of calling pdflatex manually?

latexmk auto-detects dependencies and runs the correct sequence and number of passes (bibliographies, indices, cross-references), reducing manual steps and errors.

How do I stop the live preview watch mode?

Interrupt the process with Ctrl+C in the terminal running latexmk -pvc. The viewer stays open with the last PDF until you close it.