[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KFCW6X7QMTJ4G1GXH73XQS":3,"skill-same:01M6KFCW6X7QMTJ4G1GXH73XQS":62},{"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":18,"publishedAt":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":34,"commitSha":35,"skillDirectory":36,"forksCount":14,"repositoryHtmlUrl":37,"repositoryHomepageUrl":6,"ownerHtmlUrl":38,"ownerBlogUrl":39,"ownerDescription":40,"updatedAt":41,"install":42,"resources":55},"01M6KFCW6X7QMTJ4G1GXH73XQS","document-gen-resilient",null,"Multi-path document generation with tool checks, Unicode handling, and Python fallbacks","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-96865f\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28],"document","document gen resilient","python","tool","generation","multi","Unicode","document generation","with","path","2026-11-10 10:12:30",false,"---\nname: document-gen-resilient\ndescription: Multi-path document generation with tool checks, Unicode handling, and Python fallbacks\n---\n\n# Resilient Document Generation Workflow\n\n## When to Use\n\nUse this skill when document generation tasks encounter errors or when you need reliable multi-format output:\n- `shell_agent` returns unknown or unclear errors on document generation\n- Generating documents in multiple formats (e.g., `.docx`, `.pdf`, `.html`)\n- **PDF generation fails due to LaTeX encoding or missing dependencies**\n- **You need to handle special characters, symbols, or non-ASCII text safely**\n- Previous document generation attempts have failed\n\n## Core Technique\n\nInstead of delegating the entire document generation to `shell_agent`, manually split the workflow into discrete, observable steps with built-in fallbacks:\n1. **Tool availability check** → Verify pandoc and PDF engines are available\n2. **Content creation** → Use `write_file` to create source document (Markdown)\n3. **Unicode assessment** → Determine if sanitization is needed based on target format\n4. **Format conversion** → Try primary method, fall back to alternatives on failure\n5. **Verification** → Check output files exist and are valid\n\n## ⚠️ Format-Specific Unicode Guidance\n\n**Critical**: Different formats handle Unicode differently. Plan accordingly:\n\n| Format | Unicode Support | Sanitization Needed? | Recommended Engine |\n|--------|-----------------|---------------------|-------------------|\n| `.docx` | Excellent | No | pandoc (default) |\n| `.html` | Excellent | No | pandoc (default) |\n| `.pdf` (pdflatex) | Limited | **Yes** | pandoc + sanitization |\n| `.pdf` (xelatex) | Good | Rarely | pandoc --pdf-engine=xelatex |\n| `.pdf` (wkhtmltopdf) | Good | Rarely | pandoc --pdf-engine=wkhtmltopdf |\n| `.pdf` (Python) | Excellent | No | fpdf2 or reportlab |\n\n## Step-by-Step Workflow\n\n### Step 0: Check Tool Availability\n\nBefore starting, verify which tools are available:\n\n```\nrun_shell\ncommand: which pandoc && echo \"PANDOC: OK\" || echo \"PANDOC: MISSING\"\n```\n\n```\nrun_shell\ncommand: which pdflatex && echo \"PDFLATEX: OK\" || echo \"PDFLATEX: MISSING\"\n```\n\n```\nrun_shell\ncommand: which xelatex && echo \"XELATEX: OK\" || echo \"XELATEX: MISSING\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import fpdf; print('FPDF2: OK')\" 2>\u002Fdev\u002Fnull || echo \"FPDF2: MISSING\"\n```\n\n**Decision Tree Based on Availability:**\n- **pandoc + xelatex available** → Use pandoc with xelatex engine (best Unicode support)\n- **pandoc + pdflatex only** → Use pandoc with sanitization (Step 2)\n- **pandoc missing, Python available** → Use Python libraries (Step 3 Alternative)\n- **All missing** → Install dependencies or use shell_agent with explicit instructions\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a temporary source file. This gives you full visibility into the content being generated.\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Assess and Handle Unicode (Conditional)\n\n**Before PDF conversion**, check if your content contains problematic characters:\n\n```\nrun_shell\ncommand: grep -P '[\\x{2014}\\x{2013}\\x{201C}\\x{201D}\\x{2026}]' \u002Ftmp\u002Fdocument_source.md && echo \"UNICODE_DETECTED\" || echo \"UNICODE_CLEAN\"\n```\n\n**If Unicode detected AND using pdflatex**, create a sanitized version:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source_sanitized.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here... (with all special chars replaced per table below)\n```\n\n**Common Problematic Characters:**\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| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\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 `run_shell` with explicit commands for each format. Try primary method first, fall back on failure.\n\n#### For DOCX (from original, no sanitization needed):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n#### For PDF (try in order):\n\n**Option A: xelatex (best Unicode support)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=xelatex\n```\n\n**Option B: wkhtmltopdf (good alternative)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**Option C: pdflatex with sanitization**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf\n```\n\n**Option D: Python fpdf2 fallback**\n```\nrun_shell\ncommand: python3 -c \"\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font('Arial', size=12)\nwith open('\u002Ftmp\u002Fdocument_source.md', 'r', encoding='utf-8') as f:\n    content = f.read()\npdf.multi_cell(0, 10, content)\npdf.output('output.pdf')\n\"\n```\n\n#### For HTML (from original, no sanitization needed):\n\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 successfully:\n\n```\nrun_shell\ncommand: ls -lh output.docx output.pdf output.html 2>\u002Fdev\u002Fnull\n```\n\n```\nrun_shell\ncommand: file output.pdf 2>\u002Fdev\u002Fnull\n```\n\n## Complete Example\n\n```markdown\n# Generate Negotiation Strategy Document\n\n## Step 0: Check tools\nrun_shell\ncommand: which pandoc && which xelatex && echo \"TOOLS_OK\" || echo \"TOOLS_MISSING\"\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Fnegotiation_strategy.md\ncontent: |\n  # Negotiation Strategy\n  \n  ## Executive Summary\n  [Content with original unicode...]\n  \n  ## Resolution Path\n  [Content...]\n  \n  ## BATNA Analysis\n  [Content...]\n\n## Step 2: Check for Unicode (if PDF needed)\nrun_shell\ncommand: grep -P '[\\x{2014}\\x{2013}\\x{201C}\\x{201D}]' \u002Ftmp\u002Fnegotiation_strategy.md && echo \"UNICODE_DETECTED\" || echo \"UNICODE_CLEAN\"\n\n## Step 3: Convert to DOCX (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.docx\n\n## Step 4: Convert to PDF (try xelatex first)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=xelatex\n\n## Step 5: If Step 4 failed, try wkhtmltopdf\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=wkhtmltopdf\n\n## Step 6: Convert to HTML (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.html\n\n## Step 7: Verify\nrun_shell\ncommand: ls -lh negotiation_strategy.*\n```\n\n## Advantages Over shell_agent\n\n| Aspect | shell_agent | Manual Workflow |\n|--------|-------------|-----------------|\n| Error visibility | Opaque, may retry silently | Each step shows explicit output |\n| Recovery | Automatic but may loop | Manual intervention at specific step |\n| Debugging | Hard to isolate failure point | Clear which step failed |\n| Unicode control | Agent may not handle encoding | You control character sanitization |\n| Tool fallback | Single approach | Multiple fallback options |\n| Control | Agent decides approach | You control each conversion |\n\n## Common pandoc Commands\n\n```bash\n# Markdown to Word\npandoc input.md -o output.docx\n\n# Markdown to PDF (requires LaTeX or wkhtmltopdf)\npandoc input.md -o output.pdf\n\n# Markdown to PDF with Unicode-safe engine (better Unicode support)\npandoc input.md -o output.pdf --pdf-engine=xelatex\n\n# Markdown to PDF with wkhtmltopdf (good alternative)\npandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf\n\n# Markdown to HTML\npandoc input.md -o output.html\n\n# With custom template\npandoc input.md --template=template.html -o output.html\n\n# With metadata\npandoc input.md -o output.pdf --metadata title=\"Document Title\"\n```\n\n## Troubleshooting\n\n### PDF Generation Failures\n\n- **PDF generation fails with encoding error**: \n  - Use `--pdf-engine=xelatex` for better Unicode support\n  - Or use `--pdf-engine=wkhtmltopdf` as alternative\n  - Or create sanitized markdown file and use pdflatex\n\n- **PDF generation fails: LaTeX not found**: \n  - Install LaTeX: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n  - Or use `--pdf-engine=wkhtmltopdf` instead\n  - Or fall back to Python fpdf2 (Step 3 Option D)\n\n- **PDF generation fails: wkhtmltopdf not found**: \n  - Install: `apt-get install wkhtmltopdf`\n  - Or use xelatex or pdflatex with sanitization\n  - Or fall back to Python fpdf2\n\n### DOCX Formatting Issues\n\n- Add `--reference-doc=template.docx` for custom styles\n- Ensure pandoc version is 2.0+ for best DOCX support\n\n### Unicode\u002FEncoding Errors in Any Format\n\n- Add `-f markdown+utf8` to pandoc command\n- Ensure source file is UTF-8 encoded: `file -i source.md`\n- For PDF: prefer xelatex engine over pdflatex\n\n### Special Characters Not Rendering in PDF\n\n- Use xelatex engine: `--pdf-engine=xelatex`\n- Or use the character replacement table above\n- Or create sanitized version before PDF conversion\n\n### Missing pandoc\n\n- Install via `apt-get install pandoc` or `brew install pandoc`\n- Or use Python libraries directly (fpdf2, reportlab)\n\n### Python PDF Library Fallback\n\nIf pandoc is unavailable or consistently failing:\n\n```bash\n# Using fpdf2\npython3 -c \"\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font('Arial', size=12)\npdf.multi_cell(0, 10, open('input.md').read())\npdf.output('output.pdf')\n\"\n\n# Using reportlab (more control)\npython3 -c \"\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Paragraph\nfrom reportlab.lib.styles import getSampleStyleSheet\ndoc = SimpleDocTemplate('output.pdf', pagesize=letter)\nstyles = getSampleStyleSheet()\nstory = [Paragraph(open('input.md').read(), styles['Normal'])]\ndoc.build(story)\n\"\n```\n\n## Unicode Sanitization Script (Optional)\n\nFor repeated use, create a reusable sanitization script:\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\nSave as `sanitize_for_pdf.sh`, make executable with `chmod +x sanitize_for_pdf.sh`, then use:\n\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n## Decision Matrix: Which Approach to Use\n\n| Scenario | Recommended Approach |\n|----------|---------------------|\n| DOCX only, any content | pandoc (no sanitization needed) |\n| HTML only, any content | pandoc (no sanitization needed) |\n| PDF, simple ASCII content | pandoc + pdflatex |\n| PDF, Unicode content | pandoc + xelatex (preferred) |\n| PDF, Unicode, xelatex unavailable | pandoc + sanitization + pdflatex |\n| PDF, pandoc unavailable | Python fpdf2 or reportlab |\n| Multiple formats needed | pandoc for all, sanitization for PDF only |\n| shell_agent failing repeatedly | Use this manual workflow |\n\n## When to Return to shell_agent\n\nAfter successfully completing the manual workflow once, you can attempt `shell_agent` again for similar tasks, now with a known-working fallback if errors recur. For documents with heavy Unicode content requiring PDF output, consider always using the manual workflow with xelatex or sanitization.\n\n## Related Skills\n\n- `write-file-fallback-report`: Use when web sourcing fails, create from embedded knowledge\n- `spreadsheet-direct-python`: Use Python libraries directly for spreadsheet operations\n- Use this skill when your documents contain special characters, symbols, or non-ASCII text that may cause LaTeX\u002FPDF conversion issues\n","# Resilient Document Generation Workflow\n\n## When to Use\n\nUse this skill when document generation tasks encounter errors or when you need reliable multi-format output:\n- `shell_agent` returns unknown or unclear errors on document generation\n- Generating documents in multiple formats (e.g., `.docx`, `.pdf`, `.html`)\n- **PDF generation fails due to LaTeX encoding or missing dependencies**\n- **You need to handle special characters, symbols, or non-ASCII text safely**\n- Previous document generation attempts have failed\n\n## Core Technique\n\nInstead of delegating the entire document generation to `shell_agent`, manually split the workflow into discrete, observable steps with built-in fallbacks:\n1. **Tool availability check** → Verify pandoc and PDF engines are available\n2. **Content creation** → Use `write_file` to create source document (Markdown)\n3. **Unicode assessment** → Determine if sanitization is needed based on target format\n4. **Format conversion** → Try primary method, fall back to alternatives on failure\n5. **Verification** → Check output files exist and are valid\n\n## ⚠️ Format-Specific Unicode Guidance\n\n**Critical**: Different formats handle Unicode differently. Plan accordingly:\n\n| Format | Unicode Support | Sanitization Needed? | Recommended Engine |\n|--------|-----------------|---------------------|-------------------|\n| `.docx` | Excellent | No | pandoc (default) |\n| `.html` | Excellent | No | pandoc (default) |\n| `.pdf` (pdflatex) | Limited | **Yes** | pandoc + sanitization |\n| `.pdf` (xelatex) | Good | Rarely | pandoc --pdf-engine=xelatex |\n| `.pdf` (wkhtmltopdf) | Good | Rarely | pandoc --pdf-engine=wkhtmltopdf |\n| `.pdf` (Python) | Excellent | No | fpdf2 or reportlab |\n\n## Step-by-Step Workflow\n\n### Step 0: Check Tool Availability\n\nBefore starting, verify which tools are available:\n\n```\nrun_shell\ncommand: which pandoc && echo \"PANDOC: OK\" || echo \"PANDOC: MISSING\"\n```\n\n```\nrun_shell\ncommand: which pdflatex && echo \"PDFLATEX: OK\" || echo \"PDFLATEX: MISSING\"\n```\n\n```\nrun_shell\ncommand: which xelatex && echo \"XELATEX: OK\" || echo \"XELATEX: MISSING\"\n```\n\n```\nrun_shell\ncommand: python3 -c \"import fpdf; print('FPDF2: OK')\" 2>\u002Fdev\u002Fnull || echo \"FPDF2: MISSING\"\n```\n\n**Decision Tree Based on Availability:**\n- **pandoc + xelatex available** → Use pandoc with xelatex engine (best Unicode support)\n- **pandoc + pdflatex only** → Use pandoc with sanitization (Step 2)\n- **pandoc missing, Python available** → Use Python libraries (Step 3 Alternative)\n- **All missing** → Install dependencies or use shell_agent with explicit instructions\n\n### Step 1: Create Source Content with write_file\n\nWrite your document content as Markdown to a temporary source file. This gives you full visibility into the content being generated.\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here...\n  \n  ## Section 2\n  More content...\n```\n\n### Step 2: Assess and Handle Unicode (Conditional)\n\n**Before PDF conversion**, check if your content contains problematic characters:\n\n```\nrun_shell\ncommand: grep -P '[\\x{2014}\\x{2013}\\x{201C}\\x{201D}\\x{2026}]' \u002Ftmp\u002Fdocument_source.md && echo \"UNICODE_DETECTED\" || echo \"UNICODE_CLEAN\"\n```\n\n**If Unicode detected AND using pdflatex**, create a sanitized version:\n\n```\nwrite_file\npath: \u002Ftmp\u002Fdocument_source_sanitized.md\ncontent: |\n  # Document Title\n  \n  ## Section 1\n  Content here... (with all special chars replaced per table below)\n```\n\n**Common Problematic Characters:**\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| `©` `®` `™` | May require packages | `(c)` `(r)` `(tm)` |\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 `run_shell` with explicit commands for each format. Try primary method first, fall back on failure.\n\n#### For DOCX (from original, no sanitization needed):\n\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.docx\n```\n\n#### For PDF (try in order):\n\n**Option A: xelatex (best Unicode support)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=xelatex\n```\n\n**Option B: wkhtmltopdf (good alternative)**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source.md -o output.pdf --pdf-engine=wkhtmltopdf\n```\n\n**Option C: pdflatex with sanitization**\n```\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fdocument_source_sanitized.md -o output.pdf\n```\n\n**Option D: Python fpdf2 fallback**\n```\nrun_shell\ncommand: python3 -c \"\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font('Arial', size=12)\nwith open('\u002Ftmp\u002Fdocument_source.md', 'r', encoding='utf-8') as f:\n    content = f.read()\npdf.multi_cell(0, 10, content)\npdf.output('output.pdf')\n\"\n```\n\n#### For HTML (from original, no sanitization needed):\n\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 successfully:\n\n```\nrun_shell\ncommand: ls -lh output.docx output.pdf output.html 2>\u002Fdev\u002Fnull\n```\n\n```\nrun_shell\ncommand: file output.pdf 2>\u002Fdev\u002Fnull\n```\n\n## Complete Example\n\n```markdown\n# Generate Negotiation Strategy Document\n\n## Step 0: Check tools\nrun_shell\ncommand: which pandoc && which xelatex && echo \"TOOLS_OK\" || echo \"TOOLS_MISSING\"\n\n## Step 1: Write Markdown source\nwrite_file\npath: \u002Ftmp\u002Fnegotiation_strategy.md\ncontent: |\n  # Negotiation Strategy\n  \n  ## Executive Summary\n  [Content with original unicode...]\n  \n  ## Resolution Path\n  [Content...]\n  \n  ## BATNA Analysis\n  [Content...]\n\n## Step 2: Check for Unicode (if PDF needed)\nrun_shell\ncommand: grep -P '[\\x{2014}\\x{2013}\\x{201C}\\x{201D}]' \u002Ftmp\u002Fnegotiation_strategy.md && echo \"UNICODE_DETECTED\" || echo \"UNICODE_CLEAN\"\n\n## Step 3: Convert to DOCX (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.docx\n\n## Step 4: Convert to PDF (try xelatex first)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=xelatex\n\n## Step 5: If Step 4 failed, try wkhtmltopdf\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.pdf --pdf-engine=wkhtmltopdf\n\n## Step 6: Convert to HTML (from original)\nrun_shell\ncommand: pandoc \u002Ftmp\u002Fnegotiation_strategy.md -o negotiation_strategy.html\n\n## Step 7: Verify\nrun_shell\ncommand: ls -lh negotiation_strategy.*\n```\n\n## Advantages Over shell_agent\n\n| Aspect | shell_agent | Manual Workflow |\n|--------|-------------|-----------------|\n| Error visibility | Opaque, may retry silently | Each step shows explicit output |\n| Recovery | Automatic but may loop | Manual intervention at specific step |\n| Debugging | Hard to isolate failure point | Clear which step failed |\n| Unicode control | Agent may not handle encoding | You control character sanitization |\n| Tool fallback | Single approach | Multiple fallback options |\n| Control | Agent decides approach | You control each conversion |\n\n## Common pandoc Commands\n\n```bash\n# Markdown to Word\npandoc input.md -o output.docx\n\n# Markdown to PDF (requires LaTeX or wkhtmltopdf)\npandoc input.md -o output.pdf\n\n# Markdown to PDF with Unicode-safe engine (better Unicode support)\npandoc input.md -o output.pdf --pdf-engine=xelatex\n\n# Markdown to PDF with wkhtmltopdf (good alternative)\npandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf\n\n# Markdown to HTML\npandoc input.md -o output.html\n\n# With custom template\npandoc input.md --template=template.html -o output.html\n\n# With metadata\npandoc input.md -o output.pdf --metadata title=\"Document Title\"\n```\n\n## Troubleshooting\n\n### PDF Generation Failures\n\n- **PDF generation fails with encoding error**: \n  - Use `--pdf-engine=xelatex` for better Unicode support\n  - Or use `--pdf-engine=wkhtmltopdf` as alternative\n  - Or create sanitized markdown file and use pdflatex\n\n- **PDF generation fails: LaTeX not found**: \n  - Install LaTeX: `apt-get install texlive-latex-recommended texlive-fonts-recommended`\n  - Or use `--pdf-engine=wkhtmltopdf` instead\n  - Or fall back to Python fpdf2 (Step 3 Option D)\n\n- **PDF generation fails: wkhtmltopdf not found**: \n  - Install: `apt-get install wkhtmltopdf`\n  - Or use xelatex or pdflatex with sanitization\n  - Or fall back to Python fpdf2\n\n### DOCX Formatting Issues\n\n- Add `--reference-doc=template.docx` for custom styles\n- Ensure pandoc version is 2.0+ for best DOCX support\n\n### Unicode\u002FEncoding Errors in Any Format\n\n- Add `-f markdown+utf8` to pandoc command\n- Ensure source file is UTF-8 encoded: `file -i source.md`\n- For PDF: prefer xelatex engine over pdflatex\n\n### Special Characters Not Rendering in PDF\n\n- Use xelatex engine: `--pdf-engine=xelatex`\n- Or use the character replacement table above\n- Or create sanitized version before PDF conversion\n\n### Missing pandoc\n\n- Install via `apt-get install pandoc` or `brew install pandoc`\n- Or use Python libraries directly (fpdf2, reportlab)\n\n### Python PDF Library Fallback\n\nIf pandoc is unavailable or consistently failing:\n\n```bash\n# Using fpdf2\npython3 -c \"\nfrom fpdf import FPDF\npdf = FPDF()\npdf.add_page()\npdf.set_font('Arial', size=12)\npdf.multi_cell(0, 10, open('input.md').read())\npdf.output('output.pdf')\n\"\n\n# Using reportlab (more control)\npython3 -c \"\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.platypus import SimpleDocTemplate, Paragraph\nfrom reportlab.lib.styles import getSampleStyleSheet\ndoc = SimpleDocTemplate('output.pdf', pagesize=letter)\nstyles = getSampleStyleSheet()\nstory = [Paragraph(open('input.md').read(), styles['Normal'])]\ndoc.build(story)\n\"\n```\n\n## Unicode Sanitization Script (Optional)\n\nFor repeated use, create a reusable sanitization script:\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\nSave as `sanitize_for_pdf.sh`, make executable with `chmod +x sanitize_for_pdf.sh`, then use:\n\n```\nrun_shell\ncommand: .\u002Fsanitize_for_pdf.sh \u002Ftmp\u002Fdocument_source.md \u002Ftmp\u002Fdocument_source_sanitized.md\n```\n\n## Decision Matrix: Which Approach to Use\n\n| Scenario | Recommended Approach |\n|----------|---------------------|\n| DOCX only, any content | pandoc (no sanitization needed) |\n| HTML only, any content | pandoc (no sanitization needed) |\n| PDF, simple ASCII content | pandoc + pdflatex |\n| PDF, Unicode content | pandoc + xelatex (preferred) |\n| PDF, Unicode, xelatex unavailable | pandoc + sanitization + pdflatex |\n| PDF, pandoc unavailable | Python fpdf2 or reportlab |\n| Multiple formats needed | pandoc for all, sanitization for PDF only |\n| shell_agent failing repeatedly | Use this manual workflow |\n\n## When to Return to shell_agent\n\nAfter successfully completing the manual workflow once, you can attempt `shell_agent` again for similar tasks, now with a known-working fallback if errors recur. For documents with heavy Unicode content requiring PDF output, consider always using the manual workflow with xelatex or sanitization.\n\n## Related Skills\n\n- `write-file-fallback-report`: Use when web sourcing fails, create from embedded knowledge\n- `spreadsheet-direct-python`: Use Python libraries directly for spreadsheet operations\n- Use this skill when your documents contain special characters, symbols, or non-ASCII text that may cause LaTeX\u002FPDF conversion issues\n",{"name":5,"description":7},"main","af1b40a42167d09c30b3a63000aa14ace4c1e229","gdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f","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":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient",{"tool":48,"command":49},"bunx","bunx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient",{"tool":51,"command":52},"pnpm","pnpm dlx skills add xyliu-cs\u002FOpenSpace-GDPval --skill document-gen-resilient","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f\u002FSKILL.md",true,[56],{"path":57,"resourceType":58,"resourceTypeDesc":59,"sizeBytes":60,"sourceHtmlUrl":61},".skill_id","OTHER","其他",60,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f\u002F.skill_id",[63,76,84,99,120,136],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":29},"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",[],[70,71,72,73,74,75],"zip export deliverable","zip","export","deliverables","codebase","as",{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":29},"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",[],[83,71,73,74,75],"zip deliverable finalization",{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":29},"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",[],[91,92,93,94,95,27,96,97,75,98],"failure analysis","ZeRO","analysis","iteration","zero iteration failure analysis","issues","execution","system",{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":29},"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",[],[106,107,108,109,110,111,112,113,114,115,116,117,118,119],"fallback","write","file","report","write file fallback report","domain","professional","sources","retrieval","generate","embedded","documents","data","knowledge",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":29},"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",[],[127,27,106,128,129,130,117,115,108,131,22,132,107,133,112,134,135],"fallback doc with delegation","doc","delegation","shell","markdown","text","simple","formats","for",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":29},"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",[],[106,109,143,144,115,108,145,146,107,147,148,114,27,149,117],"context","context anchored fallback report","Guardrails","Tools","task","drift","context drift"]