[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6HXGGY3RQNXWWAW3REJFE6F":3,"skill-same:01M6HXGGY3RQNXWWAW3REJFE6F":67},{"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":23,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":42,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":45,"ownerDescription":6,"updatedAt":46,"install":47,"resources":60},"01M6HXGGY3RQNXWWAW3REJFE6F","document-gen-resilient",null,"Multi-path document generation with tool checks, Unicode handling, and Python fallbacks","HKUDS\u002FAgentPilot","HKUDS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F118165258?v=4","01M6HW8VRNZP64G0P4MVJW2KKQ","✨Data Intelligence Lab@HKU✨","01M6HW8VWZVHBRHYH3T330PFWV",8029,"MIT","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000002","文档处理","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33],"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","6b84b0689ca0d9e7b1e4061188ff6b60758e0f8a","openspace\u002Flegacy\u002Fv1\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f",944,"https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot","https:\u002F\u002Fgithub.com\u002FHKUDS","https:\u002F\u002Fsites.google.com\u002Fview\u002Fchaoh","2026-11-12 22:26:39",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add HKUDS\u002FAgentPilot --skill document-gen-resilient",{"tool":53,"command":54},"bunx","bunx skills add HKUDS\u002FAgentPilot --skill document-gen-resilient",{"tool":56,"command":57},"pnpm","pnpm dlx skills add HKUDS\u002FAgentPilot --skill document-gen-resilient","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f\u002FSKILL.md",true,[61],{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},".skill_id","OTHER","其他",60,"https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fgdpval_bench\u002Fskills\u002Fdocument-gen-fallback-enhanced-enhanced-96865f\u002F.skill_id",[68,87,106,129,152,174],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":34},"01M6HYB297NDABRERJRVG0K8R0","agentpilot","Set up AgentPilot and use its single entry to prepare missing inputs and run configured RSI experiments. Use when the user requests AgentPilot installation or work with AgentPilot.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fplugins\u002Fagentpilot\u002Fskills\u002Fagentpilot\u002FSKILL.md",[],[70,75,76,32,77,78,79,80,81,82,83,84,85,86],"prepare","requests","missing","installation","rsi","up","use","user","work","SET","run","experiments",{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":34},"01M6HYAYWXTTE1J7DJM0MFNQ4H","remember","Review auto-memory entries and propose promotions to OPENSPACE.md, OPENSPACE.local.md, or retained auto-memory topics; detect duplicates, stale facts, conflicts, and ambiguous entries before making changes.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fskills\u002Fremember\u002FSKILL.md",[],[89,94,95,96,97,98,99,100,101,102,103,104,105],"memory","review","auto","openspace","changes","facts","detect","entries","local","conflicts","stale","duplicates",{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":115,"publishedAt":34},"01M6HYAVMPM4SBDV60R2B5HPV8","skill-discovery","Search reusable OpenSpace skills locally, and browse cloud packages step by step when a cloud skill may help. Reusing proven skills saves tokens, improves reliability, and extends your capabilities beyond built-in tools.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fhost_skills\u002Fskill-discovery\u002FSKILL.md",[112],{"categoryNo":113,"categoryName":114,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[116,117,118,97,119,120,121,122,123,124,125,126,127,128],"skill discovery","discovery","reusable","step by step","tokens","packages","help","cloud","reliability","capabilities","browse","search","Tools",{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":133,"categories":134,"keywords":136,"publishedAt":34},"01M6HYAR811B3RB0M50RBEDGN6","delegate-task","Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fhost_skills\u002Fdelegate-task\u002FSKILL.md",[135],{"categoryNo":113,"categoryName":114,"taxonomyType":21,"taxonomyTypeDesc":22},[137,138,139,97,140,141,142,143,144,118,96,81,145,27,146,147,148,149,150,151],"delegate","task","delegate task","time","improve","desktop automation","worker","community","autonomous","stack","for","share","tasks","automation","MCP",{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":156,"categories":157,"keywords":158,"publishedAt":34},"01M6HYAM9FSGV6E52AYENDQXYH","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[159,160,161,162,163,164,165,166,167,26,168,169,170,171,147,172,173],"write special chars ts check","write","check","type","files","filters","only","template","file","typescript","output","Existing","type-checking","errors","script",{"skillNo":175,"name":176,"nameZh":6,"description":177,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":178,"categories":179,"keywords":180,"publishedAt":34},"01M6HYAH05HGV7SVWSVR8PJRQD","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[181,182,160,32,147,173,183,184,185,186,187,166,167,188,189,26],"write special chars readback","readback","helper","post","via","scripts","read","verification","cleanup"]