pandoc-pdf-error-resolution
它能做什么
这项技能为错误信息不清楚的 pandoc PDF 转换问题提供了结构化的解决方法。适合转换文档为 PDF 时看到未知错误提示的人。
适用场景
- ✓当 pandoc 在 PDF 转换时返回未知错误时。
- ✓当同一份文档能转换为 HTML 或 Markdown,却无法转换为 PDF 时。
- ✓当我需要找出这台电脑上哪个 PDF 引擎可用时。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pandoc-pdf-error-resolution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我:pandoc 无法把我的文档转换为 PDF,只提示未知错误。请找出可用的 PDF 引擎并生成文件。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 检查 pandoc 版本,查找 pdflatex、xelatex、lualatex 和 wkhtmltopdf,用指定的引擎重新转换,并读取错误信息以决定要修改什么。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Pandoc PDF Error Resolution
This skill provides a step-by-step workflow for diagnosing and resolving "unknown error" messages when using pandoc to generate PDFs.
When to Use
Use this skill when:
- Pandoc returns an "unknown error" during PDF conversion
- The conversion succeeds for other formats (e.g., markdown, HTML) but fails for PDF
- You need to identify which PDF engine is available and working
Step-by-Step Procedure
Step 1: Verify Pandoc Installation
First, confirm pandoc is installed and check its version:
pandoc --version
This confirms pandoc is available and shows the version number. Note that pandoc itself doesn't generate PDFs directly—it delegates to external PDF engines.
Step 2: Check Available PDF Engines
Identify which PDF engines are installed on the system:
which pdflatex xelatex lualatex wkhtmltopdf pdfroff 2>/dev/null || echo "Checking individual engines..."
which pdflatex
which xelatex
which lualatex
which wkhtmltopdf
Common engines and their characteristics:
- pdflatex: Fast, widely available, good for basic documents
- xelatex: Better Unicode/font support, recommended for complex documents
- lualatex: Advanced typography, Lua scripting support
- wkhtmltopdf: HTML-to-PDF conversion, good for web-style documents
Step 3: Attempt Conversion with Explicit Engine
Retry the conversion with an explicit --pdf-engine flag:
pandoc input.md -o output.pdf --pdf-engine=xelatex
Try engines in this order:
xelatex(best Unicode support)pdflatex(most widely available)lualatex(if xelatex fails)wkhtmltopdf(for HTML-heavy content)
Step 4: Capture Full stderr Output
Always capture the complete error output before falling back:
pandoc input.md -o output.pdf --pdf-engine=xelatex 2>&1 | tee pandoc_error.log
This preserves the full error message for analysis. Common error patterns:
- Font errors: Missing LaTeX packages or fonts
- Package errors: Missing LaTeX packages (use
tlmgr install <package>) - Syntax errors: Issues in the source document
Step 5: Install Missing Dependencies (if needed)
If errors indicate missing LaTeX packages:
# For TeX Live
tlmgr install <package-name>
# For Debian/Ubuntu
apt-get install texlive-latex-extra texlive-fonts-recommended
# For macOS with Homebrew
brew install --cask mactex
Step 6: Fallback Strategies
If all engines fail, consider:
- Convert to HTML first, then use wkhtmltopdf
- Simplify the document (remove complex formatting)
- Use an online conversion service
- Generate PDF from a different format (e.g., DOCX via LibreOffice)
Example Complete Workflow
#!/bin/bash
# pandoc-pdf-debug.sh
INPUT_FILE="$1"
OUTPUT_FILE="${INPUT_FILE%.md}.pdf"
echo "=== Pandoc PDF Conversion Debug ==="
echo "Input: $INPUT_FILE"
echo "Output: $OUTPUT_FILE"
# Step 1: Verify pandoc
echo -e "\n[1] Checking pandoc version..."
pandoc --version | head -1
# Step 2: Check engines
echo -e "\n[2] Checking available PDF engines..."
for engine in pdflatex xelatex lualatex wkhtmltopdf; do
if which "$engine" &>/dev/null; then
echo " ✓ $engine: $(which $engine)"
else
echo " ✗ $engine: not found"
fi
done
# Step 3: Try conversion with xelatex
echo -e "\n[3] Attempting conversion with xelatex..."
pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=xelatex 2>&1 | tee /tmp/pandoc_error.log
if [ $? -eq 0 ]; then
echo "✓ Conversion successful!"
else
echo "✗ Conversion failed. Check /tmp/pandoc_error.log for details"
echo "Attempting fallback with pdflatex..."
pandoc "$INPUT_FILE" -o "$OUTPUT_FILE" --pdf-engine=pdflatex 2>&1
fi
Quick Reference
| Command | Purpose |
|---|---|
pandoc --version |
Verify pandoc installation |
which xelatex |
Check if xelatex engine exists |
pandoc file.md -o file.pdf --pdf-engine=xelatex |
Convert with explicit engine |
... 2>&1 | tee error.log |
Capture full stderr output |
tlmgr install <pkg> |
Install missing LaTeX package |
常见问题
pandoc 自己能生成 PDF 吗?
不能。指南说明 pandoc 会把生成工作交给外部 PDF 引擎完成。
为什么要检查其他格式?
如果其他格式可以正常转换,问题很可能出在 PDF 引擎,而不是文档本身。
哪个引擎对 Unicode 更好?
指南称 xelatex 比 pdflatex 具有更好的 Unicode 和字体支持。
详情
热度
- GitHub 星标
- 7.8k
- 排名
- #12905
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。