Chuyển đến nội dung
Skillpedia
PDF, Word và slide7.8k · #12864

document-gen-unicode-safe

Skill này làm gì

Skill này chia việc tạo tài liệu thành các bước nhìn thấy được, có làm sạch ký tự và ghi lại lỗi. Dành cho người tạo tài liệu có dấu, ký hiệu hoặc văn bản không phải tiếng Anh.

Khi nào nên dùng

  • ✓Khi một trợ lý shell trả về lỗi không rõ khi tạo tài liệu.
  • ✓Khi tài liệu có chữ có dấu hoặc ký hiệu gây lỗi PDF.
  • ✓Khi tôi cần nhiều định dạng và muốn thấy đầu ra của từng bước.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Trợ lý liên tục thất bại khi tạo tài liệu của tôi, và văn bản có dấu. Hãy tự làm từng bước để tôi thấy chỗ nào lỗi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI viết nguồn Markdown, làm sạch các ký tự mà công cụ PDF không hiển thị được, chạy từng chuyển đổi với đầu ra lỗi được hiển thị, rồi kiểm tra kết quả.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Document Generation Fallback Workflow (Unicode-Safe)

When to Use

Use this skill when shell_agent returns unknown or unclear errors on complex document generation tasks, especially when:

  • Generating documents in multiple formats (e.g., .docx, .pdf, .html)
  • The error message doesn't provide clear debugging information
  • You need to handle special characters, symbols, or non-ASCII text safely
  • PDF generation fails due to LaTeX encoding issues

Core Technique

Instead of delegating the entire document generation to shell_agent, manually split the workflow into discrete, observable steps:

  1. Content creation → Use write_file to create source document (Markdown)
  2. Unicode sanitization → Preprocess markdown to replace problematic characters before PDF conversion
  3. Format conversion with stderr capture → Use run_shell with pandoc for each target format, capturing full stderr output
  4. Verification → Check output files exist and are valid

⚠️ Unicode & LaTeX Compatibility Warning

Critical: PDF generation via pandoc typically uses LaTeX (pdflatex or xelatex), which has limited Unicode support. Common problematic characters include:

Character Issue Safe Replacement
— (em dash) May not render -- or -
– (en dash) May not render -
" " (curly quotes) Encoding errors " " (straight quotes)
' ' (curly apostrophe) Encoding errors ' (straight apostrophe)
… (ellipsis) May not render ...
→ ← ↑ ↓ (arrows) LaTeX incompatibility -> <- ^ v
✓ ✗ (checkmarks) May not render [x] [ ]
★ ● (symbols) May not render * -
© ® ™ May require packages (c) (r) (tm)
Non-ASCII letters (é, ñ, ü) Font-dependent Use xeLaTeX or replace

Step-by-Step Workflow

Step 1: Create Source Content with write_file

Write your document content as Markdown to a temporary source file. This gives you full visibility into the content being generated.

write_file
path: /tmp/document_source.md
content: |
  # Document Title
  
  ## Section 1
  Content here...
  
  ## Section 2
  More content...

Step 2: Sanitize Unicode Characters (Pre-PDF Conversion)

Before PDF conversion, create a sanitized version of your markdown with LaTeX-safe characters:

write_file
path: /tmp/document_source_sanitized.md
content: |
  # Document Title
  
  ## Section 1
  Content here... (with all special chars replaced per table above)

Alternative: Use a shell script to sanitize:

run_shell
command: sed -e 's/—/--/g' -e 's/–/-/g' -e 's/"([^"]*)"/"\1"/g' -e 's/'([^']*)/'\1'/g' /tmp/document_source.md > /tmp/document_source_sanitized.md

Note: Keep the original unsanitized file for DOCX/HTML conversion (these formats handle Unicode better).

Step 3: Convert to Target Formats with run_shell

Use run_shell with explicit pandoc commands for each format. Use sanitized source for PDF, original for other formats.

Critical: Always capture stderr output (2>&1) to diagnose failures before retrying with alternative engines.

run_shell
command: pandoc /tmp/document_source.md -o output.docx
run_shell
command: pandoc /tmp/document_source.md -o output.html

Step 3a: PDF Conversion - Try xelatex First (Best Unicode Support)

Use xelatex as the first engine - it has better Unicode support and is commonly available in containerized environments:

run_shell
command: pandoc /tmp/document_source_sanitized.md --pdf-engine=xelatex -o output.pdf 2>&1

Step 3b: If xelatex Fails - Capture Full Error and Retry with wkhtmltopdf

Before retrying, examine the full stderr output from Step 3a to understand the failure cause (missing engine, font issues, etc.). Then try wkhtmltopdf as fallback:

run_shell
command: pandoc /tmp/document_source_sanitized.md --pdf-engine=wkhtmltopdf -o output.pdf 2>&1

Step 4: Verify Outputs

Check that files were created successfully:

run_shell
command: ls -lh output.docx output.pdf output.html

Complete Example

# Generate Negotiation Strategy Document

## Step 1: Write Markdown source
write_file
path: /tmp/negotiation_strategy.md
content: |
  # Negotiation Strategy
  
  ## Executive Summary
  [Content with original unicode...]
  
  ## Resolution Path
  [Content...]
  
  ## BATNA Analysis
  [Content...]

## Step 2: Creat
Câu hỏi thường gặp

Vì sao phải thay một số ký tự?

Một số PDF engine không hiển thị được các ký tự như dấu nháy cong hoặc dấu gạch dài, nên dùng phiên bản đơn giản hơn.

Những định dạng nào được tạo?

Hướng dẫn mô tả đầu ra Word, PDF và HTML.

Lỗi có bị che giấu không?

Không. Hướng dẫn yêu cầu ghi lại toàn bộ đầu ra lỗi để thấy được từng thất bại.

Chi tiết

Mô tả gốc của tác giả

Unicode-safe fallback workflow for multi-format document generation with character sanitization and explicit error capture

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12864
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự