跳到正文
Skillpedia
PDF、Word 与幻灯片7.8k · #12907

pandoc-unicode-workaround

它能做什么

这项技能描述了在 pandoc 因特殊字符失败时,把 Markdown 转换为 PDF 的工作流程。适合文档中有勾号、箭头、破折号等符号、且能接受普通文字替代的人。

适用场景

  • ✓当 pandoc 因 Unicode 或 LaTeX 错误无法生成 PDF 时。
  • ✓当错误信息指出勾号、箭头或长破折号等特殊字符时。
  • ✓当我需要 PDF,并且可以接受符号的普通文字版本时。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pandoc-unicode-workaround/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pandoc-unicode-workaround/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我:我的笔记中有勾号和箭头,导致 PDF 导出失败。请把它们换成普通文字,然后重新生成 PDF。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 先尝试常规转换。如果失败,就根据一个对照表,把特殊字符替换为 ASCII 等价字符,然后再次转换。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Pandoc Unicode Workaround

This skill provides a workflow for generating PDFs from Markdown using pandoc when LaTeX compilation fails due to Unicode character errors.

When to Use

Use this skill when:

  • pandoc document.md -o document.pdf fails with LaTeX/Unicode errors
  • Error messages mention "Unicode character", "LaTeX Error", or specific characters like ✓, →, —, etc.
  • You need to produce PDF output but pandoc's default LaTeX engine cannot handle special characters

Step-by-Step Procedure

Step 1: Attempt Initial PDF Generation

pandoc input.md -o output.pdf

If this succeeds, you're done. If it fails with Unicode/LaTeX errors, proceed to Step 2.

Step 2: Normalize Unicode Characters

Replace problematic Unicode characters with ASCII equivalents. Common replacements:

Unicode Character ASCII Replacement Alternative
✓ (checkmark) [Y] or [X] OK, ✓ removed
✗ or ✘ (cross) [N] FAIL
→ (arrow right) -> =>
← (arrow left) <-
— (em dash) -- or - ---
– (en dash) -
• (bullet) - *
© (copyright) (c) Copyright
® (registered) (R)
™ (trademark) (TM)
… (ellipsis) ...
" (smart quotes) " or '

Step 3: Apply Replacements

Option A - Manual edit: Open the Markdown file and manually replace the characters using find/replace.

Option B - Automated with sed (Linux/Mac):

sed -i 's/✓/[Y]/g' input.md
sed -i 's/✗/[N]/g' input.md
sed -i 's/→/->/g' input.md
sed -i 's/—/--/g' input.md

Option C - Automated with Python:

replacements = {
    '✓': '[Y]',
    '✗': '[N]',
    '→': '->',
    '—': '--',
    '–': '-',
    '…': '...',
    '"': '"',
    '"': '"',
}

with open('input.md', 'r', encoding='utf-8') as f:
    content = f.read()

for orig, repl in replacements.items():
    content = content.replace(orig, repl)

with open('input.md', 'w', encoding='utf-8') as f:
    f.write(content)

Step 4: Regenerate PDF

pandoc input.md -o output.pdf

Step 5: Verify Output

Check that the PDF was generated successfully and review the content to ensure character replacements are acceptable for your use case.

Alternative Approaches

If Unicode normalization is not acceptable:

  1. Use a different PDF engine:

    pandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf
    
  2. Use XeLaTeX (better Unicode support):

    pandoc input.md -o output.pdf --pdf-engine=xelatex
    
  3. Add LaTeX packages for Unicode:

    pandoc input.md -o output.pdf -H header.tex
    

    Where header.tex contains:

    \usepackage{fontspec}
    \usepackage{xunicode}
    

Tips

  • Keep the original Markdown file before normalization if you need to preserve characters
  • Document which characters were replaced for future reference
  • Test with a small sample first if working with large documents
  • For Word documents (.docx), Unicode issues are less common; this pattern is primarily for PDF generation

Error Indicators

Common LaTeX Unicode errors to watch for:

  • ! LaTeX Error: Unicode character ... not set up for use with LaTeX
  • Package inputenc Error: Unicode character ... not set up
  • ! Missing character: There is no ... in font ...
常见问题

会先尝试常规转换吗?

会。指南先使用普通的 pandoc 命令,只有失败时才清理文本。

勾号要替换成什么?

指南建议使用带括号的 Y 或 X 等普通标记。

替换规则有列出来吗?

有。指南包含一张对照表,把每个符号映射为普通替代写法。

详情

作者的原始描述

Handle LaTeX Unicode errors in pandoc PDF generation by normalizing special characters to ASCII

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#12907
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能