latex-build

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LaTeX Build Automation

LaTeX编译自动化

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
当你需要以下操作时使用本技能:
  • 编译LaTeX文档
  • 设置带自动重新编译的实时预览
  • 管理多文件项目
  • 排查编译失败问题
  • 清理编译产物
  • 自动化编译工作流

Quick Reference

快速参考

Why latexmk?

为什么选择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)

行业标准的编译工具:
  • 自动检测依赖项(参考文献、索引等)
  • 自动运行正确次数(处理交叉引用)
  • 实时预览模式可监控文件变化
  • 与Skim配合支持SyncTeX自动重载
  • 随MacTeX捆绑安装(无需单独安装)

Basic Usage

基础用法

One-Time Build

单次编译

bash
latexmk -pdf document.tex
bash
latexmk -pdf document.tex

Result: document.pdf created

结果:生成document.pdf

undefined
undefined

Live Preview (Watch Mode)

实时预览(监控模式)

bash
latexmk -pvc -pdf document.tex
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

- 在Skim阅读器中自动重载PDF


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

---

**停止监控:** 按 `Ctrl+C`

---

Quick Reference Card

快速参考卡片

bash
undefined
bash
undefined

Build once

单次编译

latexmk -pdf document.tex
latexmk -pdf document.tex

Live preview (watch mode)

实时预览(监控模式)

latexmk -pvc -pdf document.tex
latexmk -pvc -pdf document.tex

Build with SyncTeX

带SyncTeX的编译

latexmk -pdf -synctex=1 document.tex
latexmk -pdf -synctex=1 document.tex

Clean artifacts

清理产物

latexmk -c # Keep PDF latexmk -C # Remove PDF too
latexmk -c # 保留PDF latexmk -C # 同时删除PDF

Force rebuild

强制重新编译

latexmk -gg -pdf document.tex
latexmk -gg -pdf document.tex

Non-interactive (for CI)

非交互模式(适用于CI)

latexmk -pdf -interaction=nonstopmode document.tex

---
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

  • 验证latexmk已安装:
    which latexmk
  • 测试基础编译:
    latexmk -pdf document.tex
  • 启用SyncTeX:添加
    -synctex=1
    参数
  • 测试实时预览:
    latexmk -pvc -pdf document.tex
  • 配置Skim以自动重载
  • 创建Makefile用于常见任务(可选)
  • 创建.latexmkrc用于项目特定设置(可选)
  • 测试清理:
    latexmk -c
    可删除产物

Reference Documentation

参考文档

For detailed information, see:
  • Common Commands - Build options and output formats
  • Multi-File Projects - Automatic dependency tracking for complex documents
  • Configuration - .latexmkrc and Makefile integration
  • Troubleshooting - Common build issues and solutions
  • Advanced Patterns - 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

如需详细信息,请查看:
  • 常用命令 - 编译选项及输出格式
  • 多文件项目 - 复杂文档的自动依赖追踪
  • 配置 - .latexmkrc与Makefile集成
  • 故障排查 - 常见编译问题及解决方案
  • 高级模式 - 并行编译与CI/CD集成
官方文档:运行
man latexmk
latexmk -help
获取完整参考
另请参阅
  • 使用
    latex/setup
    技能安装LaTeX并配置环境
  • 使用
    latex/tables
    技能通过tabularray创建表格

Troubleshooting

故障排查

IssueCauseSolution
latexmk not foundNot in PATHAdd
/Library/TeX/texbin
to PATH
Undefined control sequenceMissing packageCheck
\usepackage
statements for required packages
References show ??Need multiple runslatexmk handles this automatically; ensure no errors
Live preview not updatingSkim auto-reload disabledSkim Preferences → Sync → Check for file changes
Build hangsInput prompt in nonstop modeUse
-interaction=nonstopmode
flag
PDF not updatingBuild error preventing outputCheck .log file for specific error
SyncTeX not workingMissing -synctex=1 flagAdd
-synctex=1
to build command
Too many aux filesNormal build artifactsRun
latexmk -c
to clean (keeps PDF)
问题原因解决方案
latexmk未找到不在PATH中
/Library/TeX/texbin
添加到PATH
未定义的控制序列缺少宏包检查
\usepackage
语句是否包含所需宏包
参考文献显示??需要多次编译latexmk会自动处理此问题;确保编译无错误
实时预览未更新Skim自动重载已禁用Skim偏好设置 → 同步 → 勾选“检查文件变化”
编译挂起非交互模式下出现输入提示使用
-interaction=nonstopmode
参数
PDF未更新编译错误导致无法生成输出查看.log文件获取具体错误信息
SyncTeX无法工作缺少
-synctex=1
参数
在编译命令中添加
-synctex=1
过多aux文件正常的编译产物运行
latexmk -c
清理(保留PDF)