[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KFCQ05FRRM04M64TYQVX5N":3,"skill-same:01M6KFCQ05FRRM04M64TYQVX5N":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":26,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":49,"ownerDescription":50,"updatedAt":51,"install":52,"resources":65},"01M6KFCQ05FRRM04M64TYQVX5N","document-gen-resilient-multiformat",null,"Resilient multi-format document generation with environment checks, auto-sanitization, and fallback engines","xyliu-cs\u002FOpenSpace-GDPval","xyliu-cs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F89236536?v=4","01M6KF8Z1V4TXS86CKSH48BY8T","xy","01M6KF8Z67443W0SHXM85JEF0B",0,"MIT","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-618c9b\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000002","文档处理","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[27,28,29,30,31,32,33,34,35,36,37,38],"document","document gen resilient multiformat","document gen resilient","format","environment","auto","fallback","generation","multi","document generation","with","sanitization","2026-11-10 10:12:30",false,"---\nname: document-gen-resilient-multiformat\ndescription: Resilient multi-format document generation with environment checks, auto-sanitization, and fallback engines\n---\n\n# Resilient Document Generation Workflow (Multi-Format + Unicode-Safe)\n\n## When to Use\n\nUse this skill when generating documents in multiple formats (`.docx`, `.pdf`, `.html`) and you need:\n- **Reliable execution** with pre-flight environment verification\n- **Automatic Unicode handling** based on target format\n- **Fallback options** when primary tools (pandoc\u002FLaTeX) are unavailable\n- **Clear error isolation** through discrete, observable steps\n\n**Trigger this workflow when:**\n- `shell_agent` returns unknown\u002Funclear errors on document generation\n- You need multiple output formats from one source\n- Documents contain special characters, symbols, or non-ASCII text\n- Previous PDF generation attempts failed due to encoding or missing dependencies\n\n## Pre-Flight Environment Check\n\n**Before starting**, verify your environment has the required tools:\n\n```\nrun_shell\ncommand: which pandoc && pandoc --version | head -1\n```\n\n```\nrun_shell\ncommand: which pdflatex || which xelatex || which wkhtmltopdf || echo \"No PDF engine found\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import fpdf; print('fpdf2 available')\" 2>\u002Fdev\u002Fnull || echo \"fpdf2 not available\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import reportlab; print('reportlab available')\" 2>\u002Fdev\u002Fnull || echo \"reportlab not available\"\n```\n\n**If pandoc is missing:** Install via `apt-get install pandoc` or `brew install pandoc`\n\n**If no PDF engine found:** Choose fallback approach:\n- Install LaTeX: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- Or use wkhtmltopdf: `apt-get install wkhtmltopdf`\n- Or use Python fallback (fpdf2\u002Freportlab) - see Alternative PDF Generation section\n\n## Core Technique\n\nSplit the workflow into discrete, observable steps with automatic format detection:\n1. **Environment check** → Verify tools are available\n2. **Content creation** → Use `write_file` to create source Markdown\n3. **Auto-sanitization** → Conditionally sanitize based on target format (PDF needs it, DOCX\u002FHTML don't)\n4. **Format conversion** → Use appropriate tool for each format with fallback options\n5. **Verification** → Check output files exist and validate content\n\n## ⚠️ Unicode & Format Compatibility Matrix\n\n| Format | Unicode Support | Sanitization Needed | Recommended Engine |\n|--------|-----------------|---------------------|-------------------|\n| `.docx` | Excellent | No | pandoc (default) |\n| `.html` | Excellent | No | pandoc (default) |\n| `.pdf` | Limited (LaTeX) | **Yes** | xelatex > pdflatex > wkhtmltopdf > fpdf2 |\n| `.pptx` | Good | No | pandoc (if available) or python-pptx |\n\n### Critical Unicode Characters for PDF\n\n| Character | Issue | Safe Replacement |\n|-----------|-------|------------------|\n| `—` (em dash) | May not render | `--` or `-` |\n| `–` (en dash) | May not render | `-` |\n| `\" \"` (curly quotes) | Encoding errors | `\" \"` (straight quotes) |\n| `' '` (curly apostrophe) | Encoding errors | `'` (straight apostrophe) |\n| `…` (ellipsis) | May not render | `...` |\n| `→` `←` `↑` `↓` (arrows) | LaTeX incompatibility | `->` `\u003C-` `^` `v` |\n| `✓` `✗` (checkmarks) | May not render | `[x]` `[ ]` |\n| `★` `●` (symbols) | May not render | `*` `-` |\n| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\n| Non-ASCII letters (é, ñ, ü) | Font-dependent | Use xeLaTeX or replace |\n\n## Step-by-Step Workflow\n\n### Step 0: Pre-Flight Check\n\nVerify environment before proceeding:\n\n```\nrun_shell\ncommand: pandoc --version >\u002Fdev\u002Fnull 2>&1 && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\n```\n\n**If PANDOC_MISSING**: Either install pandoc or use Alternative PDF Generation (Python-based)\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a source file:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content with original unicode characters...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Conditional Unicode Sanitization\n\n**Only sanitize if generating PDF**. Create sanitized version for PDF conversion:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source_sanitized.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content with unicode replaced (em-dash -> --, curly quotes -> straight, etc.)\n  \n  ## Section 2\n  More content...\n```\n\n**Optional: Use sanitization script** (see Unicode Sanitization Script section below):\n\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n**Note**: Keep the original unsanitized file for DOCX\u002FHTML conversion (these formats handle Unicode better).\n\n### Step 3: Convert to Target Formats with run_shell\n\nUse appropriate commands for each format. **Use sanitized source for PDF, original for others**.\n\n**DOCX (from original):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n**PDF (from sanitized, with engine priority):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=xelatex\n```\n\n**If xelatex fails, try pdflatex:**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=pdflatex\n```\n\n**If LaTeX engines fail, try wkhtmltopdf:**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**HTML (from original):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.html\n```\n\n### Step 4: Verify Outputs\n\nCheck that files were created and have content:\n\n```\nrun_shell\ncommand: ls -lh output.* && file output.*\n```\n\n```\nrun_shell\ncommand: test -s output.pdf && echo \"PDF has content\" || echo \"PDF is empty\"\n```\n\n## PDF Engine Decision Tree\n\n```\nIs pandoc available?\n├─ NO → Use Python fallback (fpdf2 or reportlab)\n└─ YES → Is LaTeX available?\n    ├─ YES (xelatex) → Use: pandoc --pdf-engine=xelatex (best Unicode)\n    ├─ YES (pdflatex) → Use: pandoc --pdf-engine=pdflatex + sanitization\n    ├─ YES (wkhtmltopdf) → Use: pandoc --pdf-engine=wkhtmltopdf\n    └─ NO → Install LaTeX or use Python fallback\n```\n\n## Alternative PDF Generation (Python Fallback)\n\nWhen pandoc or LaTeX is unavailable, use Python libraries directly:\n\n### Option A: fpdf2 (Simple, fast)\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font(\"Arial\", size=12)\n# Note: fpdf2 has limited Unicode support - use Latin-1 or embed fonts\npdf.cell(200, 10, txt=\"Document Title\", ln=True, align='C')\npdf.output(\"output.pdf\")\nEOF\n```\n\n### Option B: reportlab (More control, better Unicode)\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\nfrom reportlab.pdfbase import pdfmetrics\nfrom reportlab.pdfbase.ttfonts import TTFont\n\n# Register a Unicode font if needed\n# pdfmetrics.registerFont(TTFont('UnicodeFont', 'path\u002Fto\u002Ffont.ttf'))\n\nc = canvas.Canvas(\"output.pdf\", pagesize=letter)\nc.drawString(100, 750, \"Document Title\")\nc.save()\nEOF\n```\n\n### Option C: Markdown to PDF with Markdown2 + ReportLab\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nimport markdown\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet\n\n# Read markdown\nwith open('\u002Ftmp\u002Fdocument_source.md', 'r', encoding='utf-8') as f:\n    md_content = f.read()\n\n# Convert to HTML\nhtml_content = markdown.markdown(md_content)\n\n# Create PDF\ndoc = SimpleDocTemplate(\"output.pdf\", pagesize=letter)\nstyles = getSampleStyleSheet()\nstory = []\n\n# Parse HTML and add to story (simplified - use html2text for production)\nstory.append(Paragraph(\"Document Content\", styles['Normal']))\n\ndoc.build(story)\nprint(\"PDF created successfully\")\nEOF\n```\n\n## Complete Example\n\n```markdown\n# Generate Multi-Format Report\n\n## Step 0: Check environment\nrun_shell\ncommand: pandoc --version >\u002Fdev\u002Fnull 2>&1 && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Freport.md\ncontent: |\n  # Quarterly Report\n  \n  ## Executive Summary\n  Performance metrics and analysis...\n  \n  ## Key Findings\n  — Major finding with em-dash\n  \"Quote\" with curly quotes\n  ✓ Completed items\n\n## Step 2: Create sanitized version (for PDF only)\nwrite_file\npath: \u002Ftmp\u002Freport_sanitized.md\ncontent: |\n  # Quarterly Report\n  \n  ## Executive Summary\n  Performance metrics and analysis...\n  \n  ## Key Findings\n  -- Major finding with em-dash\n  \"Quote\" with straight quotes\n  [x] Completed items\n\n## Step 3: Convert to DOCX (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport.md -o report.docx\n\n## Step 4: Convert to PDF (from sanitized, with xelatex)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport_sanitized.md -o report.pdf --pdf-engine=xelatex\n\n## Step 5: Convert to HTML (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport.md -o report.html\n\n## Step 6: Verify all outputs\nrun_shell\ncommand: ls -lh report.* && echo \"All files created\"\n```\n\n## Error Handling & Recovery\n\n| Error | Likely Cause | Recovery Action |\n|-------|-------------|-----------------|\n| `pandoc: command not found` | Pandoc not installed | Install pandoc or use Python fallback |\n| `pdflatex not found` | LaTeX missing | Use `--pdf-engine=xelatex` or `wkhtmltopdf` |\n| `! LaTeX Error: File X.sty not found` | Missing LaTeX package | Install package or use xelatex\u002Fwkhtmltopdf |\n| `Encoding error` | Unicode in PDF | Use sanitized file + xelatex engine |\n| `wkhtmltopdf: command not found` | wkhtmltopdf missing | Install or use xelatex\u002Fpdflatex |\n| `PDF is empty (0 bytes)` | Conversion silently failed | Check pandoc stderr, try alternative engine |\n| `fpdf2 Unicode error` | Non-Latin characters | Use reportlab with Unicode font or sanitize |\n\n### Recovery Workflow\n\n1. **Check error message** for specific tool\u002Fengine failure\n2. **Try next engine in priority**: xelatex → pdflatex → wkhtmltopdf → fpdf2\u002Freportlab\n3. **If all pandoc attempts fail**: Switch to Python fallback (fpdf2\u002Freportlab)\n4. **If Unicode issues persist**: Apply stricter sanitization or use xelatex with Unicode font\n5. **Document which approach succeeded** for future reference\n\n## Unicode Sanitization Script (Reusable)\n\nSave as `sanitize_for_pdf.sh`:\n\n```bash\n#!\u002Fbin\u002Fbash\n# sanitize_for_pdf.sh - Replace problematic unicode chars for LaTeX\u002FPDF\nif [ -z \"$1\" ]; then\n  echo \"Usage: $0 \u003Cinput.md> [output.md]\"\n  exit 1\nfi\nINPUT=\"$1\"\nOUTPUT=\"${2:-${1%.md}_sanitized.md}\"\n\nsed -e 's\u002F—\u002F--\u002Fg' \\\n    -e 's\u002F–\u002F-\u002Fg' \\\n    -e 's\u002F\"([^\"]*)\"\u002F\"\\1\"\u002Fg' \\\n    -e \"s\u002F'([^']*)\u002F'\\1'\u002Fg\" \\\n    -e 's\u002F…\u002F...\u002Fg' \\\n    -e 's\u002F→\u002F->\u002Fg' \\\n    -e 's\u002F←\u002F\u003C-\u002Fg' \\\n    -e 's\u002F✓\u002F[x]\u002Fg' \\\n    -e 's\u002F✗\u002F[ ]\u002Fg' \\\n    -e 's\u002F©\u002F(c)\u002Fg' \\\n    -e 's\u002F®\u002F(r)\u002Fg' \\\n    -e 's\u002F™\u002F(tm)\u002Fg' \\\n    \"$INPUT\" > \"$OUTPUT\"\n\necho \"Sanitized: $INPUT -> $OUTPUT\"\n```\n\nMake executable: `chmod +x sanitize_for_pdf.sh`\n\nUsage:\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n## Common pandoc Commands Reference\n\n```bash\n# Markdown to Word\npandoc input.md -o output.docx\n\n# Markdown to PDF (LaTeX - default pdflatex)\npandoc input.md -o output.pdf\n\n# Markdown to PDF with xelatex (best Unicode support)\npandoc input.md -o output.pdf --pdf-engine=xelatex\n\n# Markdown to PDF with wkhtmltopdf (HTML-based, no LaTeX)\npandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf\n\n# Markdown to HTML\npandoc input.md -o output.html\n\n# With metadata\npandoc input.md -o output.pdf --metadata title=\"Document Title\"\n\n# With custom reference doc (DOCX)\npandoc input.md -o output.docx --reference-doc=template.docx\n\n# With custom template (HTML\u002FPDF)\npandoc input.md --template=template.html -o output.html\n\n# Force UTF-8 input\npandoc -f markdown+utf8 input.md -o output.pdf\n```\n\n## Troubleshooting Quick Reference\n\n**PDF generation fails with encoding error:**\n- Use sanitized markdown file\n- Try `--pdf-engine=xelatex` for better Unicode support\n- Add `-f markdown+utf8` to pandoc command\n\n**PDF generation fails: LaTeX not found:**\n- Install: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- Or use: `--pdf-engine=wkhtmltopdf`\n- Or use: Python fallback (fpdf2\u002Freportlab)\n\n**DOCX formatting issues:**\n- Add `--reference-doc=template.docx` for custom styles\n- Check markdown structure (headings, lists)\n\n**Unicode\u002Fencoding errors in any format:**\n- Ensure source file is UTF-8: `file -i source.md`\n- Add `-f markdown+utf8` to pandoc command\n- Use xelatex for PDF\n\n**Special characters not rendering in PDF:**\n- Use the character replacement table\n- Create sanitized version before PDF conversion\n- Try xelatex with Unicode font\n\n**Missing pandoc:**\n- Ubuntu\u002FDebian: `apt-get install pandoc`\n- macOS: `brew install pandoc`\n- Fallback: Use Python libraries directly\n\n## When to Use shell_agent vs Manual Workflow\n\n| Scenario | Recommended Approach |\n|----------|---------------------|\n| Simple DOCX\u002FHTML, no Unicode | `shell_agent` is fine |\n| PDF generation required | Manual workflow (this skill) |\n| Multiple formats from one source | Manual workflow (this skill) |\n| Heavy Unicode\u002Fspecial characters | Manual workflow with sanitization |\n| `shell_agent` failed with unknown error | Manual workflow (this skill) |\n| Need explicit error visibility | Manual workflow (this skill) |\n| Environment constraints (no pandoc) | Python fallback (this skill) |\n\n**After successful manual workflow**: You can attempt `shell_agent` for similar future tasks, but keep this workflow as your known-working fallback.\n\n## Related Skills\n\n- `document-gen-fallback`: Original fallback workflow (less Unicode guidance)\n- `write-file-fallback-report`: For when multiple tools fail simultaneously\n- `spreadsheet-direct-python`: For Excel\u002FCSV generation with Python\n\n## Skill Health & Metrics\n\n**Expected success rate**: 85%+ with proper environment setup\n**Fallback activation**: Use Python fallback if pandoc\u002FLaTeX unavailable\n**Verification**: Always verify output files exist AND have content (>0 bytes)\n*** End Files\n*** Begin Files\n","# Resilient Document Generation Workflow (Multi-Format + Unicode-Safe)\n\n## When to Use\n\nUse this skill when generating documents in multiple formats (`.docx`, `.pdf`, `.html`) and you need:\n- **Reliable execution** with pre-flight environment verification\n- **Automatic Unicode handling** based on target format\n- **Fallback options** when primary tools (pandoc\u002FLaTeX) are unavailable\n- **Clear error isolation** through discrete, observable steps\n\n**Trigger this workflow when:**\n- `shell_agent` returns unknown\u002Funclear errors on document generation\n- You need multiple output formats from one source\n- Documents contain special characters, symbols, or non-ASCII text\n- Previous PDF generation attempts failed due to encoding or missing dependencies\n\n## Pre-Flight Environment Check\n\n**Before starting**, verify your environment has the required tools:\n\n```\nrun_shell\ncommand: which pandoc && pandoc --version | head -1\n```\n\n```\nrun_shell\ncommand: which pdflatex || which xelatex || which wkhtmltopdf || echo \"No PDF engine found\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import fpdf; print('fpdf2 available')\" 2>\u002Fdev\u002Fnull || echo \"fpdf2 not available\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import reportlab; print('reportlab available')\" 2>\u002Fdev\u002Fnull || echo \"reportlab not available\"\n```\n\n**If pandoc is missing:** Install via `apt-get install pandoc` or `brew install pandoc`\n\n**If no PDF engine found:** Choose fallback approach:\n- Install LaTeX: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- Or use wkhtmltopdf: `apt-get install wkhtmltopdf`\n- Or use Python fallback (fpdf2\u002Freportlab) - see Alternative PDF Generation section\n\n## Core Technique\n\nSplit the workflow into discrete, observable steps with automatic format detection:\n1. **Environment check** → Verify tools are available\n2. **Content creation** → Use `write_file` to create source Markdown\n3. **Auto-sanitization** → Conditionally sanitize based on target format (PDF needs it, DOCX\u002FHTML don't)\n4. **Format conversion** → Use appropriate tool for each format with fallback options\n5. **Verification** → Check output files exist and validate content\n\n## ⚠️ Unicode & Format Compatibility Matrix\n\n| Format | Unicode Support | Sanitization Needed | Recommended Engine |\n|--------|-----------------|---------------------|-------------------|\n| `.docx` | Excellent | No | pandoc (default) |\n| `.html` | Excellent | No | pandoc (default) |\n| `.pdf` | Limited (LaTeX) | **Yes** | xelatex > pdflatex > wkhtmltopdf > fpdf2 |\n| `.pptx` | Good | No | pandoc (if available) or python-pptx |\n\n### Critical Unicode Characters for PDF\n\n| Character | Issue | Safe Replacement |\n|-----------|-------|------------------|\n| `—` (em dash) | May not render | `--` or `-` |\n| `–` (en dash) | May not render | `-` |\n| `\" \"` (curly quotes) | Encoding errors | `\" \"` (straight quotes) |\n| `' '` (curly apostrophe) | Encoding errors | `'` (straight apostrophe) |\n| `…` (ellipsis) | May not render | `...` |\n| `→` `←` `↑` `↓` (arrows) | LaTeX incompatibility | `->` `\u003C-` `^` `v` |\n| `✓` `✗` (checkmarks) | May not render | `[x]` `[ ]` |\n| `★` `●` (symbols) | May not render | `*` `-` |\n| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\n| Non-ASCII letters (é, ñ, ü) | Font-dependent | Use xeLaTeX or replace |\n\n## Step-by-Step Workflow\n\n### Step 0: Pre-Flight Check\n\nVerify environment before proceeding:\n\n```\nrun_shell\ncommand: pandoc --version >\u002Fdev\u002Fnull 2>&1 && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\n```\n\n**If PANDOC_MISSING**: Either install pandoc or use Alternative PDF Generation (Python-based)\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a source file:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content with original unicode characters...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Conditional Unicode Sanitization\n\n**Only sanitize if generating PDF**. Create sanitized version for PDF conversion:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source_sanitized.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content with unicode replaced (em-dash -> --, curly quotes -> straight, etc.)\n  \n  ## Section 2\n  More content...\n```\n\n**Optional: Use sanitization script** (see Unicode Sanitization Script section below):\n\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n**Note**: Keep the original unsanitized file for DOCX\u002FHTML conversion (these formats handle Unicode better).\n\n### Step 3: Convert to Target Formats with run_shell\n\nUse appropriate commands for each format. **Use sanitized source for PDF, original for others**.\n\n**DOCX (from original):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n**PDF (from sanitized, with engine priority):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=xelatex\n```\n\n**If xelatex fails, try pdflatex:**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=pdflatex\n```\n\n**If LaTeX engines fail, try wkhtmltopdf:**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**HTML (from original):**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.html\n```\n\n### Step 4: Verify Outputs\n\nCheck that files were created and have content:\n\n```\nrun_shell\ncommand: ls -lh output.* && file output.*\n```\n\n```\nrun_shell\ncommand: test -s output.pdf && echo \"PDF has content\" || echo \"PDF is empty\"\n```\n\n## PDF Engine Decision Tree\n\n```\nIs pandoc available?\n├─ NO → Use Python fallback (fpdf2 or reportlab)\n└─ YES → Is LaTeX available?\n    ├─ YES (xelatex) → Use: pandoc --pdf-engine=xelatex (best Unicode)\n    ├─ YES (pdflatex) → Use: pandoc --pdf-engine=pdflatex + sanitization\n    ├─ YES (wkhtmltopdf) → Use: pandoc --pdf-engine=wkhtmltopdf\n    └─ NO → Install LaTeX or use Python fallback\n```\n\n## Alternative PDF Generation (Python Fallback)\n\nWhen pandoc or LaTeX is unavailable, use Python libraries directly:\n\n### Option A: fpdf2 (Simple, fast)\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font(\"Arial\", size=12)\n# Note: fpdf2 has limited Unicode support - use Latin-1 or embed fonts\npdf.cell(200, 10, txt=\"Document Title\", ln=True, align='C')\npdf.output(\"output.pdf\")\nEOF\n```\n\n### Option B: reportlab (More control, better Unicode)\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\nfrom reportlab.pdfbase import pdfmetrics\nfrom reportlab.pdfbase.ttfonts import TTFont\n\n# Register a Unicode font if needed\n# pdfmetrics.registerFont(TTFont('UnicodeFont', 'path\u002Fto\u002Ffont.ttf'))\n\nc = canvas.Canvas(\"output.pdf\", pagesize=letter)\nc.drawString(100, 750, \"Document Title\")\nc.save()\nEOF\n```\n\n### Option C: Markdown to PDF with Markdown2 + ReportLab\n\n```\nrun_shell\ncommand: python3 \u003C\u003C 'EOF'\nimport markdown\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet\n\n# Read markdown\nwith open('\u002Ftmp\u002Fdocument_source.md', 'r', encoding='utf-8') as f:\n    md_content = f.read()\n\n# Convert to HTML\nhtml_content = markdown.markdown(md_content)\n\n# Create PDF\ndoc = SimpleDocTemplate(\"output.pdf\", pagesize=letter)\nstyles = getSampleStyleSheet()\nstory = []\n\n# Parse HTML and add to story (simplified - use html2text for production)\nstory.append(Paragraph(\"Document Content\", styles['Normal']))\n\ndoc.build(story)\nprint(\"PDF created successfully\")\nEOF\n```\n\n## Complete Example\n\n```markdown\n# Generate Multi-Format Report\n\n## Step 0: Check environment\nrun_shell\ncommand: pandoc --version >\u002Fdev\u002Fnull 2>&1 && echo \"PANDOC_OK\" || echo \"PANDOC_MISSING\"\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Freport.md\ncontent: |\n  # Quarterly Report\n  \n  ## Executive Summary\n  Performance metrics and analysis...\n  \n  ## Key Findings\n  — Major finding with em-dash\n  \"Quote\" with curly quotes\n  ✓ Completed items\n\n## Step 2: Create sanitized version (for PDF only)\nwrite_file\npath: \u002Ftmp\u002Freport_sanitized.md\ncontent: |\n  # Quarterly Report\n  \n  ## Executive Summary\n  Performance metrics and analysis...\n  \n  ## Key Findings\n  -- Major finding with em-dash\n  \"Quote\" with straight quotes\n  [x] Completed items\n\n## Step 3: Convert to DOCX (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport.md -o report.docx\n\n## Step 4: Convert to PDF (from sanitized, with xelatex)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport_sanitized.md -o report.pdf --pdf-engine=xelatex\n\n## Step 5: Convert to HTML (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Freport.md -o report.html\n\n## Step 6: Verify all outputs\nrun_shell\ncommand: ls -lh report.* && echo \"All files created\"\n```\n\n## Error Handling & Recovery\n\n| Error | Likely Cause | Recovery Action |\n|-------|-------------|-----------------|\n| `pandoc: command not found` | Pandoc not installed | Install pandoc or use Python fallback |\n| `pdflatex not found` | LaTeX missing | Use `--pdf-engine=xelatex` or `wkhtmltopdf` |\n| `! LaTeX Error: File X.sty not found` | Missing LaTeX package | Install package or use xelatex\u002Fwkhtmltopdf |\n| `Encoding error` | Unicode in PDF | Use sanitized file + xelatex engine |\n| `wkhtmltopdf: command not found` | wkhtmltopdf missing | Install or use xelatex\u002Fpdflatex |\n| `PDF is empty (0 bytes)` | Conversion silently failed | Check pandoc stderr, try alternative engine |\n| `fpdf2 Unicode error` | Non-Latin characters | Use reportlab with Unicode font or sanitize |\n\n### Recovery Workflow\n\n1. **Check error message** for specific tool\u002Fengine failure\n2. **Try next engine in priority**: xelatex → pdflatex → wkhtmltopdf → fpdf2\u002Freportlab\n3. **If all pandoc attempts fail**: Switch to Python fallback (fpdf2\u002Freportlab)\n4. **If Unicode issues persist**: Apply stricter sanitization or use xelatex with Unicode font\n5. **Document which approach succeeded** for future reference\n\n## Unicode Sanitization Script (Reusable)\n\nSave as `sanitize_for_pdf.sh`:\n\n```bash\n#!\u002Fbin\u002Fbash\n# sanitize_for_pdf.sh - Replace problematic unicode chars for LaTeX\u002FPDF\nif [ -z \"$1\" ]; then\n  echo \"Usage: $0 \u003Cinput.md> [output.md]\"\n  exit 1\nfi\nINPUT=\"$1\"\nOUTPUT=\"${2:-${1%.md}_sanitized.md}\"\n\nsed -e 's\u002F—\u002F--\u002Fg' \\\n    -e 's\u002F–\u002F-\u002Fg' \\\n    -e 's\u002F\"([^\"]*)\"\u002F\"\\1\"\u002Fg' \\\n    -e \"s\u002F'([^']*)\u002F'\\1'\u002Fg\" \\\n    -e 's\u002F…\u002F...\u002Fg' \\\n    -e 's\u002F→\u002F->\u002Fg' \\\n    -e 's\u002F←\u002F\u003C-\u002Fg' \\\n    -e 's\u002F✓\u002F[x]\u002Fg' \\\n    -e 's\u002F✗\u002F[ ]\u002Fg' \\\n    -e 's\u002F©\u002F(c)\u002Fg' \\\n    -e 's\u002F®\u002F(r)\u002Fg' \\\n    -e 's\u002F™\u002F(tm)\u002Fg' \\\n    \"$INPUT\" > \"$OUTPUT\"\n\necho \"Sanitized: $INPUT -> $OUTPUT\"\n```\n\nMake executable: `chmod +x sanitize_for_pdf.sh`\n\nUsage:\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n## Common pandoc Commands Reference\n\n```bash\n# Markdown to Word\npandoc input.md -o output.docx\n\n# Markdown to PDF (LaTeX - default pdflatex)\npandoc input.md -o output.pdf\n\n# Markdown to PDF with xelatex (best Unicode support)\npandoc input.md -o output.pdf --pdf-engine=xelatex\n\n# Markdown to PDF with wkhtmltopdf (HTML-based, no LaTeX)\npandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf\n\n# Markdown to HTML\npandoc input.md -o output.html\n\n# With metadata\npandoc input.md -o output.pdf --metadata title=\"Document Title\"\n\n# With custom reference doc (DOCX)\npandoc input.md -o output.docx --reference-doc=template.docx\n\n# With custom template (HTML\u002FPDF)\npandoc input.md --template=template.html -o output.html\n\n# Force UTF-8 input\npandoc -f markdown+utf8 input.md -o output.pdf\n```\n\n## Troubleshooting Quick Reference\n\n**PDF generation fails with encoding error:**\n- Use sanitized markdown file\n- Try `--pdf-engine=xelatex` for better Unicode support\n- Add `-f markdown+utf8` to pandoc command\n\n**PDF generation fails: LaTeX not found:**\n- Install: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n- Or use: `--pdf-engine=wkhtmltopdf`\n- Or use: Python fallback (fpdf2\u002Freportlab)\n\n**DOCX formatting issues:**\n- Add `--reference-doc=template.docx` for custom styles\n- Check markdown structure (headings, lists)\n\n**Unicode\u002Fencoding errors in any format:**\n- Ensure source file is UTF-8: `file -i source.md`\n- Add `-f markdown+utf8` to pandoc command\n- Use xelatex for PDF\n\n**Special characters not rendering in PDF:**\n- Use the character replacement table\n- Create sanitized version before PDF conversion\n- Try xelatex with Unicode font\n\n**Missing pandoc:**\n- Ubuntu\u002FDebian: `apt-get install pandoc`\n- macOS: `brew install pandoc`\n- Fallback: Use Python libraries directly\n\n## When to Use shell_agent vs Manual Workflow\n\n| Scenario | Recommended Approach |\n|----------|---------------------|\n| Simple DOCX\u002FHTML, no Unicode | `shell_agent` is fine |\n| PDF generation required | Manual workflow (this skill) |\n| Multiple formats from one source | Manual workflow (this skill) |\n| Heavy Unicode\u002Fspecial characters | Manual workflow with sanitization |\n| `shell_agent` failed with unknown error | Manual workflow (this skill) |\n| Need explicit error visibility | Manual workflow (this skill) |\n| Environment constraints (no pandoc) | Python fallback (this skill) |\n\n**After successful manual workflow**: You can attempt `shell_agent` for similar future tasks, but keep this workflow as your known-working fallback.\n\n## Related Skills\n\n- `document-gen-fallback`: Original fallback workflow (less Unicode guidance)\n- `write-file-fallback-report`: For when multiple tools fail simultaneously\n- `spreadsheet-direct-python`: For Excel\u002FCSV generation with Python\n\n## Skill Health & Metrics\n\n**Expected success rate**: 85%+ with proper environment setup\n**Fallback activation**: Use Python fallback if pandoc\u002FLaTeX unavailable\n**Verification**: Always verify output files exist AND have content (>0 bytes)\n*** End Files\n*** Begin Files\n",{"name":5,"description":7},"main","af1b40a42167d09c30b3a63000aa14ace4c1e229","gdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-618c9b","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs","https:\u002F\u002Fxyliu-cs.github.io","PhD Student in CS, CUHK-Shenzhen.","2026-04-06 20:32:15",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient-multiformat",{"tool":58,"command":59},"bunx","bunx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient-multiformat",{"tool":61,"command":62},"pnpm","pnpm dlx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient-multiformat","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-618c9b\u002FSKILL.md",true,[66,72],{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},".skill_id","OTHER","其他",60,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-618c9b\u002F.skill_id",{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"sanitize_for_pdf.sh","SCRIPT","脚本",1215,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-618c9b\u002Fsanitize_for_pdf.sh",[79,92,100,115,140,158],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":39},"01M6KG8MF1S664SWBDENYRSCK8","zip-export-deliverable","Ensures codebase deliverables are properly exported as ZIP archives through a dedicated finalization step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-export-deliverable\u002FSKILL.md",[],[86,87,88,89,90,91],"zip export deliverable","zip","export","deliverables","codebase","as",{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":39},"01M6KG8GAZWHHEK7VNJDW0ME21","zip-deliverable-finalization","Ensure codebase deliverables are properly packaged as ZIP exports in a dedicated final step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-deliverable-finalization\u002FSKILL.md",[],[99,87,89,90,91],"zip deliverable finalization",{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":39},"01M6KG8CMQQ1PYMNTSRZ9VS1MD","zero-iteration-failure-analysis","Identify and handle agent failures with 0 iterations as pre-execution system issues","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzero-iteration-failure-analysis\u002FSKILL.md",[],[107,108,109,110,111,37,112,113,91,114],"failure analysis","ZeRO","analysis","iteration","zero iteration failure analysis","issues","execution","system",{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":126,"publishedAt":39},"01M6KG86W3PA07FT9W58YHHERM","write-file-fallback-report","Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report\u002FSKILL.md",[121],{"categoryNo":122,"categoryName":123,"taxonomyType":124,"taxonomyTypeDesc":125},"01JBSEEDCAT000000000000034","行政与办公人员","PROFESSION","适用职业",[33,127,128,129,130,131,132,133,134,135,136,137,138,139],"write","file","report","write file fallback report","domain","professional","sources","retrieval","generate","embedded","documents","data","knowledge",{"skillNo":141,"name":142,"nameZh":6,"description":143,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":144,"categories":145,"keywords":147,"publishedAt":39},"01M6KG82GAEY3GG77CMGCK1C2T","fallback-doc-with-delegation","Generate professional documents after tool failures using shell_agent for complex formats or write_file for simple text\u002Fmarkdown","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced\u002FSKILL.md",[146],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[148,37,33,149,150,151,137,135,128,152,153,154,127,155,132,156,157],"fallback doc with delegation","doc","delegation","shell","markdown","tool","text","simple","formats","for",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":165,"publishedAt":39},"01M6KG7WT7GX5NYCGEFHW22NV7","context-anchored-fallback-report","Generate documents with write_file when retrieval tools fail, with explicit guardrails against task context drift","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced-4bc5c2\u002FSKILL.md",[164],{"categoryNo":122,"categoryName":123,"taxonomyType":124,"taxonomyTypeDesc":125},[33,129,166,167,135,128,168,169,127,170,171,134,37,172,137],"context","context anchored fallback report","Guardrails","Tools","task","drift","context drift"]