latex-build
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaTeX 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.texbash
latexmk -pdf document.texResult: document.pdf created
结果:生成document.pdf
undefinedundefinedLive Preview (Watch Mode)
实时预览(监控模式)
bash
latexmk -pvc -pdf document.texbash
latexmk -pvc -pdf document.texWhat 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
undefinedbash
undefinedBuild 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 flag
-synctex=1 - 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: removes artifacts
latexmk -c
- 验证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 or for complete reference
man latexmklatexmk -helpSee Also:
- Use skill for installing LaTeX and configuring environment
latex/setup - Use skill for creating tables with tabularray
latex/tables
如需详细信息,请查看:
- 常用命令 - 编译选项及输出格式
- 多文件项目 - 复杂文档的自动依赖追踪
- 配置 - .latexmkrc与Makefile集成
- 故障排查 - 常见编译问题及解决方案
- 高级模式 - 并行编译与CI/CD集成
官方文档:运行 或 获取完整参考
man latexmklatexmk -help另请参阅:
- 使用 技能安装LaTeX并配置环境
latex/setup - 使用 技能通过tabularray创建表格
latex/tables
Troubleshooting
故障排查
| Issue | Cause | Solution |
|---|---|---|
| latexmk not found | Not in PATH | Add |
| Undefined control sequence | Missing package | Check |
| 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 |
| PDF not updating | Build error preventing output | Check .log file for specific error |
| SyncTeX not working | Missing -synctex=1 flag | Add |
| Too many aux files | Normal build artifacts | Run |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| latexmk未找到 | 不在PATH中 | 将 |
| 未定义的控制序列 | 缺少宏包 | 检查 |
| 参考文献显示?? | 需要多次编译 | latexmk会自动处理此问题;确保编译无错误 |
| 实时预览未更新 | Skim自动重载已禁用 | Skim偏好设置 → 同步 → 勾选“检查文件变化” |
| 编译挂起 | 非交互模式下出现输入提示 | 使用 |
| PDF未更新 | 编译错误导致无法生成输出 | 查看.log文件获取具体错误信息 |
| SyncTeX无法工作 | 缺少 | 在编译命令中添加 |
| 过多aux文件 | 正常的编译产物 | 运行 |