pdf-engine-fallback
它能做什么
这项技能是 pandoc 生成 PDF 的重试方案,当默认引擎失败时会尝试其他引擎。它适合用于处理非英文或含特殊字符的文档,或自动化流程中的人。
适用场景
- ✓当 pandoc 生成 PDF 时出现错误的时候。
- ✓当文档包含重音字母或非拉丁文字等非 ASCII 文本的时候。
- ✓当我的文档流程需要在配置不同的电脑上生成 PDF 的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-engine-fallback/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“pandoc 无法把我的文档制作成 PDF,文档中包含带重音的字母和中文。请检查可用的引擎,并换一个能处理这些字符的引擎重试。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会先尝试默认转换;失败时检查已安装的 PDF 引擎,然后根据内容选用合适的引擎重试,例如用 xelatex 处理 Unicode,或用 wkhtmltopdf 处理网页式版面。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PDF Engine Fallback
This skill provides a diagnostic-retry workflow for PDF generation when Pandoc's default PDF engine fails. It systematically checks available engines and retries with alternatives optimized for different content types (e.g., xelatex for Unicode).
When to Use
- Pandoc PDF generation fails with errors
- Document contains non-ASCII characters (Unicode, CJK, etc.)
- Need robust PDF generation across different system configurations
- Working in CI/CD or automated document pipelines
Steps
1. Attempt Initial PDF Generation
First, try generating with pandoc's default engine:
pandoc input.md -o output.pdf
2. Diagnose on Failure
If the initial attempt fails, check which PDF engines are available:
# Check for pdflatex
which pdflatex && echo "pdflatex: available" || echo "pdflatex: not found"
# Check for xelatex (better Unicode support)
which xelatex && echo "xelatex: available" || echo "xelatex: not found"
# Check for wkhtmltopdf (HTML-based rendering)
which wkhtmltopdf && echo "wkhtmltopdf: available" || echo "wkhtmltopdf: not found"
3. Retry with Alternative Engine
Based on available engines and document content, retry with an appropriate engine:
# For documents with Unicode/special characters - prefer xelatex
pandoc input.md -o output.pdf --pdf-engine=xelatex
# Alternative: use pdflatex for simple Latin documents
pandoc input.md -o output.pdf --pdf-engine=pdflatex
# For HTML-heavy content or complex layouts
pandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf
4. Handle Missing Engines
If no PDF engines are available, install one:
# Ubuntu/Debian - install texlive with xelatex
sudo apt-get install texlive-xetex
# Or install minimal teTeX
sudo apt-get install texlive-latex-base texlive-latex-extra
# macOS with Homebrew
brew install basictex
Complete Fallback Script
#!/bin/bash
# pdf-fallback.sh - Robust PDF generation with engine fallback
INPUT_FILE="${1:-input.md}"
OUTPUT_FILE="${2:-output.pdf}"
echo "Attempting PDF generation: $INPUT_FILE -> $OUTPUT_FILE"
# Try default engine first
if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" 2>/dev/null; then
echo "SUCCESS: PDF generated with default engine"
exit 0
fi
echo "Default engine failed. Checking available engines..."
# Check and try engines in priority order
if command -v xelatex &>/dev/null; then
echo "Retrying with xelatex (Unicode support)..."
if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=xelatex; then
echo "SUCCESS: PDF generated with xelatex"
exit 0
fi
fi
if command -v pdflatex &>/dev/null; then
echo "Retrying with pdflatex..."
if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=pdflatex; then
echo "SUCCESS: PDF generated with pdflatex"
exit 0
fi
fi
if command -v wkhtmltopdf &>/dev/null; then
echo "Retrying with wkhtmltopdf..."
if pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=wkhtmltopdf; then
echo "SUCCESS: PDF generated with wkhtmltopdf"
exit 0
fi
fi
echo "FAILURE: No available PDF engine succeeded"
echo "Install a PDF engine (texlive-xetex recommended) and retry"
exit 1
Usage
# Make executable
chmod +x pdf-fallback.sh
# Run with defaults (input.md -> output.pdf)
./pdf-fallback.sh
# Run with custom files
./pdf-fallback.sh report.md report.pdf
Engine Selection Guide
| Engine | Best For | Unicode | Speed |
|---|---|---|---|
| xelatex | Non-Latin scripts, modern fonts | Excellent | Moderate |
| pdflatex | Simple Latin documents | Limited | Fast |
| wkhtmltopdf | HTML/CSS styling | Good | Fast |
Troubleshooting
- Font errors: Install required fonts or use xelatex with system fonts
- Package errors: Install missing LaTeX packages via
tlmgr - Large documents: Try pdflatex for speed, xelatex for compatibility
- Citation issues: Ensure pandoc-citeproc or citeproc is installed
常见问题
为什么用 xelatex 处理 Unicode?
指南说,xelatex 完整支持 Unicode,适合带重音和非拉丁文字的内容。
如何检查引擎?
AI 会对每个引擎运行 which 命令,查看是否已安装。
什么时候使用 pdflatex?
指南建议把它用于只有普通拉丁文字的简单文档。
详情
热度
- GitHub 星标
- 7.8k
- 排名
- #12920
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。