Handle LaTeX Unicode errors in pandoc PDF generation by normalizing special characters to ASCII
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-pandoc-unicode-workaround-3a1966a79f02 ,按照其中的说明把「pandoc-unicode-workaround」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides a workflow for generating PDFs from Markdown using pandoc when LaTeX compilation fails due to Unicode character errors.
Use this skill when:
pandoc document.md -o document.pdf fails with LaTeX/Unicode errorspandoc input.md -o output.pdf
If this succeeds, you're done. If it fails with Unicode/LaTeX errors, proceed to Step 2.
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 ' |
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)
pandoc input.md -o output.pdf
Check that the PDF was generated successfully and review the content to ensure character replacements are acceptable for your use case.
If Unicode normalization is not acceptable:
Use a different PDF engine:
pandoc input.md -o output.pdf --pdf-engine=wkhtmltopdf
Use XeLaTeX (better Unicode support):
pandoc input.md -o output.pdf --pdf-engine=xelatex
Add LaTeX packages for Unicode:
pandoc input.md -o output.pdf -H header.tex
Where header.tex contains:
\usepackage{fontspec}
\usepackage{xunicode}
Common LaTeX Unicode errors to watch for: