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

pandoc-unicode-sanitize

它能做什么

这项技能通过把 LaTeX 无法处理的符号替换为普通等价字符,为 PDF 转换准备 Markdown 文件。适合文档中含有货币符号、花式引号或箭头的人。

适用场景

  • ✓当我的 Markdown 中含有欧元、英镑或卢比等货币符号,且 PDF 转换失败时。
  • ✓当文档中有弯引号、箭头或项目符号导致 PDF 转换出错时。
  • ✓当我希望每次生成 PDF 前都有一个可复用的清理步骤时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我:我的 Markdown 中有卢比和欧元符号以及弯引号,PDF 转换失败了。请清理这些符号并生成 PDF。”

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

工作原理

AI 对 Markdown 运行一组文本替换,把符号转换为普通文字,例如 Rs 或 EUR,然后用 pandoc 转换清理后的文件。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Pandoc Unicode Sanitization for PDF Conversion

Problem

LaTeX (used by pandoc for PDF output) may fail or produce errors when encountering non-ASCII Unicode characters like currency symbols (₹, €, £), special quotes, or other Unicode characters not supported by the default LaTeX engine.

Solution

Pre-process Markdown files to replace problematic Unicode characters with ASCII equivalents before running pandoc PDF conversion.

Steps

1. Identify Problematic Characters

Common problematic characters include:

  • Currency symbols: ₹, €, £, ¥
  • Special quotes: " " ' '
  • Arrows: →, ←, ↑, ↓
  • Bullets: •, ◦
  • Other symbols: ©, ®, ™, ±, ×, ÷, —, –

2. Create a Sed Substitution Script

Create a shell script for reusable sanitization:

#!/bin/bash
# sanitize-for-pdf.sh

sed -e 's/₹/Rs/g' \
    -e 's/€/EUR/g' \
    -e 's/£/GBP/g' \
    -e 's/¥/JPY/g' \
    -e 's/"/"/g' \
    -e 's/"/"/g' \
    -e "s/'/'/g" \
    -e "s/'/'/g" \
    -e 's/→/->/g' \
    -e 's/←/<-/g' \
    -e 's/•/-/g' \
    -e 's/©/(c)/g' \
    -e 's/®/(R)/g' \
    -e 's/™/(TM)/g' \
    -e 's/±/+/ -/g' \
    -e 's/×/x/g' \
    -e 's/÷/\//g' \
    -e 's/—/--/g' \
    -e 's/–/-/g' \
    "$1"

3. Run Sanitization Before Pandoc

# Using the script
./sanitize-for-pdf.sh input.md > sanitized.md
pandoc sanitized.md -o output.pdf

# Or inline
cat input.md | sed 's/₹/Rs/g; s/€/EUR/g; s/£/GBP/g' | pandoc -o output.pdf

4. Alternative: Use iconv for Automatic Transliteration

For broader Unicode coverage:

iconv -f UTF-8 -t ASCII//TRANSLIT < input.md > sanitized.md
pandoc sanitized.md -o output.pdf

5. Alternative: Use XeLaTeX or LuaLaTeX Engine

If you want to preserve Unicode characters, use a Unicode-capable engine:

pandoc input.md -o output.pdf --pdf-engine=xelatex
# or
pandoc input.md -o output.pdf --pdf-engine=lualatex

Best Practices

  • Sanitize files before conversion rather than debugging LaTeX errors after
  • Keep a mapping of your organization's common symbols and preferred replacements
  • Test with a small sample before processing large documents
  • Consider using XeLaTeX/LuaLaTeX if Unicode preservation is required
  • Document which characters cause issues in your specific environment

Common Error Signs

Look for these LaTeX errors that indicate Unicode issues:

  • Package inputenc Error: Unicode character ... not set up
  • LaTeX Error: Unicode character ... cannot be used with pdflatex
  • Missing or garbled characters in the output PDF
常见问题

哪些符号会被替换?

指南列出了货币符号、弯引号、箭头、项目符号、版权符号和各种破折号。

原始文件会被修改吗?

不会。指南把清理后的文本写入新文件,原始文件保持不变。

这个清理步骤可以重复使用吗?

可以。指南建议把这些替换规则保存在一个小型 shell 脚本中。

详情

作者的原始描述

Pre-process Markdown to replace non-ASCII characters before pandoc PDF conversion

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能