| name | pdf-engine-fallback |
| description | Retry PDF generation with alternative engines when pandoc fails |
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:
which pdflatex && echo "pdflatex: available" || echo "pdflatex: not found"
which xelatex && echo "xelatex: available" || echo "xelatex: not found"
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:
pandoc input.md -o output.pdf --pdf-engine=xelatex
pandoc input.md -o output.pdf --pdf-engine=pdflatex
pandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf
4. Handle Missing Engines
If no PDF engines are available, install one:
sudo apt-get install texlive-xetex
sudo apt-get install texlive-latex-base texlive-latex-extra
brew install basictex
Complete Fallback Script
#!/bin/bash
INPUT_FILE="${1:-input.md}"
OUTPUT_FILE="${2:-output.pdf}"
echo "Attempting PDF generation: $INPUT_FILE -> $OUTPUT_FILE"
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..."
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;
0
-v wkhtmltopdf &>/dev/null;
pandoc -o --pdf-engine=wkhtmltopdf;
0
1
Usage
chmod +x pdf-fallback.sh
./pdf-fallback.sh
./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