Retry PDF generation with alternative engines when pandoc fails
64
76%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Medium
Suggest reviewing before use
Fix and improve this skill with Tessl
tessl review fix ./benchmarks/gdpval/skills/pdf-engine-fallback/SKILL.mdThis 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).
First, try generating with pandoc's default engine:
pandoc input.md -o output.pdfIf 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"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=wkhtmltopdfIf 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#!/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# 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 | Best For | Unicode | Speed |
|---|---|---|---|
| xelatex | Non-Latin scripts, modern fonts | Excellent | Moderate |
| pdflatex | Simple Latin documents | Limited | Fast |
| wkhtmltopdf | HTML/CSS styling | Good | Fast |
tlmgrc5a9c4b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.